blob: dca123527d5f034ebdd8a73ad2a7097e39abda43 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080030#include <linux/delay.h>
31#include "drmP.h"
32#include "drm.h"
33#include "drm_crtc.h"
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +080034#include "drm_edid.h"
Chris Wilsonea5b2132010-08-04 13:50:23 +010035#include "intel_drv.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080036#include "i915_drm.h"
37#include "i915_drv.h"
38#include "intel_sdvo_regs.h"
39
Zhenyu Wang14571b42010-03-30 14:06:33 +080040#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
41#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
42#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
43#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
44
45#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
46 SDVO_TV_MASK)
47
48#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
49#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
50
Jesse Barnes79e53942008-11-07 14:24:08 -080051
Zhao Yakuice6feab2009-08-24 13:50:26 +080052static char *tv_format_names[] = {
53 "NTSC_M" , "NTSC_J" , "NTSC_443",
54 "PAL_B" , "PAL_D" , "PAL_G" ,
55 "PAL_H" , "PAL_I" , "PAL_M" ,
56 "PAL_N" , "PAL_NC" , "PAL_60" ,
57 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
58 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
59 "SECAM_60"
60};
61
62#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
63
Chris Wilsonea5b2132010-08-04 13:50:23 +010064struct intel_sdvo {
65 struct intel_encoder base;
66
Keith Packardf9c10a92009-05-30 12:16:25 -070067 u8 slave_addr;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080068
69 /* Register for the SDVO device: SDVOB or SDVOC */
Eric Anholtc751ce42010-03-25 11:48:48 -070070 int sdvo_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080071
Jesse Barnese2f0ba92009-02-02 15:11:52 -080072 /* Active outputs controlled by this SDVO output */
73 uint16_t controlled_output;
Jesse Barnes79e53942008-11-07 14:24:08 -080074
Jesse Barnese2f0ba92009-02-02 15:11:52 -080075 /*
76 * Capabilities of the SDVO device returned by
77 * i830_sdvo_get_capabilities()
78 */
Jesse Barnes79e53942008-11-07 14:24:08 -080079 struct intel_sdvo_caps caps;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080080
81 /* Pixel clock limitations reported by the SDVO device, in kHz */
Jesse Barnes79e53942008-11-07 14:24:08 -080082 int pixel_clock_min, pixel_clock_max;
83
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +080084 /*
85 * For multiple function SDVO device,
86 * this is for current attached outputs.
87 */
88 uint16_t attached_output;
89
Jesse Barnese2f0ba92009-02-02 15:11:52 -080090 /**
91 * This is set if we're going to treat the device as TV-out.
92 *
93 * While we have these nice friendly flags for output types that ought
94 * to decide this for us, the S-Video output on our HDMI+S-Video card
95 * shows up as RGB1 (VGA).
96 */
97 bool is_tv;
98
Zhao Yakuice6feab2009-08-24 13:50:26 +080099 /* This is for current tv format name */
100 char *tv_format_name;
101
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800102 /**
103 * This is set if we treat the device as HDMI, instead of DVI.
104 */
105 bool is_hdmi;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800106
Ma Ling7086c872009-05-13 11:20:06 +0800107 /**
108 * This is set if we detect output of sdvo device as LVDS.
109 */
110 bool is_lvds;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800111
112 /**
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800113 * This is sdvo flags for input timing.
114 */
115 uint8_t sdvo_flags;
116
117 /**
118 * This is sdvo fixed pannel mode pointer
119 */
120 struct drm_display_mode *sdvo_lvds_fixed_mode;
121
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800122 /*
123 * supported encoding mode, used to determine whether HDMI is
124 * supported
125 */
126 struct intel_sdvo_encode encode;
127
Eric Anholtc751ce42010-03-25 11:48:48 -0700128 /* DDC bus used by this SDVO encoder */
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800129 uint8_t ddc_bus;
130
Keith Packard57cdaf92009-09-04 13:07:54 +0800131 /* Mac mini hack -- use the same DDC as the analog connector */
132 struct i2c_adapter *analog_ddc_bus;
133
Zhenyu Wang14571b42010-03-30 14:06:33 +0800134};
135
136struct intel_sdvo_connector {
Chris Wilson615fb932010-08-04 13:50:24 +0100137 struct intel_connector base;
138
Zhenyu Wang14571b42010-03-30 14:06:33 +0800139 /* Mark the type of connector */
140 uint16_t output_flag;
141
142 /* This contains all current supported TV format */
143 char *tv_format_supported[TV_FORMAT_NUM];
144 int format_supported_num;
145 struct drm_property *tv_format_property;
146 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
147
148 /**
149 * Returned SDTV resolutions allowed for the current format, if the
150 * device reported it.
151 */
152 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
153
Zhao Yakuib9219c52009-09-10 15:45:46 +0800154 /* add the property for the SDVO-TV */
155 struct drm_property *left_property;
156 struct drm_property *right_property;
157 struct drm_property *top_property;
158 struct drm_property *bottom_property;
159 struct drm_property *hpos_property;
160 struct drm_property *vpos_property;
161
162 /* add the property for the SDVO-TV/LVDS */
163 struct drm_property *brightness_property;
164 struct drm_property *contrast_property;
165 struct drm_property *saturation_property;
166 struct drm_property *hue_property;
167
168 /* Add variable to record current setting for the above property */
169 u32 left_margin, right_margin, top_margin, bottom_margin;
170 /* this is to get the range of margin.*/
171 u32 max_hscan, max_vscan;
172 u32 max_hpos, cur_hpos;
173 u32 max_vpos, cur_vpos;
174 u32 cur_brightness, max_brightness;
175 u32 cur_contrast, max_contrast;
176 u32 cur_saturation, max_saturation;
177 u32 cur_hue, max_hue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800178};
179
Chris Wilsonea5b2132010-08-04 13:50:23 +0100180static struct intel_sdvo *enc_to_intel_sdvo(struct drm_encoder *encoder)
181{
182 return container_of(enc_to_intel_encoder(encoder), struct intel_sdvo, base);
183}
184
Chris Wilson615fb932010-08-04 13:50:24 +0100185static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector)
186{
187 return container_of(to_intel_connector(connector), struct intel_sdvo_connector, base);
188}
189
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800190static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +0100191intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags);
Zhenyu Wang14571b42010-03-30 14:06:33 +0800192static void
193intel_sdvo_tv_create_property(struct drm_connector *connector, int type);
194static void
195intel_sdvo_create_enhance_property(struct drm_connector *connector);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800196
Jesse Barnes79e53942008-11-07 14:24:08 -0800197/**
198 * Writes the SDVOB or SDVOC with the given value, but always writes both
199 * SDVOB and SDVOC to work around apparent hardware issues (according to
200 * comments in the BIOS).
201 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100202static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800203{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100204 struct drm_device *dev = intel_sdvo->base.enc.dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800205 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes79e53942008-11-07 14:24:08 -0800206 u32 bval = val, cval = val;
207 int i;
208
Chris Wilsonea5b2132010-08-04 13:50:23 +0100209 if (intel_sdvo->sdvo_reg == PCH_SDVOB) {
210 I915_WRITE(intel_sdvo->sdvo_reg, val);
211 I915_READ(intel_sdvo->sdvo_reg);
Zhao Yakui461ed3c2010-03-30 15:11:33 +0800212 return;
213 }
214
Chris Wilsonea5b2132010-08-04 13:50:23 +0100215 if (intel_sdvo->sdvo_reg == SDVOB) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800216 cval = I915_READ(SDVOC);
217 } else {
218 bval = I915_READ(SDVOB);
219 }
220 /*
221 * Write the registers twice for luck. Sometimes,
222 * writing them only once doesn't appear to 'stick'.
223 * The BIOS does this too. Yay, magic
224 */
225 for (i = 0; i < 2; i++)
226 {
227 I915_WRITE(SDVOB, bval);
228 I915_READ(SDVOB);
229 I915_WRITE(SDVOC, cval);
230 I915_READ(SDVOC);
231 }
232}
233
Chris Wilsonea5b2132010-08-04 13:50:23 +0100234static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800235 u8 *ch)
236{
Jesse Barnes79e53942008-11-07 14:24:08 -0800237 u8 out_buf[2];
238 u8 buf[2];
239 int ret;
240
241 struct i2c_msg msgs[] = {
242 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100243 .addr = intel_sdvo->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800244 .flags = 0,
245 .len = 1,
246 .buf = out_buf,
247 },
248 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100249 .addr = intel_sdvo->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800250 .flags = I2C_M_RD,
251 .len = 1,
252 .buf = buf,
253 }
254 };
255
256 out_buf[0] = addr;
257 out_buf[1] = 0;
258
Chris Wilsonea5b2132010-08-04 13:50:23 +0100259 if ((ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 2)) == 2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800260 {
261 *ch = buf[0];
262 return true;
263 }
264
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800265 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
Jesse Barnes79e53942008-11-07 14:24:08 -0800266 return false;
267}
268
Chris Wilsonea5b2132010-08-04 13:50:23 +0100269static bool intel_sdvo_write_byte(struct intel_sdvo *intel_sdvo, int addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800270 u8 ch)
271{
272 u8 out_buf[2];
273 struct i2c_msg msgs[] = {
274 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100275 .addr = intel_sdvo->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800276 .flags = 0,
277 .len = 2,
278 .buf = out_buf,
279 }
280 };
281
282 out_buf[0] = addr;
283 out_buf[1] = ch;
284
Chris Wilsonea5b2132010-08-04 13:50:23 +0100285 if (i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 1) == 1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800286 {
287 return true;
288 }
289 return false;
290}
291
292#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
293/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100294static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800295 u8 cmd;
296 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800297} sdvo_cmd_names[] = {
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
Zhao Yakuib9219c52009-09-10 15:45:46 +0800341 /* Add the op code for SDVO enhancements */
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
355 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
356 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
359 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
360 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
361 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
362 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800366 /* HDMI op code */
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
368 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
369 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
370 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
371 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
372 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
373 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
374 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
375 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
376 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
377 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
378 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
379 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
380 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
381 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
382 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
383 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
384 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
385 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
386 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800387};
388
Zhao Yakui461ed3c2010-03-30 15:11:33 +0800389#define IS_SDVOB(reg) (reg == SDVOB || reg == PCH_SDVOB)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100390#define SDVO_NAME(svdo) (IS_SDVOB((svdo)->sdvo_reg) ? "SDVOB" : "SDVOC")
Jesse Barnes79e53942008-11-07 14:24:08 -0800391
Chris Wilsonea5b2132010-08-04 13:50:23 +0100392static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800393 void *args, int args_len)
394{
Jesse Barnes79e53942008-11-07 14:24:08 -0800395 int i;
396
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800397 DRM_DEBUG_KMS("%s: W: %02X ",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100398 SDVO_NAME(intel_sdvo), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800399 for (i = 0; i < args_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800400 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800401 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800402 DRM_LOG_KMS(" ");
Kulikov Vasiliy04ad3272010-06-28 15:54:56 +0400403 for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800404 if (cmd == sdvo_cmd_names[i].cmd) {
yakui_zhao342dc382009-06-02 14:12:00 +0800405 DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800406 break;
407 }
408 }
Kulikov Vasiliy04ad3272010-06-28 15:54:56 +0400409 if (i == ARRAY_SIZE(sdvo_cmd_names))
yakui_zhao342dc382009-06-02 14:12:00 +0800410 DRM_LOG_KMS("(%02X)", cmd);
411 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800412}
Jesse Barnes79e53942008-11-07 14:24:08 -0800413
Chris Wilsonea5b2132010-08-04 13:50:23 +0100414static void intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800415 void *args, int args_len)
416{
417 int i;
418
Chris Wilsonea5b2132010-08-04 13:50:23 +0100419 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
Jesse Barnes79e53942008-11-07 14:24:08 -0800420
421 for (i = 0; i < args_len; i++) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100422 intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_ARG_0 - i,
Jesse Barnes79e53942008-11-07 14:24:08 -0800423 ((u8*)args)[i]);
424 }
425
Chris Wilsonea5b2132010-08-04 13:50:23 +0100426 intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_OPCODE, cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800427}
428
Jesse Barnes79e53942008-11-07 14:24:08 -0800429static const char *cmd_status_names[] = {
430 "Power on",
431 "Success",
432 "Not supported",
433 "Invalid arg",
434 "Pending",
435 "Target not specified",
436 "Scaling not supported"
437};
438
Chris Wilsonea5b2132010-08-04 13:50:23 +0100439static void intel_sdvo_debug_response(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800440 void *response, int response_len,
441 u8 status)
442{
Zhenyu Wang33b52962009-03-24 14:02:40 +0800443 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800444
Chris Wilsonea5b2132010-08-04 13:50:23 +0100445 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo));
Jesse Barnes79e53942008-11-07 14:24:08 -0800446 for (i = 0; i < response_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800447 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800448 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800449 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800450 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
yakui_zhao342dc382009-06-02 14:12:00 +0800451 DRM_LOG_KMS("(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800452 else
yakui_zhao342dc382009-06-02 14:12:00 +0800453 DRM_LOG_KMS("(??? %d)", status);
454 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800455}
Jesse Barnes79e53942008-11-07 14:24:08 -0800456
Chris Wilsonea5b2132010-08-04 13:50:23 +0100457static u8 intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800458 void *response, int response_len)
459{
460 int i;
461 u8 status;
462 u8 retry = 50;
463
464 while (retry--) {
465 /* Read the command response */
466 for (i = 0; i < response_len; i++) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100467 intel_sdvo_read_byte(intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800468 SDVO_I2C_RETURN_0 + i,
469 &((u8 *)response)[i]);
470 }
471
472 /* read the return status */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100473 intel_sdvo_read_byte(intel_sdvo, SDVO_I2C_CMD_STATUS,
Jesse Barnes79e53942008-11-07 14:24:08 -0800474 &status);
475
Chris Wilsonea5b2132010-08-04 13:50:23 +0100476 intel_sdvo_debug_response(intel_sdvo, response, response_len,
Jesse Barnes79e53942008-11-07 14:24:08 -0800477 status);
478 if (status != SDVO_CMD_STATUS_PENDING)
479 return status;
480
481 mdelay(50);
482 }
483
484 return status;
485}
486
Hannes Ederb358d0a2008-12-18 21:18:47 +0100487static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800488{
489 if (mode->clock >= 100000)
490 return 1;
491 else if (mode->clock >= 50000)
492 return 2;
493 else
494 return 4;
495}
496
497/**
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800498 * Try to read the response after issuie the DDC switch command. But it
499 * is noted that we must do the action of reading response and issuing DDC
500 * switch command in one I2C transaction. Otherwise when we try to start
501 * another I2C transaction after issuing the DDC bus switch, it will be
502 * switched to the internal SDVO register.
Jesse Barnes79e53942008-11-07 14:24:08 -0800503 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100504static void intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
Hannes Ederb358d0a2008-12-18 21:18:47 +0100505 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800506{
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800507 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
508 struct i2c_msg msgs[] = {
509 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100510 .addr = intel_sdvo->slave_addr >> 1,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800511 .flags = 0,
512 .len = 2,
513 .buf = out_buf,
514 },
515 /* the following two are to read the response */
516 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100517 .addr = intel_sdvo->slave_addr >> 1,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800518 .flags = 0,
519 .len = 1,
520 .buf = cmd_buf,
521 },
522 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100523 .addr = intel_sdvo->slave_addr >> 1,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800524 .flags = I2C_M_RD,
525 .len = 1,
526 .buf = ret_value,
527 },
528 };
529
Chris Wilsonea5b2132010-08-04 13:50:23 +0100530 intel_sdvo_debug_write(intel_sdvo, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800531 &target, 1);
532 /* write the DDC switch command argument */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100533 intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_ARG_0, target);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800534
535 out_buf[0] = SDVO_I2C_OPCODE;
536 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
537 cmd_buf[0] = SDVO_I2C_CMD_STATUS;
538 cmd_buf[1] = 0;
539 ret_value[0] = 0;
540 ret_value[1] = 0;
541
Chris Wilsonea5b2132010-08-04 13:50:23 +0100542 ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 3);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800543 if (ret != 3) {
544 /* failure in I2C transfer */
545 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
546 return;
547 }
548 if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
549 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
550 ret_value[0]);
551 return;
552 }
553 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800554}
555
Chris Wilsonea5b2132010-08-04 13:50:23 +0100556static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo, bool target_0, bool target_1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800557{
558 struct intel_sdvo_set_target_input_args targets = {0};
559 u8 status;
560
561 if (target_0 && target_1)
562 return SDVO_CMD_STATUS_NOTSUPP;
563
564 if (target_1)
565 targets.target_1 = 1;
566
Chris Wilsonea5b2132010-08-04 13:50:23 +0100567 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_TARGET_INPUT, &targets,
Jesse Barnes79e53942008-11-07 14:24:08 -0800568 sizeof(targets));
569
Chris Wilsonea5b2132010-08-04 13:50:23 +0100570 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800571
572 return (status == SDVO_CMD_STATUS_SUCCESS);
573}
574
575/**
576 * Return whether each input is trained.
577 *
578 * This function is making an assumption about the layout of the response,
579 * which should be checked against the docs.
580 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100581static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800582{
583 struct intel_sdvo_get_trained_inputs_response response;
584 u8 status;
585
Chris Wilsonea5b2132010-08-04 13:50:23 +0100586 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
587 status = intel_sdvo_read_response(intel_sdvo, &response, sizeof(response));
Jesse Barnes79e53942008-11-07 14:24:08 -0800588 if (status != SDVO_CMD_STATUS_SUCCESS)
589 return false;
590
591 *input_1 = response.input0_trained;
592 *input_2 = response.input1_trained;
593 return true;
594}
595
Chris Wilsonea5b2132010-08-04 13:50:23 +0100596static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800597 u16 outputs)
598{
599 u8 status;
600
Chris Wilsonea5b2132010-08-04 13:50:23 +0100601 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800602 sizeof(outputs));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100603 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800604 return (status == SDVO_CMD_STATUS_SUCCESS);
605}
606
Chris Wilsonea5b2132010-08-04 13:50:23 +0100607static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800608 int mode)
609{
610 u8 status, state = SDVO_ENCODER_STATE_ON;
611
612 switch (mode) {
613 case DRM_MODE_DPMS_ON:
614 state = SDVO_ENCODER_STATE_ON;
615 break;
616 case DRM_MODE_DPMS_STANDBY:
617 state = SDVO_ENCODER_STATE_STANDBY;
618 break;
619 case DRM_MODE_DPMS_SUSPEND:
620 state = SDVO_ENCODER_STATE_SUSPEND;
621 break;
622 case DRM_MODE_DPMS_OFF:
623 state = SDVO_ENCODER_STATE_OFF;
624 break;
625 }
626
Chris Wilsonea5b2132010-08-04 13:50:23 +0100627 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
Jesse Barnes79e53942008-11-07 14:24:08 -0800628 sizeof(state));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100629 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800630
631 return (status == SDVO_CMD_STATUS_SUCCESS);
632}
633
Chris Wilsonea5b2132010-08-04 13:50:23 +0100634static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800635 int *clock_min,
636 int *clock_max)
637{
638 struct intel_sdvo_pixel_clock_range clocks;
639 u8 status;
640
Chris Wilsonea5b2132010-08-04 13:50:23 +0100641 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
Jesse Barnes79e53942008-11-07 14:24:08 -0800642 NULL, 0);
643
Chris Wilsonea5b2132010-08-04 13:50:23 +0100644 status = intel_sdvo_read_response(intel_sdvo, &clocks, sizeof(clocks));
Jesse Barnes79e53942008-11-07 14:24:08 -0800645
646 if (status != SDVO_CMD_STATUS_SUCCESS)
647 return false;
648
649 /* Convert the values from units of 10 kHz to kHz. */
650 *clock_min = clocks.min * 10;
651 *clock_max = clocks.max * 10;
652
653 return true;
654}
655
Chris Wilsonea5b2132010-08-04 13:50:23 +0100656static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800657 u16 outputs)
658{
659 u8 status;
660
Chris Wilsonea5b2132010-08-04 13:50:23 +0100661 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800662 sizeof(outputs));
663
Chris Wilsonea5b2132010-08-04 13:50:23 +0100664 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800665 return (status == SDVO_CMD_STATUS_SUCCESS);
666}
667
Chris Wilsonea5b2132010-08-04 13:50:23 +0100668static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800669 struct intel_sdvo_dtd *dtd)
670{
671 u8 status;
672
Chris Wilsonea5b2132010-08-04 13:50:23 +0100673 intel_sdvo_write_cmd(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1));
674 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800675 if (status != SDVO_CMD_STATUS_SUCCESS)
676 return false;
677
Chris Wilsonea5b2132010-08-04 13:50:23 +0100678 intel_sdvo_write_cmd(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
679 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800680 if (status != SDVO_CMD_STATUS_SUCCESS)
681 return false;
682
683 return true;
684}
685
Chris Wilsonea5b2132010-08-04 13:50:23 +0100686static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800687 struct intel_sdvo_dtd *dtd)
688{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100689 return intel_sdvo_set_timing(intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800690 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
691}
692
Chris Wilsonea5b2132010-08-04 13:50:23 +0100693static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800694 struct intel_sdvo_dtd *dtd)
695{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100696 return intel_sdvo_set_timing(intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -0800697 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
698}
699
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800700static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +0100701intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800702 uint16_t clock,
703 uint16_t width,
704 uint16_t height)
705{
706 struct intel_sdvo_preferred_input_timing_args args;
707 uint8_t status;
708
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800709 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800710 args.clock = clock;
711 args.width = width;
712 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800713 args.interlace = 0;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800714
Chris Wilsonea5b2132010-08-04 13:50:23 +0100715 if (intel_sdvo->is_lvds &&
716 (intel_sdvo->sdvo_lvds_fixed_mode->hdisplay != width ||
717 intel_sdvo->sdvo_lvds_fixed_mode->vdisplay != height))
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800718 args.scaled = 1;
719
Chris Wilsonea5b2132010-08-04 13:50:23 +0100720 intel_sdvo_write_cmd(intel_sdvo,
Eric Anholtc751ce42010-03-25 11:48:48 -0700721 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800722 &args, sizeof(args));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100723 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800724 if (status != SDVO_CMD_STATUS_SUCCESS)
725 return false;
726
727 return true;
728}
729
Chris Wilsonea5b2132010-08-04 13:50:23 +0100730static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800731 struct intel_sdvo_dtd *dtd)
732{
733 bool status;
734
Chris Wilsonea5b2132010-08-04 13:50:23 +0100735 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800736 NULL, 0);
737
Chris Wilsonea5b2132010-08-04 13:50:23 +0100738 status = intel_sdvo_read_response(intel_sdvo, &dtd->part1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800739 sizeof(dtd->part1));
740 if (status != SDVO_CMD_STATUS_SUCCESS)
741 return false;
742
Chris Wilsonea5b2132010-08-04 13:50:23 +0100743 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800744 NULL, 0);
745
Chris Wilsonea5b2132010-08-04 13:50:23 +0100746 status = intel_sdvo_read_response(intel_sdvo, &dtd->part2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800747 sizeof(dtd->part2));
748 if (status != SDVO_CMD_STATUS_SUCCESS)
749 return false;
750
751 return false;
752}
Jesse Barnes79e53942008-11-07 14:24:08 -0800753
Chris Wilsonea5b2132010-08-04 13:50:23 +0100754static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800755{
756 u8 status;
757
Chris Wilsonea5b2132010-08-04 13:50:23 +0100758 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
759 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800760 if (status != SDVO_CMD_STATUS_SUCCESS)
761 return false;
762
763 return true;
764}
765
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800766static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
767 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800768{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800769 uint16_t width, height;
770 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
771 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800772
773 width = mode->crtc_hdisplay;
774 height = mode->crtc_vdisplay;
775
776 /* do some mode translations */
777 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
778 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
779
780 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
781 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
782
783 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
784 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
785
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800786 dtd->part1.clock = mode->clock / 10;
787 dtd->part1.h_active = width & 0xff;
788 dtd->part1.h_blank = h_blank_len & 0xff;
789 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800790 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800791 dtd->part1.v_active = height & 0xff;
792 dtd->part1.v_blank = v_blank_len & 0xff;
793 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800794 ((v_blank_len >> 8) & 0xf);
795
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800796 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800797 dtd->part2.h_sync_width = h_sync_len & 0xff;
798 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800799 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800800 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800801 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
802 ((v_sync_len & 0x30) >> 4);
803
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800804 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800805 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800806 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800807 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800808 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800809
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800810 dtd->part2.sdvo_flags = 0;
811 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
812 dtd->part2.reserved = 0;
813}
Jesse Barnes79e53942008-11-07 14:24:08 -0800814
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800815static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
816 struct intel_sdvo_dtd *dtd)
817{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800818 mode->hdisplay = dtd->part1.h_active;
819 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
820 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800821 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800822 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
823 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
824 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
825 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
826
827 mode->vdisplay = dtd->part1.v_active;
828 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
829 mode->vsync_start = mode->vdisplay;
830 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800831 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800832 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
833 mode->vsync_end = mode->vsync_start +
834 (dtd->part2.v_sync_off_width & 0xf);
835 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
836 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
837 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
838
839 mode->clock = dtd->part1.clock * 10;
840
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800841 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800842 if (dtd->part2.dtd_flags & 0x2)
843 mode->flags |= DRM_MODE_FLAG_PHSYNC;
844 if (dtd->part2.dtd_flags & 0x4)
845 mode->flags |= DRM_MODE_FLAG_PVSYNC;
846}
847
Chris Wilsonea5b2132010-08-04 13:50:23 +0100848static bool intel_sdvo_get_supp_encode(struct intel_sdvo *intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800849 struct intel_sdvo_encode *encode)
850{
851 uint8_t status;
852
Chris Wilsonea5b2132010-08-04 13:50:23 +0100853 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
854 status = intel_sdvo_read_response(intel_sdvo, encode, sizeof(*encode));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800855 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
856 memset(encode, 0, sizeof(*encode));
857 return false;
858 }
859
860 return true;
861}
862
Chris Wilsonea5b2132010-08-04 13:50:23 +0100863static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
Eric Anholtc751ce42010-03-25 11:48:48 -0700864 uint8_t mode)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800865{
866 uint8_t status;
867
Chris Wilsonea5b2132010-08-04 13:50:23 +0100868 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
869 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800870
871 return (status == SDVO_CMD_STATUS_SUCCESS);
872}
873
Chris Wilsonea5b2132010-08-04 13:50:23 +0100874static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800875 uint8_t mode)
876{
877 uint8_t status;
878
Chris Wilsonea5b2132010-08-04 13:50:23 +0100879 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
880 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800881
882 return (status == SDVO_CMD_STATUS_SUCCESS);
883}
884
885#if 0
Chris Wilsonea5b2132010-08-04 13:50:23 +0100886static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800887{
888 int i, j;
889 uint8_t set_buf_index[2];
890 uint8_t av_split;
891 uint8_t buf_size;
892 uint8_t buf[48];
893 uint8_t *pos;
894
Eric Anholtc751ce42010-03-25 11:48:48 -0700895 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
896 intel_sdvo_read_response(encoder, &av_split, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800897
898 for (i = 0; i <= av_split; i++) {
899 set_buf_index[0] = i; set_buf_index[1] = 0;
Eric Anholtc751ce42010-03-25 11:48:48 -0700900 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800901 set_buf_index, 2);
Eric Anholtc751ce42010-03-25 11:48:48 -0700902 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
903 intel_sdvo_read_response(encoder, &buf_size, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800904
905 pos = buf;
906 for (j = 0; j <= buf_size; j += 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700907 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800908 NULL, 0);
Eric Anholtc751ce42010-03-25 11:48:48 -0700909 intel_sdvo_read_response(encoder, pos, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800910 pos += 8;
911 }
912 }
913}
914#endif
915
Chris Wilsonea5b2132010-08-04 13:50:23 +0100916static void intel_sdvo_set_hdmi_buf(struct intel_sdvo *intel_sdvo,
Eric Anholtc751ce42010-03-25 11:48:48 -0700917 int index,
918 uint8_t *data, int8_t size, uint8_t tx_rate)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800919{
920 uint8_t set_buf_index[2];
921
922 set_buf_index[0] = index;
923 set_buf_index[1] = 0;
924
Chris Wilsonea5b2132010-08-04 13:50:23 +0100925 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_INDEX,
Eric Anholtc751ce42010-03-25 11:48:48 -0700926 set_buf_index, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800927
928 for (; size > 0; size -= 8) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100929 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_DATA, data, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800930 data += 8;
931 }
932
Chris Wilsonea5b2132010-08-04 13:50:23 +0100933 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800934}
935
936static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
937{
938 uint8_t csum = 0;
939 int i;
940
941 for (i = 0; i < size; i++)
942 csum += data[i];
943
944 return 0x100 - csum;
945}
946
947#define DIP_TYPE_AVI 0x82
948#define DIP_VERSION_AVI 0x2
949#define DIP_LEN_AVI 13
950
951struct dip_infoframe {
952 uint8_t type;
953 uint8_t version;
954 uint8_t len;
955 uint8_t checksum;
956 union {
957 struct {
958 /* Packet Byte #1 */
959 uint8_t S:2;
960 uint8_t B:2;
961 uint8_t A:1;
962 uint8_t Y:2;
963 uint8_t rsvd1:1;
964 /* Packet Byte #2 */
965 uint8_t R:4;
966 uint8_t M:2;
967 uint8_t C:2;
968 /* Packet Byte #3 */
969 uint8_t SC:2;
970 uint8_t Q:2;
971 uint8_t EC:3;
972 uint8_t ITC:1;
973 /* Packet Byte #4 */
974 uint8_t VIC:7;
975 uint8_t rsvd2:1;
976 /* Packet Byte #5 */
977 uint8_t PR:4;
978 uint8_t rsvd3:4;
979 /* Packet Byte #6~13 */
980 uint16_t top_bar_end;
981 uint16_t bottom_bar_start;
982 uint16_t left_bar_end;
983 uint16_t right_bar_start;
984 } avi;
985 struct {
986 /* Packet Byte #1 */
987 uint8_t channel_count:3;
988 uint8_t rsvd1:1;
989 uint8_t coding_type:4;
990 /* Packet Byte #2 */
991 uint8_t sample_size:2; /* SS0, SS1 */
992 uint8_t sample_frequency:3;
993 uint8_t rsvd2:3;
994 /* Packet Byte #3 */
995 uint8_t coding_type_private:5;
996 uint8_t rsvd3:3;
997 /* Packet Byte #4 */
998 uint8_t channel_allocation;
999 /* Packet Byte #5 */
1000 uint8_t rsvd4:3;
1001 uint8_t level_shift:4;
1002 uint8_t downmix_inhibit:1;
1003 } audio;
1004 uint8_t payload[28];
1005 } __attribute__ ((packed)) u;
1006} __attribute__((packed));
1007
Chris Wilsonea5b2132010-08-04 13:50:23 +01001008static void intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001009 struct drm_display_mode * mode)
1010{
1011 struct dip_infoframe avi_if = {
1012 .type = DIP_TYPE_AVI,
1013 .version = DIP_VERSION_AVI,
1014 .len = DIP_LEN_AVI,
1015 };
1016
1017 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
1018 4 + avi_if.len);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001019 intel_sdvo_set_hdmi_buf(intel_sdvo, 1, (uint8_t *)&avi_if,
Eric Anholtc751ce42010-03-25 11:48:48 -07001020 4 + avi_if.len,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001021 SDVO_HBUF_TX_VSYNC);
1022}
1023
Chris Wilsonea5b2132010-08-04 13:50:23 +01001024static void intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001025{
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001026
Zhao Yakuice6feab2009-08-24 13:50:26 +08001027 struct intel_sdvo_tv_format format;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001028 uint32_t format_map, i;
1029 uint8_t status;
1030
1031 for (i = 0; i < TV_FORMAT_NUM; i++)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001032 if (tv_format_names[i] == intel_sdvo->tv_format_name)
Zhao Yakuice6feab2009-08-24 13:50:26 +08001033 break;
1034
1035 format_map = 1 << i;
1036 memset(&format, 0, sizeof(format));
1037 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
1038 sizeof(format) : sizeof(format_map));
1039
Chris Wilsonea5b2132010-08-04 13:50:23 +01001040 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_TV_FORMAT, &format,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001041 sizeof(format));
1042
Chris Wilsonea5b2132010-08-04 13:50:23 +01001043 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001044 if (status != SDVO_CMD_STATUS_SUCCESS)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001045 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +01001046 SDVO_NAME(intel_sdvo));
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001047}
1048
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001049static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1050 struct drm_display_mode *mode,
1051 struct drm_display_mode *adjusted_mode)
1052{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001053 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001054
Chris Wilsonea5b2132010-08-04 13:50:23 +01001055 if (intel_sdvo->is_tv) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001056 struct intel_sdvo_dtd output_dtd;
1057 bool success;
1058
1059 /* We need to construct preferred input timings based on our
1060 * output timings. To do that, we have to set the output
1061 * timings, even though this isn't really the right place in
1062 * the sequence to do it. Oh well.
1063 */
1064
1065
1066 /* Set output timings */
1067 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001068 intel_sdvo_set_target_output(intel_sdvo,
1069 intel_sdvo->attached_output);
1070 intel_sdvo_set_output_timing(intel_sdvo, &output_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001071
1072 /* Set the input timing to the screen. Assume always input 0. */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001073 intel_sdvo_set_target_input(intel_sdvo, true, false);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001074
1075
Chris Wilsonea5b2132010-08-04 13:50:23 +01001076 success = intel_sdvo_create_preferred_input_timing(intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001077 mode->clock / 10,
1078 mode->hdisplay,
1079 mode->vdisplay);
1080 if (success) {
1081 struct intel_sdvo_dtd input_dtd;
1082
Chris Wilsonea5b2132010-08-04 13:50:23 +01001083 intel_sdvo_get_preferred_input_timing(intel_sdvo,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001084 &input_dtd);
1085 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001086 intel_sdvo->sdvo_flags = input_dtd.part2.sdvo_flags;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001087
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001088 drm_mode_set_crtcinfo(adjusted_mode, 0);
1089
1090 mode->clock = adjusted_mode->clock;
1091
1092 adjusted_mode->clock *=
1093 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001094 } else {
1095 return false;
1096 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001097 } else if (intel_sdvo->is_lvds) {
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001098 struct intel_sdvo_dtd output_dtd;
1099 bool success;
1100
Chris Wilsonea5b2132010-08-04 13:50:23 +01001101 drm_mode_set_crtcinfo(intel_sdvo->sdvo_lvds_fixed_mode, 0);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001102 /* Set output timings */
1103 intel_sdvo_get_dtd_from_mode(&output_dtd,
Chris Wilsonea5b2132010-08-04 13:50:23 +01001104 intel_sdvo->sdvo_lvds_fixed_mode);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001105
Chris Wilsonea5b2132010-08-04 13:50:23 +01001106 intel_sdvo_set_target_output(intel_sdvo,
1107 intel_sdvo->attached_output);
1108 intel_sdvo_set_output_timing(intel_sdvo, &output_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001109
1110 /* Set the input timing to the screen. Assume always input 0. */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001111 intel_sdvo_set_target_input(intel_sdvo, true, false);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001112
1113
1114 success = intel_sdvo_create_preferred_input_timing(
Chris Wilsonea5b2132010-08-04 13:50:23 +01001115 intel_sdvo,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001116 mode->clock / 10,
1117 mode->hdisplay,
1118 mode->vdisplay);
1119
1120 if (success) {
1121 struct intel_sdvo_dtd input_dtd;
1122
Chris Wilsonea5b2132010-08-04 13:50:23 +01001123 intel_sdvo_get_preferred_input_timing(intel_sdvo,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001124 &input_dtd);
1125 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001126 intel_sdvo->sdvo_flags = input_dtd.part2.sdvo_flags;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001127
1128 drm_mode_set_crtcinfo(adjusted_mode, 0);
1129
1130 mode->clock = adjusted_mode->clock;
1131
1132 adjusted_mode->clock *=
1133 intel_sdvo_get_pixel_multiplier(mode);
1134 } else {
1135 return false;
1136 }
1137
1138 } else {
1139 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1140 * SDVO device will be told of the multiplier during mode_set.
1141 */
1142 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001143 }
1144 return true;
1145}
1146
1147static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1148 struct drm_display_mode *mode,
1149 struct drm_display_mode *adjusted_mode)
1150{
1151 struct drm_device *dev = encoder->dev;
1152 struct drm_i915_private *dev_priv = dev->dev_private;
1153 struct drm_crtc *crtc = encoder->crtc;
1154 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001155 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001156 u32 sdvox = 0;
1157 int sdvo_pixel_multiply;
1158 struct intel_sdvo_in_out_map in_out;
1159 struct intel_sdvo_dtd input_dtd;
1160 u8 status;
1161
1162 if (!mode)
1163 return;
1164
1165 /* First, set the input mapping for the first input to our controlled
1166 * output. This is only correct if we're a single-input device, in
1167 * which case the first input is the output from the appropriate SDVO
1168 * channel on the motherboard. In a two-input device, the first input
1169 * will be SDVOB and the second SDVOC.
1170 */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001171 in_out.in0 = intel_sdvo->attached_output;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001172 in_out.in1 = 0;
1173
Chris Wilsonea5b2132010-08-04 13:50:23 +01001174 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_IN_OUT_MAP,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001175 &in_out, sizeof(in_out));
Chris Wilsonea5b2132010-08-04 13:50:23 +01001176 status = intel_sdvo_read_response(intel_sdvo, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001177
Chris Wilsonea5b2132010-08-04 13:50:23 +01001178 if (intel_sdvo->is_hdmi) {
1179 intel_sdvo_set_avi_infoframe(intel_sdvo, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001180 sdvox |= SDVO_AUDIO_ENABLE;
1181 }
1182
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001183 /* We have tried to get input timing in mode_fixup, and filled into
1184 adjusted_mode */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001185 if (intel_sdvo->is_tv || intel_sdvo->is_lvds) {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001186 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001187 input_dtd.part2.sdvo_flags = intel_sdvo->sdvo_flags;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001188 } else
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001189 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001190
1191 /* If it's a TV, we already set the output timing in mode_fixup.
1192 * Otherwise, the output timing is equal to the input timing.
1193 */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001194 if (!intel_sdvo->is_tv && !intel_sdvo->is_lvds) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001195 /* Set the output timing to the screen */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001196 intel_sdvo_set_target_output(intel_sdvo,
1197 intel_sdvo->attached_output);
1198 intel_sdvo_set_output_timing(intel_sdvo, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001199 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001200
1201 /* Set the input timing to the screen. Assume always input 0. */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001202 intel_sdvo_set_target_input(intel_sdvo, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001203
Chris Wilsonea5b2132010-08-04 13:50:23 +01001204 if (intel_sdvo->is_tv)
1205 intel_sdvo_set_tv_format(intel_sdvo);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001206
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001207 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001208 * provide the device with a timing it can support, if it supports that
1209 * feature. However, presumably we would need to adjust the CRTC to
1210 * output the preferred timing, and we don't support that currently.
1211 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001212#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -07001213 success = intel_sdvo_create_preferred_input_timing(encoder, clock,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001214 width, height);
1215 if (success) {
1216 struct intel_sdvo_dtd *input_dtd;
1217
Eric Anholtc751ce42010-03-25 11:48:48 -07001218 intel_sdvo_get_preferred_input_timing(encoder, &input_dtd);
1219 intel_sdvo_set_input_timing(encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001220 }
1221#else
Chris Wilsonea5b2132010-08-04 13:50:23 +01001222 intel_sdvo_set_input_timing(intel_sdvo, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001223#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001224
1225 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1226 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +01001227 intel_sdvo_set_clock_rate_mult(intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -08001228 SDVO_CLOCK_RATE_MULT_1X);
1229 break;
1230 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +01001231 intel_sdvo_set_clock_rate_mult(intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -08001232 SDVO_CLOCK_RATE_MULT_2X);
1233 break;
1234 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +01001235 intel_sdvo_set_clock_rate_mult(intel_sdvo,
Jesse Barnes79e53942008-11-07 14:24:08 -08001236 SDVO_CLOCK_RATE_MULT_4X);
1237 break;
1238 }
1239
1240 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001241 if (IS_I965G(dev)) {
Adam Jackson81a14b42010-07-16 14:46:32 -04001242 sdvox |= SDVO_BORDER_ENABLE;
1243 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1244 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
1245 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1246 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001247 } else {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001248 sdvox |= I915_READ(intel_sdvo->sdvo_reg);
1249 switch (intel_sdvo->sdvo_reg) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001250 case SDVOB:
1251 sdvox &= SDVOB_PRESERVE_MASK;
1252 break;
1253 case SDVOC:
1254 sdvox &= SDVOC_PRESERVE_MASK;
1255 break;
1256 }
1257 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1258 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001259 if (intel_crtc->pipe == 1)
1260 sdvox |= SDVO_PIPE_B_SELECT;
1261
1262 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1263 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001264 /* done in crtc_mode_set as the dpll_md reg must be written early */
1265 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1266 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001267 } else {
1268 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1269 }
1270
Chris Wilsonea5b2132010-08-04 13:50:23 +01001271 if (intel_sdvo->sdvo_flags & SDVO_NEED_TO_STALL)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001272 sdvox |= SDVO_STALL_SELECT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001273 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001274}
1275
1276static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1277{
1278 struct drm_device *dev = encoder->dev;
1279 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001280 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08001281 u32 temp;
1282
1283 if (mode != DRM_MODE_DPMS_ON) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001284 intel_sdvo_set_active_outputs(intel_sdvo, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -08001285 if (0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001286 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -08001287
1288 if (mode == DRM_MODE_DPMS_OFF) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001289 temp = I915_READ(intel_sdvo->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001290 if ((temp & SDVO_ENABLE) != 0) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001291 intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001292 }
1293 }
1294 } else {
1295 bool input1, input2;
1296 int i;
1297 u8 status;
1298
Chris Wilsonea5b2132010-08-04 13:50:23 +01001299 temp = I915_READ(intel_sdvo->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001300 if ((temp & SDVO_ENABLE) == 0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001301 intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001302 for (i = 0; i < 2; i++)
1303 intel_wait_for_vblank(dev);
1304
Chris Wilsonea5b2132010-08-04 13:50:23 +01001305 status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1,
Jesse Barnes79e53942008-11-07 14:24:08 -08001306 &input2);
1307
1308
1309 /* Warn if the device reported failure to sync.
1310 * A lot of SDVO devices fail to notify of sync, but it's
1311 * a given it the status is a success, we succeeded.
1312 */
1313 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001314 DRM_DEBUG_KMS("First %s output reported failure to "
Chris Wilsonea5b2132010-08-04 13:50:23 +01001315 "sync\n", SDVO_NAME(intel_sdvo));
Jesse Barnes79e53942008-11-07 14:24:08 -08001316 }
1317
1318 if (0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001319 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1320 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001321 }
1322 return;
1323}
1324
Jesse Barnes79e53942008-11-07 14:24:08 -08001325static int intel_sdvo_mode_valid(struct drm_connector *connector,
1326 struct drm_display_mode *mode)
1327{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001328 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001329 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08001330
1331 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1332 return MODE_NO_DBLESCAN;
1333
Chris Wilsonea5b2132010-08-04 13:50:23 +01001334 if (intel_sdvo->pixel_clock_min > mode->clock)
Jesse Barnes79e53942008-11-07 14:24:08 -08001335 return MODE_CLOCK_LOW;
1336
Chris Wilsonea5b2132010-08-04 13:50:23 +01001337 if (intel_sdvo->pixel_clock_max < mode->clock)
Jesse Barnes79e53942008-11-07 14:24:08 -08001338 return MODE_CLOCK_HIGH;
1339
Chris Wilsonea5b2132010-08-04 13:50:23 +01001340 if (intel_sdvo->is_lvds == true) {
1341 if (intel_sdvo->sdvo_lvds_fixed_mode == NULL)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001342 return MODE_PANEL;
1343
Chris Wilsonea5b2132010-08-04 13:50:23 +01001344 if (mode->hdisplay > intel_sdvo->sdvo_lvds_fixed_mode->hdisplay)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001345 return MODE_PANEL;
1346
Chris Wilsonea5b2132010-08-04 13:50:23 +01001347 if (mode->vdisplay > intel_sdvo->sdvo_lvds_fixed_mode->vdisplay)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001348 return MODE_PANEL;
1349 }
1350
Jesse Barnes79e53942008-11-07 14:24:08 -08001351 return MODE_OK;
1352}
1353
Chris Wilsonea5b2132010-08-04 13:50:23 +01001354static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
Jesse Barnes79e53942008-11-07 14:24:08 -08001355{
1356 u8 status;
1357
Chris Wilsonea5b2132010-08-04 13:50:23 +01001358 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1359 status = intel_sdvo_read_response(intel_sdvo, caps, sizeof(*caps));
Jesse Barnes79e53942008-11-07 14:24:08 -08001360 if (status != SDVO_CMD_STATUS_SUCCESS)
1361 return false;
1362
1363 return true;
1364}
1365
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001366/* No use! */
1367#if 0
Jesse Barnes79e53942008-11-07 14:24:08 -08001368struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1369{
1370 struct drm_connector *connector = NULL;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001371 struct intel_sdvo *iout = NULL;
1372 struct intel_sdvo *sdvo;
Jesse Barnes79e53942008-11-07 14:24:08 -08001373
1374 /* find the sdvo connector */
1375 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001376 iout = to_intel_sdvo(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001377
1378 if (iout->type != INTEL_OUTPUT_SDVO)
1379 continue;
1380
1381 sdvo = iout->dev_priv;
1382
Eric Anholtc751ce42010-03-25 11:48:48 -07001383 if (sdvo->sdvo_reg == SDVOB && sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001384 return connector;
1385
Eric Anholtc751ce42010-03-25 11:48:48 -07001386 if (sdvo->sdvo_reg == SDVOC && !sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001387 return connector;
1388
1389 }
1390
1391 return NULL;
1392}
1393
1394int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1395{
1396 u8 response[2];
1397 u8 status;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001398 struct intel_sdvo *intel_sdvo;
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001399 DRM_DEBUG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -08001400
1401 if (!connector)
1402 return 0;
1403
Chris Wilsonea5b2132010-08-04 13:50:23 +01001404 intel_sdvo = to_intel_sdvo(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001405
Chris Wilsonea5b2132010-08-04 13:50:23 +01001406 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1407 status = intel_sdvo_read_response(intel_sdvo, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001408
1409 if (response[0] !=0)
1410 return 1;
1411
1412 return 0;
1413}
1414
1415void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1416{
1417 u8 response[2];
1418 u8 status;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001419 struct intel_sdvo *intel_sdvo = to_intel_sdvo(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001420
Chris Wilsonea5b2132010-08-04 13:50:23 +01001421 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1422 intel_sdvo_read_response(intel_sdvo, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001423
1424 if (on) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001425 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1426 status = intel_sdvo_read_response(intel_sdvo, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001427
Chris Wilsonea5b2132010-08-04 13:50:23 +01001428 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001429 } else {
1430 response[0] = 0;
1431 response[1] = 0;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001432 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001433 }
1434
Chris Wilsonea5b2132010-08-04 13:50:23 +01001435 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1436 intel_sdvo_read_response(intel_sdvo, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001437}
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001438#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001439
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001440static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001441intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001442{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001443 int caps = 0;
1444
Chris Wilsonea5b2132010-08-04 13:50:23 +01001445 if (intel_sdvo->caps.output_flags &
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001446 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1447 caps++;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001448 if (intel_sdvo->caps.output_flags &
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001449 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1450 caps++;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001451 if (intel_sdvo->caps.output_flags &
Roel Kluin19e1f882009-08-09 13:50:53 +02001452 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001453 caps++;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001454 if (intel_sdvo->caps.output_flags &
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001455 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1456 caps++;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001457 if (intel_sdvo->caps.output_flags &
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001458 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1459 caps++;
1460
Chris Wilsonea5b2132010-08-04 13:50:23 +01001461 if (intel_sdvo->caps.output_flags &
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001462 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1463 caps++;
1464
Chris Wilsonea5b2132010-08-04 13:50:23 +01001465 if (intel_sdvo->caps.output_flags &
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001466 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1467 caps++;
1468
1469 return (caps > 1);
1470}
1471
Keith Packard57cdaf92009-09-04 13:07:54 +08001472static struct drm_connector *
1473intel_find_analog_connector(struct drm_device *dev)
1474{
1475 struct drm_connector *connector;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001476 struct drm_encoder *encoder;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001477 struct intel_sdvo *intel_sdvo;
Keith Packard57cdaf92009-09-04 13:07:54 +08001478
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001479 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001480 intel_sdvo = enc_to_intel_sdvo(encoder);
1481 if (intel_sdvo->base.type == INTEL_OUTPUT_ANALOG) {
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001482 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Dan Carpenter90a78e82010-05-07 10:40:09 +02001483 if (encoder == intel_attached_encoder(connector))
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001484 return connector;
1485 }
1486 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001487 }
1488 return NULL;
1489}
1490
1491static int
1492intel_analog_is_connected(struct drm_device *dev)
1493{
1494 struct drm_connector *analog_connector;
1495 analog_connector = intel_find_analog_connector(dev);
1496
1497 if (!analog_connector)
1498 return false;
1499
1500 if (analog_connector->funcs->detect(analog_connector) ==
1501 connector_status_disconnected)
1502 return false;
1503
1504 return true;
1505}
1506
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001507enum drm_connector_status
Adam Jackson149c36a2010-04-29 14:05:18 -04001508intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
Ma Ling9dff6af2009-04-02 13:13:26 +08001509{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001510 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001511 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Chris Wilson615fb932010-08-04 13:50:24 +01001512 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001513 enum drm_connector_status status = connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001514 struct edid *edid = NULL;
1515
Chris Wilsonea5b2132010-08-04 13:50:23 +01001516 edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001517
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001518 /* This is only applied to SDVO cards with multiple outputs */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001519 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001520 uint8_t saved_ddc, temp_ddc;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001521 saved_ddc = intel_sdvo->ddc_bus;
1522 temp_ddc = intel_sdvo->ddc_bus >> 1;
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001523 /*
1524 * Don't use the 1 as the argument of DDC bus switch to get
1525 * the EDID. It is used for SDVO SPD ROM.
1526 */
1527 while(temp_ddc > 1) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001528 intel_sdvo->ddc_bus = temp_ddc;
1529 edid = drm_get_edid(connector, intel_sdvo->base.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 */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001535 intel_sdvo->ddc_bus = temp_ddc;
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001536 break;
1537 }
1538 temp_ddc >>= 1;
1539 }
1540 if (edid == NULL)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001541 intel_sdvo->ddc_bus = saved_ddc;
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001542 }
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 */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001546 if (edid == NULL && intel_sdvo->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001547 !intel_analog_is_connected(connector->dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01001548 edid = drm_get_edid(connector, intel_sdvo->analog_ddc_bus);
Adam Jackson149c36a2010-04-29 14:05:18 -04001549
Ma Ling9dff6af2009-04-02 13:13:26 +08001550 if (edid != NULL) {
Adam Jackson149c36a2010-04-29 14:05:18 -04001551 bool is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
Chris Wilson615fb932010-08-04 13:50:24 +01001552 bool need_digital = !!(intel_sdvo_connector->output_flag & SDVO_TMDS_MASK);
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001553
Adam Jackson149c36a2010-04-29 14:05:18 -04001554 /* DDC bus is shared, match EDID to connector type */
1555 if (is_digital && need_digital)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001556 intel_sdvo->is_hdmi = drm_detect_hdmi_monitor(edid);
Adam Jackson149c36a2010-04-29 14:05:18 -04001557 else if (is_digital != need_digital)
1558 status = connector_status_disconnected;
1559
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001560 connector->display_info.raw_edid = NULL;
Adam Jackson149c36a2010-04-29 14:05:18 -04001561 } else
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001562 status = connector_status_disconnected;
Adam Jackson149c36a2010-04-29 14:05:18 -04001563
1564 kfree(edid);
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001565
1566 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +08001567}
1568
Jesse Barnes79e53942008-11-07 14:24:08 -08001569static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1570{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001571 uint16_t response;
Jesse Barnes79e53942008-11-07 14:24:08 -08001572 u8 status;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001573 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001574 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Chris Wilson615fb932010-08-04 13:50:24 +01001575 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001576 enum drm_connector_status ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001577
Chris Wilsonea5b2132010-08-04 13:50:23 +01001578 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001579 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001580 if (intel_sdvo->is_tv) {
Zhao Yakuid09c23d2009-11-06 15:39:56 +08001581 /* add 30ms delay when the output type is SDVO-TV */
1582 mdelay(30);
1583 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001584 status = intel_sdvo_read_response(intel_sdvo, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001585
Dave Airlie51c8b402009-08-20 13:38:04 +10001586 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001587
1588 if (status != SDVO_CMD_STATUS_SUCCESS)
1589 return connector_status_unknown;
1590
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001591 if (response == 0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001592 return connector_status_disconnected;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001593
Chris Wilsonea5b2132010-08-04 13:50:23 +01001594 intel_sdvo->attached_output = response;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001595
Chris Wilson615fb932010-08-04 13:50:24 +01001596 if ((intel_sdvo_connector->output_flag & response) == 0)
Zhenyu Wang14571b42010-03-30 14:06:33 +08001597 ret = connector_status_disconnected;
Adam Jackson149c36a2010-04-29 14:05:18 -04001598 else if (response & SDVO_TMDS_MASK)
1599 ret = intel_sdvo_hdmi_sink_detect(connector);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001600 else
1601 ret = connector_status_connected;
1602
1603 /* May update encoder flag for like clock for SDVO TV, etc.*/
1604 if (ret == connector_status_connected) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001605 intel_sdvo->is_tv = false;
1606 intel_sdvo->is_lvds = false;
1607 intel_sdvo->base.needs_tv_clock = false;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001608
1609 if (response & SDVO_TV_MASK) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001610 intel_sdvo->is_tv = true;
1611 intel_sdvo->base.needs_tv_clock = true;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001612 }
1613 if (response & SDVO_LVDS_MASK)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001614 intel_sdvo->is_lvds = true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001615 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001616
1617 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001618}
1619
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001620static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001621{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001622 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001623 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Keith Packard57cdaf92009-09-04 13:07:54 +08001624 int num_modes;
Jesse Barnes79e53942008-11-07 14:24:08 -08001625
1626 /* set the bus switch and get the modes */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001627 num_modes = intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001628
Keith Packard57cdaf92009-09-04 13:07:54 +08001629 /*
1630 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1631 * link between analog and digital outputs. So, if the regular SDVO
1632 * DDC fails, check to see if the analog output is disconnected, in
1633 * which case we'll look there for the digital DDC data.
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001634 */
Keith Packard57cdaf92009-09-04 13:07:54 +08001635 if (num_modes == 0 &&
Chris Wilsonea5b2132010-08-04 13:50:23 +01001636 intel_sdvo->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001637 !intel_analog_is_connected(connector->dev)) {
Keith Packard57cdaf92009-09-04 13:07:54 +08001638 /* Switch to the analog ddc bus and try that
1639 */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001640 (void) intel_ddc_get_modes(connector, intel_sdvo->analog_ddc_bus);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001641 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001642}
1643
1644/*
1645 * Set of SDVO TV modes.
1646 * Note! This is in reply order (see loop in get_tv_modes).
1647 * XXX: all 60Hz refresh?
1648 */
1649struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001650 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1651 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001652 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001653 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1654 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001655 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001656 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1657 496, 0, 300, 301, 332, 333, 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("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1660 736, 0, 350, 351, 382, 383, 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("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1663 736, 0, 400, 401, 432, 433, 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("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1666 736, 0, 480, 481, 512, 513, 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("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1669 800, 0, 480, 481, 512, 513, 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("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1672 800, 0, 576, 577, 608, 609, 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("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1675 816, 0, 350, 351, 382, 383, 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("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1678 816, 0, 400, 401, 432, 433, 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("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1681 816, 0, 480, 481, 512, 513, 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("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1684 816, 0, 540, 541, 572, 573, 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("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1687 816, 0, 576, 577, 608, 609, 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("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1690 864, 0, 576, 577, 608, 609, 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("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1693 896, 0, 600, 601, 632, 633, 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("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1696 928, 0, 624, 625, 656, 657, 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("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1699 1016, 0, 766, 767, 798, 799, 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("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1702 1120, 0, 768, 769, 800, 801, 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("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1705 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001706 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1707};
1708
1709static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1710{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001711 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001712 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001713 struct intel_sdvo_sdtv_resolution_request tv_res;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001714 uint32_t reply = 0, format_map = 0;
1715 int i;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001716 uint8_t status;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001717
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001718
1719 /* Read the list of supported input resolutions for the selected TV
1720 * format.
1721 */
Zhao Yakuice6feab2009-08-24 13:50:26 +08001722 for (i = 0; i < TV_FORMAT_NUM; i++)
Chris Wilsonea5b2132010-08-04 13:50:23 +01001723 if (tv_format_names[i] == intel_sdvo->tv_format_name)
Zhao Yakuice6feab2009-08-24 13:50:26 +08001724 break;
1725
1726 format_map = (1 << i);
1727 memcpy(&tv_res, &format_map,
1728 sizeof(struct intel_sdvo_sdtv_resolution_request) >
1729 sizeof(format_map) ? sizeof(format_map) :
1730 sizeof(struct intel_sdvo_sdtv_resolution_request));
1731
Chris Wilsonea5b2132010-08-04 13:50:23 +01001732 intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001733
Chris Wilsonea5b2132010-08-04 13:50:23 +01001734 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001735 &tv_res, sizeof(tv_res));
Chris Wilsonea5b2132010-08-04 13:50:23 +01001736 status = intel_sdvo_read_response(intel_sdvo, &reply, 3);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001737 if (status != SDVO_CMD_STATUS_SUCCESS)
1738 return;
1739
1740 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001741 if (reply & (1 << i)) {
1742 struct drm_display_mode *nmode;
1743 nmode = drm_mode_duplicate(connector->dev,
1744 &sdvo_tv_modes[i]);
1745 if (nmode)
1746 drm_mode_probed_add(connector, nmode);
1747 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001748
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001749}
1750
Ma Ling7086c872009-05-13 11:20:06 +08001751static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1752{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001753 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001754 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Ma Ling7086c872009-05-13 11:20:06 +08001755 struct drm_i915_private *dev_priv = connector->dev->dev_private;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001756 struct drm_display_mode *newmode;
Ma Ling7086c872009-05-13 11:20:06 +08001757
1758 /*
1759 * Attempt to get the mode list from DDC.
1760 * Assume that the preferred modes are
1761 * arranged in priority order.
1762 */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001763 intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus);
Ma Ling7086c872009-05-13 11:20:06 +08001764 if (list_empty(&connector->probed_modes) == false)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001765 goto end;
Ma Ling7086c872009-05-13 11:20:06 +08001766
1767 /* Fetch modes from VBT */
1768 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
Ma Ling7086c872009-05-13 11:20:06 +08001769 newmode = drm_mode_duplicate(connector->dev,
1770 dev_priv->sdvo_lvds_vbt_mode);
1771 if (newmode != NULL) {
1772 /* Guarantee the mode is preferred */
1773 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1774 DRM_MODE_TYPE_DRIVER);
1775 drm_mode_probed_add(connector, newmode);
1776 }
1777 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001778
1779end:
1780 list_for_each_entry(newmode, &connector->probed_modes, head) {
1781 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001782 intel_sdvo->sdvo_lvds_fixed_mode =
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001783 drm_mode_duplicate(connector->dev, newmode);
1784 break;
1785 }
1786 }
1787
Ma Ling7086c872009-05-13 11:20:06 +08001788}
1789
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001790static int intel_sdvo_get_modes(struct drm_connector *connector)
1791{
Chris Wilson615fb932010-08-04 13:50:24 +01001792 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001793
Chris Wilson615fb932010-08-04 13:50:24 +01001794 if (IS_TV(intel_sdvo_connector))
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001795 intel_sdvo_get_tv_modes(connector);
Chris Wilson615fb932010-08-04 13:50:24 +01001796 else if (IS_LVDS(intel_sdvo_connector))
Ma Ling7086c872009-05-13 11:20:06 +08001797 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001798 else
1799 intel_sdvo_get_ddc_modes(connector);
1800
Jesse Barnes79e53942008-11-07 14:24:08 -08001801 if (list_empty(&connector->probed_modes))
1802 return 0;
1803 return 1;
1804}
1805
Zhao Yakuib9219c52009-09-10 15:45:46 +08001806static
1807void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1808{
Chris Wilson615fb932010-08-04 13:50:24 +01001809 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Zhao Yakuib9219c52009-09-10 15:45:46 +08001810 struct drm_device *dev = connector->dev;
1811
Chris Wilson615fb932010-08-04 13:50:24 +01001812 if (IS_TV(intel_sdvo_connector)) {
1813 if (intel_sdvo_connector->left_property)
1814 drm_property_destroy(dev, intel_sdvo_connector->left_property);
1815 if (intel_sdvo_connector->right_property)
1816 drm_property_destroy(dev, intel_sdvo_connector->right_property);
1817 if (intel_sdvo_connector->top_property)
1818 drm_property_destroy(dev, intel_sdvo_connector->top_property);
1819 if (intel_sdvo_connector->bottom_property)
1820 drm_property_destroy(dev, intel_sdvo_connector->bottom_property);
1821 if (intel_sdvo_connector->hpos_property)
1822 drm_property_destroy(dev, intel_sdvo_connector->hpos_property);
1823 if (intel_sdvo_connector->vpos_property)
1824 drm_property_destroy(dev, intel_sdvo_connector->vpos_property);
1825 if (intel_sdvo_connector->saturation_property)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001826 drm_property_destroy(dev,
Chris Wilson615fb932010-08-04 13:50:24 +01001827 intel_sdvo_connector->saturation_property);
1828 if (intel_sdvo_connector->contrast_property)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001829 drm_property_destroy(dev,
Chris Wilson615fb932010-08-04 13:50:24 +01001830 intel_sdvo_connector->contrast_property);
1831 if (intel_sdvo_connector->hue_property)
1832 drm_property_destroy(dev, intel_sdvo_connector->hue_property);
Zhao Yakuib9219c52009-09-10 15:45:46 +08001833 }
Chris Wilson615fb932010-08-04 13:50:24 +01001834 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector)) {
1835 if (intel_sdvo_connector->brightness_property)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001836 drm_property_destroy(dev,
Chris Wilson615fb932010-08-04 13:50:24 +01001837 intel_sdvo_connector->brightness_property);
Zhao Yakuib9219c52009-09-10 15:45:46 +08001838 }
1839 return;
1840}
1841
Jesse Barnes79e53942008-11-07 14:24:08 -08001842static void intel_sdvo_destroy(struct drm_connector *connector)
1843{
Chris Wilson615fb932010-08-04 13:50:24 +01001844 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001845
Chris Wilson615fb932010-08-04 13:50:24 +01001846 if (intel_sdvo_connector->tv_format_property)
Zhao Yakuice6feab2009-08-24 13:50:26 +08001847 drm_property_destroy(connector->dev,
Chris Wilson615fb932010-08-04 13:50:24 +01001848 intel_sdvo_connector->tv_format_property);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001849
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001850 intel_sdvo_destroy_enhance_property(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001851 drm_sysfs_connector_remove(connector);
1852 drm_connector_cleanup(connector);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001853 kfree(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001854}
1855
Zhao Yakuice6feab2009-08-24 13:50:26 +08001856static int
1857intel_sdvo_set_property(struct drm_connector *connector,
1858 struct drm_property *property,
1859 uint64_t val)
1860{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001861 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001862 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Chris Wilson615fb932010-08-04 13:50:24 +01001863 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001864 struct drm_crtc *crtc = encoder->crtc;
1865 int ret = 0;
1866 bool changed = false;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001867 uint8_t cmd, status;
1868 uint16_t temp_value;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001869
1870 ret = drm_connector_property_set_value(connector, property, val);
1871 if (ret < 0)
1872 goto out;
1873
Chris Wilson615fb932010-08-04 13:50:24 +01001874 if (property == intel_sdvo_connector->tv_format_property) {
Zhao Yakuice6feab2009-08-24 13:50:26 +08001875 if (val >= TV_FORMAT_NUM) {
1876 ret = -EINVAL;
1877 goto out;
1878 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001879 if (intel_sdvo->tv_format_name ==
Chris Wilson615fb932010-08-04 13:50:24 +01001880 intel_sdvo_connector->tv_format_supported[val])
Zhao Yakuice6feab2009-08-24 13:50:26 +08001881 goto out;
1882
Chris Wilson615fb932010-08-04 13:50:24 +01001883 intel_sdvo->tv_format_name = intel_sdvo_connector->tv_format_supported[val];
Zhao Yakuice6feab2009-08-24 13:50:26 +08001884 changed = true;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001885 }
1886
Chris Wilson615fb932010-08-04 13:50:24 +01001887 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001888 cmd = 0;
1889 temp_value = val;
Chris Wilson615fb932010-08-04 13:50:24 +01001890 if (intel_sdvo_connector->left_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001891 drm_connector_property_set_value(connector,
Chris Wilson615fb932010-08-04 13:50:24 +01001892 intel_sdvo_connector->right_property, val);
1893 if (intel_sdvo_connector->left_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001894 goto out;
1895
Chris Wilson615fb932010-08-04 13:50:24 +01001896 intel_sdvo_connector->left_margin = temp_value;
1897 intel_sdvo_connector->right_margin = temp_value;
1898 temp_value = intel_sdvo_connector->max_hscan -
1899 intel_sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001900 cmd = SDVO_CMD_SET_OVERSCAN_H;
Chris Wilson615fb932010-08-04 13:50:24 +01001901 } else if (intel_sdvo_connector->right_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001902 drm_connector_property_set_value(connector,
Chris Wilson615fb932010-08-04 13:50:24 +01001903 intel_sdvo_connector->left_property, val);
1904 if (intel_sdvo_connector->right_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001905 goto out;
1906
Chris Wilson615fb932010-08-04 13:50:24 +01001907 intel_sdvo_connector->left_margin = temp_value;
1908 intel_sdvo_connector->right_margin = temp_value;
1909 temp_value = intel_sdvo_connector->max_hscan -
1910 intel_sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001911 cmd = SDVO_CMD_SET_OVERSCAN_H;
Chris Wilson615fb932010-08-04 13:50:24 +01001912 } else if (intel_sdvo_connector->top_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001913 drm_connector_property_set_value(connector,
Chris Wilson615fb932010-08-04 13:50:24 +01001914 intel_sdvo_connector->bottom_property, val);
1915 if (intel_sdvo_connector->top_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001916 goto out;
1917
Chris Wilson615fb932010-08-04 13:50:24 +01001918 intel_sdvo_connector->top_margin = temp_value;
1919 intel_sdvo_connector->bottom_margin = temp_value;
1920 temp_value = intel_sdvo_connector->max_vscan -
1921 intel_sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001922 cmd = SDVO_CMD_SET_OVERSCAN_V;
Chris Wilson615fb932010-08-04 13:50:24 +01001923 } else if (intel_sdvo_connector->bottom_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001924 drm_connector_property_set_value(connector,
Chris Wilson615fb932010-08-04 13:50:24 +01001925 intel_sdvo_connector->top_property, val);
1926 if (intel_sdvo_connector->bottom_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001927 goto out;
Chris Wilson615fb932010-08-04 13:50:24 +01001928 intel_sdvo_connector->top_margin = temp_value;
1929 intel_sdvo_connector->bottom_margin = temp_value;
1930 temp_value = intel_sdvo_connector->max_vscan -
1931 intel_sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001932 cmd = SDVO_CMD_SET_OVERSCAN_V;
Chris Wilson615fb932010-08-04 13:50:24 +01001933 } else if (intel_sdvo_connector->hpos_property == property) {
1934 if (intel_sdvo_connector->cur_hpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001935 goto out;
1936
1937 cmd = SDVO_CMD_SET_POSITION_H;
Chris Wilson615fb932010-08-04 13:50:24 +01001938 intel_sdvo_connector->cur_hpos = temp_value;
1939 } else if (intel_sdvo_connector->vpos_property == property) {
1940 if (intel_sdvo_connector->cur_vpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001941 goto out;
1942
1943 cmd = SDVO_CMD_SET_POSITION_V;
Chris Wilson615fb932010-08-04 13:50:24 +01001944 intel_sdvo_connector->cur_vpos = temp_value;
1945 } else if (intel_sdvo_connector->saturation_property == property) {
1946 if (intel_sdvo_connector->cur_saturation == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001947 goto out;
1948
1949 cmd = SDVO_CMD_SET_SATURATION;
Chris Wilson615fb932010-08-04 13:50:24 +01001950 intel_sdvo_connector->cur_saturation = temp_value;
1951 } else if (intel_sdvo_connector->contrast_property == property) {
1952 if (intel_sdvo_connector->cur_contrast == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001953 goto out;
1954
1955 cmd = SDVO_CMD_SET_CONTRAST;
Chris Wilson615fb932010-08-04 13:50:24 +01001956 intel_sdvo_connector->cur_contrast = temp_value;
1957 } else if (intel_sdvo_connector->hue_property == property) {
1958 if (intel_sdvo_connector->cur_hue == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001959 goto out;
1960
1961 cmd = SDVO_CMD_SET_HUE;
Chris Wilson615fb932010-08-04 13:50:24 +01001962 intel_sdvo_connector->cur_hue = temp_value;
1963 } else if (intel_sdvo_connector->brightness_property == property) {
1964 if (intel_sdvo_connector->cur_brightness == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001965 goto out;
1966
1967 cmd = SDVO_CMD_SET_BRIGHTNESS;
Chris Wilson615fb932010-08-04 13:50:24 +01001968 intel_sdvo_connector->cur_brightness = temp_value;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001969 }
1970 if (cmd) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001971 intel_sdvo_write_cmd(intel_sdvo, cmd, &temp_value, 2);
1972 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08001973 NULL, 0);
1974 if (status != SDVO_CMD_STATUS_SUCCESS) {
1975 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1976 return -EINVAL;
1977 }
1978 changed = true;
1979 }
1980 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001981 if (changed && crtc)
1982 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1983 crtc->y, crtc->fb);
1984out:
1985 return ret;
1986}
1987
Jesse Barnes79e53942008-11-07 14:24:08 -08001988static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1989 .dpms = intel_sdvo_dpms,
1990 .mode_fixup = intel_sdvo_mode_fixup,
1991 .prepare = intel_encoder_prepare,
1992 .mode_set = intel_sdvo_mode_set,
1993 .commit = intel_encoder_commit,
1994};
1995
1996static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -07001997 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -08001998 .detect = intel_sdvo_detect,
1999 .fill_modes = drm_helper_probe_single_connector_modes,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002000 .set_property = intel_sdvo_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -08002001 .destroy = intel_sdvo_destroy,
2002};
2003
2004static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2005 .get_modes = intel_sdvo_get_modes,
2006 .mode_valid = intel_sdvo_mode_valid,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002007 .best_encoder = intel_attached_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002008};
2009
Hannes Ederb358d0a2008-12-18 21:18:47 +01002010static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08002011{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002012 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002013
Chris Wilsonea5b2132010-08-04 13:50:23 +01002014 if (intel_sdvo->analog_ddc_bus)
2015 intel_i2c_destroy(intel_sdvo->analog_ddc_bus);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002016
Chris Wilsonea5b2132010-08-04 13:50:23 +01002017 if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002018 drm_mode_destroy(encoder->dev,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002019 intel_sdvo->sdvo_lvds_fixed_mode);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002020
Chris Wilsonea5b2132010-08-04 13:50:23 +01002021 intel_encoder_destroy(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002022}
2023
2024static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2025 .destroy = intel_sdvo_enc_destroy,
2026};
2027
2028
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002029/**
2030 * Choose the appropriate DDC bus for control bus switch command for this
2031 * SDVO output based on the controlled output.
2032 *
2033 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2034 * outputs, then LVDS outputs.
2035 */
2036static void
Adam Jacksonb1083332010-04-23 16:07:40 -04002037intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002038 struct intel_sdvo *sdvo, u32 reg)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002039{
Adam Jacksonb1083332010-04-23 16:07:40 -04002040 struct sdvo_device_mapping *mapping;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002041
Adam Jacksonb1083332010-04-23 16:07:40 -04002042 if (IS_SDVOB(reg))
2043 mapping = &(dev_priv->sdvo_mappings[0]);
2044 else
2045 mapping = &(dev_priv->sdvo_mappings[1]);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002046
Adam Jacksonb1083332010-04-23 16:07:40 -04002047 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002048}
2049
2050static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002051intel_sdvo_get_digital_encoding_mode(struct intel_sdvo *intel_sdvo, int device)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002052{
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002053 uint8_t status;
2054
Zhenyu Wang14571b42010-03-30 14:06:33 +08002055 if (device == 0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002056 intel_sdvo_set_target_output(intel_sdvo, SDVO_OUTPUT_TMDS0);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002057 else
Chris Wilsonea5b2132010-08-04 13:50:23 +01002058 intel_sdvo_set_target_output(intel_sdvo, SDVO_OUTPUT_TMDS1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002059
Chris Wilsonea5b2132010-08-04 13:50:23 +01002060 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_ENCODE, NULL, 0);
2061 status = intel_sdvo_read_response(intel_sdvo, &intel_sdvo->is_hdmi, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002062 if (status != SDVO_CMD_STATUS_SUCCESS)
2063 return false;
2064 return true;
2065}
2066
Chris Wilsonea5b2132010-08-04 13:50:23 +01002067static struct intel_sdvo *
2068intel_sdvo_chan_to_intel_sdvo(struct intel_i2c_chan *chan)
Ma Ling619ac3b2009-05-18 16:12:46 +08002069{
2070 struct drm_device *dev = chan->drm_dev;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002071 struct drm_encoder *encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002072
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002073 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002074 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
2075 if (intel_sdvo->base.ddc_bus == &chan->adapter)
2076 return intel_sdvo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002077 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002078
2079 return NULL;;
Ma Ling619ac3b2009-05-18 16:12:46 +08002080}
2081
2082static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2083 struct i2c_msg msgs[], int num)
2084{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002085 struct intel_sdvo *intel_sdvo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002086 struct i2c_algo_bit_data *algo_data;
Keith Packardf9c10a92009-05-30 12:16:25 -07002087 const struct i2c_algorithm *algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002088
2089 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002090 intel_sdvo =
2091 intel_sdvo_chan_to_intel_sdvo((struct intel_i2c_chan *)
2092 (algo_data->data));
2093 if (intel_sdvo == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002094 return -EINVAL;
2095
Chris Wilsonea5b2132010-08-04 13:50:23 +01002096 algo = intel_sdvo->base.i2c_bus->algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002097
Chris Wilsonea5b2132010-08-04 13:50:23 +01002098 intel_sdvo_set_control_bus_switch(intel_sdvo, intel_sdvo->ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08002099 return algo->master_xfer(i2c_adap, msgs, num);
2100}
2101
2102static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
2103 .master_xfer = intel_sdvo_master_xfer,
2104};
2105
yakui_zhao714605e2009-05-31 17:18:07 +08002106static u8
Eric Anholtc751ce42010-03-25 11:48:48 -07002107intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
yakui_zhao714605e2009-05-31 17:18:07 +08002108{
2109 struct drm_i915_private *dev_priv = dev->dev_private;
2110 struct sdvo_device_mapping *my_mapping, *other_mapping;
2111
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002112 if (IS_SDVOB(sdvo_reg)) {
yakui_zhao714605e2009-05-31 17:18:07 +08002113 my_mapping = &dev_priv->sdvo_mappings[0];
2114 other_mapping = &dev_priv->sdvo_mappings[1];
2115 } else {
2116 my_mapping = &dev_priv->sdvo_mappings[1];
2117 other_mapping = &dev_priv->sdvo_mappings[0];
2118 }
2119
2120 /* If the BIOS described our SDVO device, take advantage of it. */
2121 if (my_mapping->slave_addr)
2122 return my_mapping->slave_addr;
2123
2124 /* If the BIOS only described a different SDVO device, use the
2125 * address that it isn't using.
2126 */
2127 if (other_mapping->slave_addr) {
2128 if (other_mapping->slave_addr == 0x70)
2129 return 0x72;
2130 else
2131 return 0x70;
2132 }
2133
2134 /* No SDVO device info is found for another DVO port,
2135 * so use mapping assumption we had before BIOS parsing.
2136 */
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002137 if (IS_SDVOB(sdvo_reg))
yakui_zhao714605e2009-05-31 17:18:07 +08002138 return 0x70;
2139 else
2140 return 0x72;
2141}
2142
Zhenyu Wang14571b42010-03-30 14:06:33 +08002143static void
2144intel_sdvo_connector_create (struct drm_encoder *encoder,
2145 struct drm_connector *connector)
2146{
2147 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs,
2148 connector->connector_type);
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002149
Zhenyu Wang14571b42010-03-30 14:06:33 +08002150 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2151
2152 connector->interlace_allowed = 0;
2153 connector->doublescan_allowed = 0;
2154 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2155
2156 drm_mode_connector_attach_encoder(connector, encoder);
2157 drm_sysfs_connector_add(connector);
2158}
2159
2160static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002161intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002162{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002163 struct drm_encoder *encoder = &intel_sdvo->base.enc;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002164 struct drm_connector *connector;
2165 struct intel_connector *intel_connector;
Chris Wilson615fb932010-08-04 13:50:24 +01002166 struct intel_sdvo_connector *intel_sdvo_connector;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002167
Chris Wilson615fb932010-08-04 13:50:24 +01002168 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2169 if (!intel_sdvo_connector)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002170 return false;
2171
Zhenyu Wang14571b42010-03-30 14:06:33 +08002172 if (device == 0) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002173 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
Chris Wilson615fb932010-08-04 13:50:24 +01002174 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002175 } else if (device == 1) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002176 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
Chris Wilson615fb932010-08-04 13:50:24 +01002177 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002178 }
2179
Chris Wilson615fb932010-08-04 13:50:24 +01002180 intel_connector = &intel_sdvo_connector->base;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002181 connector = &intel_connector->base;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002182 connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002183 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2184 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2185
Chris Wilsonea5b2132010-08-04 13:50:23 +01002186 if (intel_sdvo_get_supp_encode(intel_sdvo, &intel_sdvo->encode)
2187 && intel_sdvo_get_digital_encoding_mode(intel_sdvo, device)
2188 && intel_sdvo->is_hdmi) {
Zhenyu Wang14571b42010-03-30 14:06:33 +08002189 /* enable hdmi encoding mode if supported */
Chris Wilsonea5b2132010-08-04 13:50:23 +01002190 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
2191 intel_sdvo_set_colorimetry(intel_sdvo,
Zhenyu Wang14571b42010-03-30 14:06:33 +08002192 SDVO_COLORIMETRY_RGB256);
2193 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2194 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002195 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2196 (1 << INTEL_ANALOG_CLONE_BIT));
Zhenyu Wang14571b42010-03-30 14:06:33 +08002197
2198 intel_sdvo_connector_create(encoder, connector);
2199
2200 return true;
2201}
2202
2203static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002204intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002205{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002206 struct drm_encoder *encoder = &intel_sdvo->base.enc;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002207 struct drm_connector *connector;
2208 struct intel_connector *intel_connector;
Chris Wilson615fb932010-08-04 13:50:24 +01002209 struct intel_sdvo_connector *intel_sdvo_connector;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002210
Chris Wilson615fb932010-08-04 13:50:24 +01002211 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2212 if (!intel_sdvo_connector)
2213 return false;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002214
Chris Wilson615fb932010-08-04 13:50:24 +01002215 intel_connector = &intel_sdvo_connector->base;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002216 connector = &intel_connector->base;
2217 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2218 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002219
Chris Wilsonea5b2132010-08-04 13:50:23 +01002220 intel_sdvo->controlled_output |= type;
Chris Wilson615fb932010-08-04 13:50:24 +01002221 intel_sdvo_connector->output_flag = type;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002222
Chris Wilsonea5b2132010-08-04 13:50:23 +01002223 intel_sdvo->is_tv = true;
2224 intel_sdvo->base.needs_tv_clock = true;
2225 intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002226
2227 intel_sdvo_connector_create(encoder, connector);
2228
2229 intel_sdvo_tv_create_property(connector, type);
2230
2231 intel_sdvo_create_enhance_property(connector);
2232
2233 return true;
2234}
2235
2236static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002237intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002238{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002239 struct drm_encoder *encoder = &intel_sdvo->base.enc;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002240 struct drm_connector *connector;
2241 struct intel_connector *intel_connector;
Chris Wilson615fb932010-08-04 13:50:24 +01002242 struct intel_sdvo_connector *intel_sdvo_connector;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002243
Chris Wilson615fb932010-08-04 13:50:24 +01002244 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2245 if (!intel_sdvo_connector)
2246 return false;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002247
Chris Wilson615fb932010-08-04 13:50:24 +01002248 intel_connector = &intel_sdvo_connector->base;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002249 connector = &intel_connector->base;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002250 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002251 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2252 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002253
2254 if (device == 0) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002255 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
Chris Wilson615fb932010-08-04 13:50:24 +01002256 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002257 } else if (device == 1) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002258 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
Chris Wilson615fb932010-08-04 13:50:24 +01002259 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002260 }
2261
Chris Wilsonea5b2132010-08-04 13:50:23 +01002262 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2263 (1 << INTEL_ANALOG_CLONE_BIT));
Zhenyu Wang14571b42010-03-30 14:06:33 +08002264
2265 intel_sdvo_connector_create(encoder, connector);
2266 return true;
2267}
2268
2269static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002270intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002271{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002272 struct drm_encoder *encoder = &intel_sdvo->base.enc;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002273 struct drm_connector *connector;
2274 struct intel_connector *intel_connector;
Chris Wilson615fb932010-08-04 13:50:24 +01002275 struct intel_sdvo_connector *intel_sdvo_connector;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002276
Chris Wilson615fb932010-08-04 13:50:24 +01002277 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2278 if (!intel_sdvo_connector)
2279 return false;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002280
Chris Wilson615fb932010-08-04 13:50:24 +01002281 intel_connector = &intel_sdvo_connector->base;
2282 connector = &intel_connector->base;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002283 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2284 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002285
Chris Wilsonea5b2132010-08-04 13:50:23 +01002286 intel_sdvo->is_lvds = true;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002287
2288 if (device == 0) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002289 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
Chris Wilson615fb932010-08-04 13:50:24 +01002290 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002291 } else if (device == 1) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002292 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
Chris Wilson615fb932010-08-04 13:50:24 +01002293 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002294 }
2295
Chris Wilsonea5b2132010-08-04 13:50:23 +01002296 intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) |
2297 (1 << INTEL_SDVO_LVDS_CLONE_BIT));
Zhenyu Wang14571b42010-03-30 14:06:33 +08002298
2299 intel_sdvo_connector_create(encoder, connector);
2300 intel_sdvo_create_enhance_property(connector);
2301 return true;
2302}
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002303
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002304static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002305intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002306{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002307 intel_sdvo->is_tv = false;
2308 intel_sdvo->base.needs_tv_clock = false;
2309 intel_sdvo->is_lvds = false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002310
Zhenyu Wang14571b42010-03-30 14:06:33 +08002311 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002312
Zhenyu Wang14571b42010-03-30 14:06:33 +08002313 if (flags & SDVO_OUTPUT_TMDS0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002314 if (!intel_sdvo_dvi_init(intel_sdvo, 0))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002315 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002316
Zhenyu Wang14571b42010-03-30 14:06:33 +08002317 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002318 if (!intel_sdvo_dvi_init(intel_sdvo, 1))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002319 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002320
Zhenyu Wang14571b42010-03-30 14:06:33 +08002321 /* TV has no XXX1 function block */
Zhenyu Wanga1f4b7ff2010-03-29 23:16:13 +08002322 if (flags & SDVO_OUTPUT_SVID0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002323 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002324 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002325
Zhenyu Wang14571b42010-03-30 14:06:33 +08002326 if (flags & SDVO_OUTPUT_CVBS0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002327 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002328 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002329
Zhenyu Wang14571b42010-03-30 14:06:33 +08002330 if (flags & SDVO_OUTPUT_RGB0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002331 if (!intel_sdvo_analog_init(intel_sdvo, 0))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002332 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002333
Zhenyu Wang14571b42010-03-30 14:06:33 +08002334 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002335 if (!intel_sdvo_analog_init(intel_sdvo, 1))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002336 return false;
Zhao Yakui2dd87382010-01-27 16:32:46 +08002337
Zhenyu Wang14571b42010-03-30 14:06:33 +08002338 if (flags & SDVO_OUTPUT_LVDS0)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002339 if (!intel_sdvo_lvds_init(intel_sdvo, 0))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002340 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002341
Zhenyu Wang14571b42010-03-30 14:06:33 +08002342 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002343 if (!intel_sdvo_lvds_init(intel_sdvo, 1))
Zhenyu Wang14571b42010-03-30 14:06:33 +08002344 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002345
Zhenyu Wang14571b42010-03-30 14:06:33 +08002346 if ((flags & SDVO_OUTPUT_MASK) == 0) {
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002347 unsigned char bytes[2];
2348
Chris Wilsonea5b2132010-08-04 13:50:23 +01002349 intel_sdvo->controlled_output = 0;
2350 memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
Dave Airlie51c8b402009-08-20 13:38:04 +10002351 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +01002352 SDVO_NAME(intel_sdvo),
Dave Airlie51c8b402009-08-20 13:38:04 +10002353 bytes[0], bytes[1]);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002354 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002355 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002356 intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002357
Zhenyu Wang14571b42010-03-30 14:06:33 +08002358 return true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002359}
2360
Zhenyu Wang14571b42010-03-30 14:06:33 +08002361static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002362{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002363 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002364 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Chris Wilson615fb932010-08-04 13:50:24 +01002365 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002366 struct intel_sdvo_tv_format format;
2367 uint32_t format_map, i;
2368 uint8_t status;
2369
Chris Wilsonea5b2132010-08-04 13:50:23 +01002370 intel_sdvo_set_target_output(intel_sdvo, type);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002371
Chris Wilsonea5b2132010-08-04 13:50:23 +01002372 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002373 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002374 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002375 &format, sizeof(format));
2376 if (status != SDVO_CMD_STATUS_SUCCESS)
2377 return;
2378
2379 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
2380 sizeof(format_map) : sizeof(format));
2381
2382 if (format_map == 0)
2383 return;
2384
Chris Wilson615fb932010-08-04 13:50:24 +01002385 intel_sdvo_connector->format_supported_num = 0;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002386 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2387 if (format_map & (1 << i)) {
Chris Wilson615fb932010-08-04 13:50:24 +01002388 intel_sdvo_connector->tv_format_supported
2389 [intel_sdvo_connector->format_supported_num++] =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002390 tv_format_names[i];
2391 }
2392
2393
Chris Wilson615fb932010-08-04 13:50:24 +01002394 intel_sdvo_connector->tv_format_property =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002395 drm_property_create(
2396 connector->dev, DRM_MODE_PROP_ENUM,
Chris Wilson615fb932010-08-04 13:50:24 +01002397 "mode", intel_sdvo_connector->format_supported_num);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002398
Chris Wilson615fb932010-08-04 13:50:24 +01002399 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002400 drm_property_add_enum(
Chris Wilson615fb932010-08-04 13:50:24 +01002401 intel_sdvo_connector->tv_format_property, i,
2402 i, intel_sdvo_connector->tv_format_supported[i]);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002403
Chris Wilson615fb932010-08-04 13:50:24 +01002404 intel_sdvo->tv_format_name = intel_sdvo_connector->tv_format_supported[0];
Zhao Yakuice6feab2009-08-24 13:50:26 +08002405 drm_connector_attach_property(
Chris Wilson615fb932010-08-04 13:50:24 +01002406 connector, intel_sdvo_connector->tv_format_property, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002407
2408}
2409
Zhao Yakuib9219c52009-09-10 15:45:46 +08002410static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2411{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002412 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002413 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
Chris Wilson615fb932010-08-04 13:50:24 +01002414 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002415 struct intel_sdvo_enhancements_reply sdvo_data;
2416 struct drm_device *dev = connector->dev;
2417 uint8_t status;
2418 uint16_t response, data_value[2];
2419
Chris Wilsonea5b2132010-08-04 13:50:23 +01002420 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002421 NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002422 status = intel_sdvo_read_response(intel_sdvo, &sdvo_data,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002423 sizeof(sdvo_data));
2424 if (status != SDVO_CMD_STATUS_SUCCESS) {
2425 DRM_DEBUG_KMS(" incorrect response is returned\n");
2426 return;
2427 }
2428 response = *((uint16_t *)&sdvo_data);
2429 if (!response) {
2430 DRM_DEBUG_KMS("No enhancement is supported\n");
2431 return;
2432 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002433 if (IS_TV(intel_sdvo_connector)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002434 /* when horizontal overscan is supported, Add the left/right
2435 * property
2436 */
2437 if (sdvo_data.overscan_h) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002438 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002439 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002440 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002441 &data_value, 4);
2442 if (status != SDVO_CMD_STATUS_SUCCESS) {
2443 DRM_DEBUG_KMS("Incorrect SDVO max "
2444 "h_overscan\n");
2445 return;
2446 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002447 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002448 SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002449 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002450 &response, 2);
2451 if (status != SDVO_CMD_STATUS_SUCCESS) {
2452 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2453 return;
2454 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002455 intel_sdvo_connector->max_hscan = data_value[0];
2456 intel_sdvo_connector->left_margin = data_value[0] - response;
2457 intel_sdvo_connector->right_margin = intel_sdvo_connector->left_margin;
2458 intel_sdvo_connector->left_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002459 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2460 "left_margin", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002461 intel_sdvo_connector->left_property->values[0] = 0;
2462 intel_sdvo_connector->left_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002463 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002464 intel_sdvo_connector->left_property,
2465 intel_sdvo_connector->left_margin);
2466 intel_sdvo_connector->right_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002467 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2468 "right_margin", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002469 intel_sdvo_connector->right_property->values[0] = 0;
2470 intel_sdvo_connector->right_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002471 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002472 intel_sdvo_connector->right_property,
2473 intel_sdvo_connector->right_margin);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002474 DRM_DEBUG_KMS("h_overscan: max %d, "
2475 "default %d, current %d\n",
2476 data_value[0], data_value[1], response);
2477 }
2478 if (sdvo_data.overscan_v) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002479 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002480 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002481 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002482 &data_value, 4);
2483 if (status != SDVO_CMD_STATUS_SUCCESS) {
2484 DRM_DEBUG_KMS("Incorrect SDVO max "
2485 "v_overscan\n");
2486 return;
2487 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002488 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002489 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002490 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002491 &response, 2);
2492 if (status != SDVO_CMD_STATUS_SUCCESS) {
2493 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2494 return;
2495 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002496 intel_sdvo_connector->max_vscan = data_value[0];
2497 intel_sdvo_connector->top_margin = data_value[0] - response;
2498 intel_sdvo_connector->bottom_margin = intel_sdvo_connector->top_margin;
2499 intel_sdvo_connector->top_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002500 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2501 "top_margin", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002502 intel_sdvo_connector->top_property->values[0] = 0;
2503 intel_sdvo_connector->top_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002504 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002505 intel_sdvo_connector->top_property,
2506 intel_sdvo_connector->top_margin);
2507 intel_sdvo_connector->bottom_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002508 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2509 "bottom_margin", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002510 intel_sdvo_connector->bottom_property->values[0] = 0;
2511 intel_sdvo_connector->bottom_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002512 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002513 intel_sdvo_connector->bottom_property,
2514 intel_sdvo_connector->bottom_margin);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002515 DRM_DEBUG_KMS("v_overscan: max %d, "
2516 "default %d, current %d\n",
2517 data_value[0], data_value[1], response);
2518 }
2519 if (sdvo_data.position_h) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002520 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002521 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002522 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002523 &data_value, 4);
2524 if (status != SDVO_CMD_STATUS_SUCCESS) {
2525 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2526 return;
2527 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002528 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002529 SDVO_CMD_GET_POSITION_H, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002530 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002531 &response, 2);
2532 if (status != SDVO_CMD_STATUS_SUCCESS) {
2533 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2534 return;
2535 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002536 intel_sdvo_connector->max_hpos = data_value[0];
2537 intel_sdvo_connector->cur_hpos = response;
2538 intel_sdvo_connector->hpos_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002539 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2540 "hpos", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002541 intel_sdvo_connector->hpos_property->values[0] = 0;
2542 intel_sdvo_connector->hpos_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002543 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002544 intel_sdvo_connector->hpos_property,
2545 intel_sdvo_connector->cur_hpos);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002546 DRM_DEBUG_KMS("h_position: max %d, "
2547 "default %d, current %d\n",
2548 data_value[0], data_value[1], response);
2549 }
2550 if (sdvo_data.position_v) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002551 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002552 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002553 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002554 &data_value, 4);
2555 if (status != SDVO_CMD_STATUS_SUCCESS) {
2556 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2557 return;
2558 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002559 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002560 SDVO_CMD_GET_POSITION_V, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002561 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002562 &response, 2);
2563 if (status != SDVO_CMD_STATUS_SUCCESS) {
2564 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2565 return;
2566 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002567 intel_sdvo_connector->max_vpos = data_value[0];
2568 intel_sdvo_connector->cur_vpos = response;
2569 intel_sdvo_connector->vpos_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002570 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2571 "vpos", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002572 intel_sdvo_connector->vpos_property->values[0] = 0;
2573 intel_sdvo_connector->vpos_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002574 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002575 intel_sdvo_connector->vpos_property,
2576 intel_sdvo_connector->cur_vpos);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002577 DRM_DEBUG_KMS("v_position: max %d, "
2578 "default %d, current %d\n",
2579 data_value[0], data_value[1], response);
2580 }
Zhao Yakuib9219c52009-09-10 15:45:46 +08002581 if (sdvo_data.saturation) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002582 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002583 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002584 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002585 &data_value, 4);
2586 if (status != SDVO_CMD_STATUS_SUCCESS) {
2587 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2588 return;
2589 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002590 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002591 SDVO_CMD_GET_SATURATION, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002592 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002593 &response, 2);
2594 if (status != SDVO_CMD_STATUS_SUCCESS) {
2595 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2596 return;
2597 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002598 intel_sdvo_connector->max_saturation = data_value[0];
2599 intel_sdvo_connector->cur_saturation = response;
2600 intel_sdvo_connector->saturation_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002601 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2602 "saturation", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002603 intel_sdvo_connector->saturation_property->values[0] = 0;
2604 intel_sdvo_connector->saturation_property->values[1] =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002605 data_value[0];
2606 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002607 intel_sdvo_connector->saturation_property,
2608 intel_sdvo_connector->cur_saturation);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002609 DRM_DEBUG_KMS("saturation: max %d, "
2610 "default %d, current %d\n",
2611 data_value[0], data_value[1], response);
2612 }
2613 if (sdvo_data.contrast) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002614 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002615 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002616 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002617 &data_value, 4);
2618 if (status != SDVO_CMD_STATUS_SUCCESS) {
2619 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2620 return;
2621 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002622 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002623 SDVO_CMD_GET_CONTRAST, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002624 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002625 &response, 2);
2626 if (status != SDVO_CMD_STATUS_SUCCESS) {
2627 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2628 return;
2629 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002630 intel_sdvo_connector->max_contrast = data_value[0];
2631 intel_sdvo_connector->cur_contrast = response;
2632 intel_sdvo_connector->contrast_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002633 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2634 "contrast", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002635 intel_sdvo_connector->contrast_property->values[0] = 0;
2636 intel_sdvo_connector->contrast_property->values[1] = data_value[0];
Zhao Yakuib9219c52009-09-10 15:45:46 +08002637 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002638 intel_sdvo_connector->contrast_property,
2639 intel_sdvo_connector->cur_contrast);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002640 DRM_DEBUG_KMS("contrast: max %d, "
2641 "default %d, current %d\n",
2642 data_value[0], data_value[1], response);
2643 }
2644 if (sdvo_data.hue) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002645 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002646 SDVO_CMD_GET_MAX_HUE, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002647 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002648 &data_value, 4);
2649 if (status != SDVO_CMD_STATUS_SUCCESS) {
2650 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2651 return;
2652 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002653 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002654 SDVO_CMD_GET_HUE, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002655 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002656 &response, 2);
2657 if (status != SDVO_CMD_STATUS_SUCCESS) {
2658 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2659 return;
2660 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002661 intel_sdvo_connector->max_hue = data_value[0];
2662 intel_sdvo_connector->cur_hue = response;
2663 intel_sdvo_connector->hue_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002664 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2665 "hue", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002666 intel_sdvo_connector->hue_property->values[0] = 0;
2667 intel_sdvo_connector->hue_property->values[1] =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002668 data_value[0];
2669 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002670 intel_sdvo_connector->hue_property,
2671 intel_sdvo_connector->cur_hue);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002672 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2673 data_value[0], data_value[1], response);
2674 }
2675 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002676 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002677 if (sdvo_data.brightness) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002678 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002679 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002680 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002681 &data_value, 4);
2682 if (status != SDVO_CMD_STATUS_SUCCESS) {
2683 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2684 return;
2685 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002686 intel_sdvo_write_cmd(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002687 SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002688 status = intel_sdvo_read_response(intel_sdvo,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002689 &response, 2);
2690 if (status != SDVO_CMD_STATUS_SUCCESS) {
2691 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2692 return;
2693 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002694 intel_sdvo_connector->max_brightness = data_value[0];
2695 intel_sdvo_connector->cur_brightness = response;
2696 intel_sdvo_connector->brightness_property =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002697 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2698 "brightness", 2);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002699 intel_sdvo_connector->brightness_property->values[0] = 0;
2700 intel_sdvo_connector->brightness_property->values[1] =
Zhao Yakuib9219c52009-09-10 15:45:46 +08002701 data_value[0];
2702 drm_connector_attach_property(connector,
Chris Wilsonea5b2132010-08-04 13:50:23 +01002703 intel_sdvo_connector->brightness_property,
2704 intel_sdvo_connector->cur_brightness);
Zhao Yakuib9219c52009-09-10 15:45:46 +08002705 DRM_DEBUG_KMS("brightness: max %d, "
2706 "default %d, current %d\n",
2707 data_value[0], data_value[1], response);
2708 }
2709 }
2710 return;
2711}
2712
Eric Anholtc751ce42010-03-25 11:48:48 -07002713bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
Jesse Barnes79e53942008-11-07 14:24:08 -08002714{
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002715 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07002716 struct intel_encoder *intel_encoder;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002717 struct intel_sdvo *intel_sdvo;
Jesse Barnes79e53942008-11-07 14:24:08 -08002718 u8 ch[0x40];
2719 int i;
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002720 u32 i2c_reg, ddc_reg, analog_ddc_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -08002721
Chris Wilsonea5b2132010-08-04 13:50:23 +01002722 intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
2723 if (!intel_sdvo)
Eric Anholt7d573822009-01-02 13:33:00 -08002724 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002725
Chris Wilsonea5b2132010-08-04 13:50:23 +01002726 intel_sdvo->sdvo_reg = sdvo_reg;
Keith Packard308cd3a2009-06-14 11:56:18 -07002727
Chris Wilsonea5b2132010-08-04 13:50:23 +01002728 intel_encoder = &intel_sdvo->base;
Eric Anholt21d40d32010-03-25 11:11:14 -07002729 intel_encoder->type = INTEL_OUTPUT_SDVO;
Jesse Barnes79e53942008-11-07 14:24:08 -08002730
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002731 if (HAS_PCH_SPLIT(dev)) {
2732 i2c_reg = PCH_GPIOE;
2733 ddc_reg = PCH_GPIOE;
2734 analog_ddc_reg = PCH_GPIOA;
2735 } else {
2736 i2c_reg = GPIOE;
2737 ddc_reg = GPIOE;
2738 analog_ddc_reg = GPIOA;
2739 }
2740
Jesse Barnes79e53942008-11-07 14:24:08 -08002741 /* setup the DDC bus. */
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002742 if (IS_SDVOB(sdvo_reg))
2743 intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOB");
Keith Packard308cd3a2009-06-14 11:56:18 -07002744 else
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002745 intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOC");
Keith Packard308cd3a2009-06-14 11:56:18 -07002746
Eric Anholt21d40d32010-03-25 11:11:14 -07002747 if (!intel_encoder->i2c_bus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002748 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08002749
Chris Wilsonea5b2132010-08-04 13:50:23 +01002750 intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08002751
Keith Packard308cd3a2009-06-14 11:56:18 -07002752 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
Eric Anholt21d40d32010-03-25 11:11:14 -07002753 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
Jesse Barnes79e53942008-11-07 14:24:08 -08002754
Jesse Barnes79e53942008-11-07 14:24:08 -08002755 /* Read the regs to test if we can talk to the device */
2756 for (i = 0; i < 0x40; i++) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002757 if (!intel_sdvo_read_byte(intel_sdvo, i, &ch[i])) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002758 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002759 IS_SDVOB(sdvo_reg) ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002760 goto err_i2c;
2761 }
2762 }
2763
Ma Ling619ac3b2009-05-18 16:12:46 +08002764 /* setup the DDC bus. */
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002765 if (IS_SDVOB(sdvo_reg)) {
2766 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS");
Chris Wilsonea5b2132010-08-04 13:50:23 +01002767 intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg,
Keith Packard57cdaf92009-09-04 13:07:54 +08002768 "SDVOB/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002769 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002770 } else {
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002771 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS");
Chris Wilsonea5b2132010-08-04 13:50:23 +01002772 intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg,
Keith Packard57cdaf92009-09-04 13:07:54 +08002773 "SDVOC/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002774 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002775 }
Ma Ling619ac3b2009-05-18 16:12:46 +08002776
Eric Anholt21d40d32010-03-25 11:11:14 -07002777 if (intel_encoder->ddc_bus == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002778 goto err_i2c;
2779
Keith Packard308cd3a2009-06-14 11:56:18 -07002780 /* Wrap with our custom algo which switches to DDC mode */
Eric Anholt21d40d32010-03-25 11:11:14 -07002781 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002782
Zhenyu Wang14571b42010-03-30 14:06:33 +08002783 /* encoder type will be decided later */
2784 drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0);
2785 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2786
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002787 /* In default case sdvo lvds is false */
Chris Wilsonea5b2132010-08-04 13:50:23 +01002788 intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps);
Jesse Barnes79e53942008-11-07 14:24:08 -08002789
Chris Wilsonea5b2132010-08-04 13:50:23 +01002790 if (intel_sdvo_output_setup(intel_sdvo,
2791 intel_sdvo->caps.output_flags) != true) {
Dave Airlie51c8b402009-08-20 13:38:04 +10002792 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002793 IS_SDVOB(sdvo_reg) ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002794 goto err_i2c;
2795 }
2796
Chris Wilsonea5b2132010-08-04 13:50:23 +01002797 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002798
Jesse Barnes79e53942008-11-07 14:24:08 -08002799 /* Set the input timing to the screen. Assume always input 0. */
Chris Wilsonea5b2132010-08-04 13:50:23 +01002800 intel_sdvo_set_target_input(intel_sdvo, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08002801
Chris Wilsonea5b2132010-08-04 13:50:23 +01002802 intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
2803 &intel_sdvo->pixel_clock_min,
2804 &intel_sdvo->pixel_clock_max);
Jesse Barnes79e53942008-11-07 14:24:08 -08002805
2806
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002807 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
yakui_zhao342dc382009-06-02 14:12:00 +08002808 "clock range %dMHz - %dMHz, "
2809 "input 1: %c, input 2: %c, "
2810 "output 1: %c, output 2: %c\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +01002811 SDVO_NAME(intel_sdvo),
2812 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
2813 intel_sdvo->caps.device_rev_id,
2814 intel_sdvo->pixel_clock_min / 1000,
2815 intel_sdvo->pixel_clock_max / 1000,
2816 (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2817 (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
yakui_zhao342dc382009-06-02 14:12:00 +08002818 /* check currently supported outputs */
Chris Wilsonea5b2132010-08-04 13:50:23 +01002819 intel_sdvo->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002820 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
Chris Wilsonea5b2132010-08-04 13:50:23 +01002821 intel_sdvo->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002822 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2823
Eric Anholt7d573822009-01-02 13:33:00 -08002824 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08002825
2826err_i2c:
Chris Wilsonea5b2132010-08-04 13:50:23 +01002827 if (intel_sdvo->analog_ddc_bus != NULL)
2828 intel_i2c_destroy(intel_sdvo->analog_ddc_bus);
Eric Anholt21d40d32010-03-25 11:11:14 -07002829 if (intel_encoder->ddc_bus != NULL)
2830 intel_i2c_destroy(intel_encoder->ddc_bus);
2831 if (intel_encoder->i2c_bus != NULL)
2832 intel_i2c_destroy(intel_encoder->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002833err_inteloutput:
Chris Wilsonea5b2132010-08-04 13:50:23 +01002834 kfree(intel_sdvo);
Jesse Barnes79e53942008-11-07 14:24:08 -08002835
Eric Anholt7d573822009-01-02 13:33:00 -08002836 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002837}