blob: 5534704c151aa7c168f3f26cae5b4e96e653298d [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Eric Anholt <eric@anholt.net>
27 */
28#include <linux/i2c.h>
29#include <linux/delay.h>
30#include "drmP.h"
31#include "drm.h"
32#include "drm_crtc.h"
33#include "intel_drv.h"
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +080034#include "drm_edid.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "i915_drm.h"
36#include "i915_drv.h"
37#include "intel_sdvo_regs.h"
Zhao Yakui6070a4a2010-02-08 21:35:12 +080038#include <linux/dmi.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080039
Zhao Yakuice6feab2009-08-24 13:50:26 +080040static char *tv_format_names[] = {
41 "NTSC_M" , "NTSC_J" , "NTSC_443",
42 "PAL_B" , "PAL_D" , "PAL_G" ,
43 "PAL_H" , "PAL_I" , "PAL_M" ,
44 "PAL_N" , "PAL_NC" , "PAL_60" ,
45 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
46 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
47 "SECAM_60"
48};
49
50#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
51
Jesse Barnes79e53942008-11-07 14:24:08 -080052struct intel_sdvo_priv {
Keith Packardf9c10a92009-05-30 12:16:25 -070053 u8 slave_addr;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080054
55 /* Register for the SDVO device: SDVOB or SDVOC */
Eric Anholtc751ce42010-03-25 11:48:48 -070056 int sdvo_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080057
Jesse Barnese2f0ba92009-02-02 15:11:52 -080058 /* Active outputs controlled by this SDVO output */
59 uint16_t controlled_output;
Jesse Barnes79e53942008-11-07 14:24:08 -080060
Jesse Barnese2f0ba92009-02-02 15:11:52 -080061 /*
62 * Capabilities of the SDVO device returned by
63 * i830_sdvo_get_capabilities()
64 */
Jesse Barnes79e53942008-11-07 14:24:08 -080065 struct intel_sdvo_caps caps;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080066
67 /* Pixel clock limitations reported by the SDVO device, in kHz */
Jesse Barnes79e53942008-11-07 14:24:08 -080068 int pixel_clock_min, pixel_clock_max;
69
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +080070 /*
71 * For multiple function SDVO device,
72 * this is for current attached outputs.
73 */
74 uint16_t attached_output;
75
Jesse Barnese2f0ba92009-02-02 15:11:52 -080076 /**
77 * This is set if we're going to treat the device as TV-out.
78 *
79 * While we have these nice friendly flags for output types that ought
80 * to decide this for us, the S-Video output on our HDMI+S-Video card
81 * shows up as RGB1 (VGA).
82 */
83 bool is_tv;
84
Zhao Yakuice6feab2009-08-24 13:50:26 +080085 /* This is for current tv format name */
86 char *tv_format_name;
87
88 /* This contains all current supported TV format */
89 char *tv_format_supported[TV_FORMAT_NUM];
90 int format_supported_num;
91 struct drm_property *tv_format_property;
92 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
93
Jesse Barnese2f0ba92009-02-02 15:11:52 -080094 /**
95 * This is set if we treat the device as HDMI, instead of DVI.
96 */
97 bool is_hdmi;
ling.ma@intel.com12682a92009-06-30 11:35:35 +080098
Ma Ling7086c872009-05-13 11:20:06 +080099 /**
100 * This is set if we detect output of sdvo device as LVDS.
101 */
102 bool is_lvds;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800103
104 /**
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800105 * This is sdvo flags for input timing.
106 */
107 uint8_t sdvo_flags;
108
109 /**
110 * This is sdvo fixed pannel mode pointer
111 */
112 struct drm_display_mode *sdvo_lvds_fixed_mode;
113
114 /**
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800115 * Returned SDTV resolutions allowed for the current format, if the
116 * device reported it.
117 */
118 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
119
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800120 /*
121 * supported encoding mode, used to determine whether HDMI is
122 * supported
123 */
124 struct intel_sdvo_encode encode;
125
Eric Anholtc751ce42010-03-25 11:48:48 -0700126 /* DDC bus used by this SDVO encoder */
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800127 uint8_t ddc_bus;
128
Keith Packard57cdaf92009-09-04 13:07:54 +0800129 /* Mac mini hack -- use the same DDC as the analog connector */
130 struct i2c_adapter *analog_ddc_bus;
131
Zhao Yakuib9219c52009-09-10 15:45:46 +0800132 /* add the property for the SDVO-TV */
133 struct drm_property *left_property;
134 struct drm_property *right_property;
135 struct drm_property *top_property;
136 struct drm_property *bottom_property;
137 struct drm_property *hpos_property;
138 struct drm_property *vpos_property;
139
140 /* add the property for the SDVO-TV/LVDS */
141 struct drm_property *brightness_property;
142 struct drm_property *contrast_property;
143 struct drm_property *saturation_property;
144 struct drm_property *hue_property;
145
146 /* Add variable to record current setting for the above property */
147 u32 left_margin, right_margin, top_margin, bottom_margin;
148 /* this is to get the range of margin.*/
149 u32 max_hscan, max_vscan;
150 u32 max_hpos, cur_hpos;
151 u32 max_vpos, cur_vpos;
152 u32 cur_brightness, max_brightness;
153 u32 cur_contrast, max_contrast;
154 u32 cur_saturation, max_saturation;
155 u32 cur_hue, max_hue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800156};
157
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800158static bool
Eric Anholt21d40d32010-03-25 11:11:14 -0700159intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800160
Jesse Barnes79e53942008-11-07 14:24:08 -0800161/**
162 * Writes the SDVOB or SDVOC with the given value, but always writes both
163 * SDVOB and SDVOC to work around apparent hardware issues (according to
164 * comments in the BIOS).
165 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700166static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800167{
Eric Anholt21d40d32010-03-25 11:11:14 -0700168 struct drm_device *dev = intel_encoder->base.dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800169 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -0700170 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800171 u32 bval = val, cval = val;
172 int i;
173
Eric Anholtc751ce42010-03-25 11:48:48 -0700174 if (sdvo_priv->sdvo_reg == SDVOB) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800175 cval = I915_READ(SDVOC);
176 } else {
177 bval = I915_READ(SDVOB);
178 }
179 /*
180 * Write the registers twice for luck. Sometimes,
181 * writing them only once doesn't appear to 'stick'.
182 * The BIOS does this too. Yay, magic
183 */
184 for (i = 0; i < 2; i++)
185 {
186 I915_WRITE(SDVOB, bval);
187 I915_READ(SDVOB);
188 I915_WRITE(SDVOC, cval);
189 I915_READ(SDVOC);
190 }
191}
192
Eric Anholt21d40d32010-03-25 11:11:14 -0700193static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800194 u8 *ch)
195{
Eric Anholt21d40d32010-03-25 11:11:14 -0700196 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800197 u8 out_buf[2];
198 u8 buf[2];
199 int ret;
200
201 struct i2c_msg msgs[] = {
202 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700203 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800204 .flags = 0,
205 .len = 1,
206 .buf = out_buf,
207 },
208 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700209 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800210 .flags = I2C_M_RD,
211 .len = 1,
212 .buf = buf,
213 }
214 };
215
216 out_buf[0] = addr;
217 out_buf[1] = 0;
218
Eric Anholt21d40d32010-03-25 11:11:14 -0700219 if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800220 {
221 *ch = buf[0];
222 return true;
223 }
224
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800225 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
Jesse Barnes79e53942008-11-07 14:24:08 -0800226 return false;
227}
228
Eric Anholt21d40d32010-03-25 11:11:14 -0700229static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800230 u8 ch)
231{
Eric Anholt21d40d32010-03-25 11:11:14 -0700232 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800233 u8 out_buf[2];
234 struct i2c_msg msgs[] = {
235 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700236 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800237 .flags = 0,
238 .len = 2,
239 .buf = out_buf,
240 }
241 };
242
243 out_buf[0] = addr;
244 out_buf[1] = ch;
245
Eric Anholt21d40d32010-03-25 11:11:14 -0700246 if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800247 {
248 return true;
249 }
250 return false;
251}
252
253#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
254/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100255static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800256 u8 cmd;
257 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800258} sdvo_cmd_names[] = {
259 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
260 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
261 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
262 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
263 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
264 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
265 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
266 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
267 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
268 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
269 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
270 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
271 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
272 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
273 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
274 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
275 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
276 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
277 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
278 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
279 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
280 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
281 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
Zhao Yakuib9219c52009-09-10 15:45:46 +0800302 /* Add the op code for SDVO enhancements */
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800327 /* HDMI op code */
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800348};
349
Eric Anholtc751ce42010-03-25 11:48:48 -0700350#define SDVO_NAME(dev_priv) ((dev_priv)->sdvo_reg == SDVOB ? "SDVOB" : "SDVOC")
351#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -0800352
Eric Anholt21d40d32010-03-25 11:11:14 -0700353static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800354 void *args, int args_len)
355{
Eric Anholt21d40d32010-03-25 11:11:14 -0700356 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800357 int i;
358
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800359 DRM_DEBUG_KMS("%s: W: %02X ",
yakui_zhao342dc382009-06-02 14:12:00 +0800360 SDVO_NAME(sdvo_priv), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800361 for (i = 0; i < args_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800362 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800363 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800364 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800365 for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
366 if (cmd == sdvo_cmd_names[i].cmd) {
yakui_zhao342dc382009-06-02 14:12:00 +0800367 DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800368 break;
369 }
370 }
371 if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
yakui_zhao342dc382009-06-02 14:12:00 +0800372 DRM_LOG_KMS("(%02X)", cmd);
373 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800374}
Jesse Barnes79e53942008-11-07 14:24:08 -0800375
Eric Anholt21d40d32010-03-25 11:11:14 -0700376static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800377 void *args, int args_len)
378{
379 int i;
380
Eric Anholt21d40d32010-03-25 11:11:14 -0700381 intel_sdvo_debug_write(intel_encoder, cmd, args, args_len);
Jesse Barnes79e53942008-11-07 14:24:08 -0800382
383 for (i = 0; i < args_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700384 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i,
Jesse Barnes79e53942008-11-07 14:24:08 -0800385 ((u8*)args)[i]);
386 }
387
Eric Anholt21d40d32010-03-25 11:11:14 -0700388 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800389}
390
Jesse Barnes79e53942008-11-07 14:24:08 -0800391static const char *cmd_status_names[] = {
392 "Power on",
393 "Success",
394 "Not supported",
395 "Invalid arg",
396 "Pending",
397 "Target not specified",
398 "Scaling not supported"
399};
400
Eric Anholt21d40d32010-03-25 11:11:14 -0700401static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800402 void *response, int response_len,
403 u8 status)
404{
Eric Anholt21d40d32010-03-25 11:11:14 -0700405 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang33b52962009-03-24 14:02:40 +0800406 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800407
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800408 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -0800409 for (i = 0; i < response_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800410 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800411 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800412 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800413 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
yakui_zhao342dc382009-06-02 14:12:00 +0800414 DRM_LOG_KMS("(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800415 else
yakui_zhao342dc382009-06-02 14:12:00 +0800416 DRM_LOG_KMS("(??? %d)", status);
417 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800418}
Jesse Barnes79e53942008-11-07 14:24:08 -0800419
Eric Anholt21d40d32010-03-25 11:11:14 -0700420static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800421 void *response, int response_len)
422{
423 int i;
424 u8 status;
425 u8 retry = 50;
426
427 while (retry--) {
428 /* Read the command response */
429 for (i = 0; i < response_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700430 intel_sdvo_read_byte(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800431 SDVO_I2C_RETURN_0 + i,
432 &((u8 *)response)[i]);
433 }
434
435 /* read the return status */
Eric Anholt21d40d32010-03-25 11:11:14 -0700436 intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS,
Jesse Barnes79e53942008-11-07 14:24:08 -0800437 &status);
438
Eric Anholt21d40d32010-03-25 11:11:14 -0700439 intel_sdvo_debug_response(intel_encoder, response, response_len,
Jesse Barnes79e53942008-11-07 14:24:08 -0800440 status);
441 if (status != SDVO_CMD_STATUS_PENDING)
442 return status;
443
444 mdelay(50);
445 }
446
447 return status;
448}
449
Hannes Ederb358d0a2008-12-18 21:18:47 +0100450static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800451{
452 if (mode->clock >= 100000)
453 return 1;
454 else if (mode->clock >= 50000)
455 return 2;
456 else
457 return 4;
458}
459
460/**
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800461 * Try to read the response after issuie the DDC switch command. But it
462 * is noted that we must do the action of reading response and issuing DDC
463 * switch command in one I2C transaction. Otherwise when we try to start
464 * another I2C transaction after issuing the DDC bus switch, it will be
465 * switched to the internal SDVO register.
Jesse Barnes79e53942008-11-07 14:24:08 -0800466 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700467static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder,
Hannes Ederb358d0a2008-12-18 21:18:47 +0100468 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800469{
Eric Anholt21d40d32010-03-25 11:11:14 -0700470 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800471 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
472 struct i2c_msg msgs[] = {
473 {
474 .addr = sdvo_priv->slave_addr >> 1,
475 .flags = 0,
476 .len = 2,
477 .buf = out_buf,
478 },
479 /* the following two are to read the response */
480 {
481 .addr = sdvo_priv->slave_addr >> 1,
482 .flags = 0,
483 .len = 1,
484 .buf = cmd_buf,
485 },
486 {
487 .addr = sdvo_priv->slave_addr >> 1,
488 .flags = I2C_M_RD,
489 .len = 1,
490 .buf = ret_value,
491 },
492 };
493
Eric Anholt21d40d32010-03-25 11:11:14 -0700494 intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800495 &target, 1);
496 /* write the DDC switch command argument */
Eric Anholt21d40d32010-03-25 11:11:14 -0700497 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800498
499 out_buf[0] = SDVO_I2C_OPCODE;
500 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
501 cmd_buf[0] = SDVO_I2C_CMD_STATUS;
502 cmd_buf[1] = 0;
503 ret_value[0] = 0;
504 ret_value[1] = 0;
505
Eric Anholt21d40d32010-03-25 11:11:14 -0700506 ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800507 if (ret != 3) {
508 /* failure in I2C transfer */
509 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
510 return;
511 }
512 if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
513 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
514 ret_value[0]);
515 return;
516 }
517 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800518}
519
Eric Anholt21d40d32010-03-25 11:11:14 -0700520static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800521{
522 struct intel_sdvo_set_target_input_args targets = {0};
523 u8 status;
524
525 if (target_0 && target_1)
526 return SDVO_CMD_STATUS_NOTSUPP;
527
528 if (target_1)
529 targets.target_1 = 1;
530
Eric Anholt21d40d32010-03-25 11:11:14 -0700531 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets,
Jesse Barnes79e53942008-11-07 14:24:08 -0800532 sizeof(targets));
533
Eric Anholt21d40d32010-03-25 11:11:14 -0700534 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800535
536 return (status == SDVO_CMD_STATUS_SUCCESS);
537}
538
539/**
540 * Return whether each input is trained.
541 *
542 * This function is making an assumption about the layout of the response,
543 * which should be checked against the docs.
544 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700545static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800546{
547 struct intel_sdvo_get_trained_inputs_response response;
548 u8 status;
549
Eric Anholt21d40d32010-03-25 11:11:14 -0700550 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
551 status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response));
Jesse Barnes79e53942008-11-07 14:24:08 -0800552 if (status != SDVO_CMD_STATUS_SUCCESS)
553 return false;
554
555 *input_1 = response.input0_trained;
556 *input_2 = response.input1_trained;
557 return true;
558}
559
Eric Anholt21d40d32010-03-25 11:11:14 -0700560static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800561 u16 outputs)
562{
563 u8 status;
564
Eric Anholt21d40d32010-03-25 11:11:14 -0700565 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800566 sizeof(outputs));
Eric Anholt21d40d32010-03-25 11:11:14 -0700567 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800568 return (status == SDVO_CMD_STATUS_SUCCESS);
569}
570
Eric Anholt21d40d32010-03-25 11:11:14 -0700571static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800572 int mode)
573{
574 u8 status, state = SDVO_ENCODER_STATE_ON;
575
576 switch (mode) {
577 case DRM_MODE_DPMS_ON:
578 state = SDVO_ENCODER_STATE_ON;
579 break;
580 case DRM_MODE_DPMS_STANDBY:
581 state = SDVO_ENCODER_STATE_STANDBY;
582 break;
583 case DRM_MODE_DPMS_SUSPEND:
584 state = SDVO_ENCODER_STATE_SUSPEND;
585 break;
586 case DRM_MODE_DPMS_OFF:
587 state = SDVO_ENCODER_STATE_OFF;
588 break;
589 }
590
Eric Anholt21d40d32010-03-25 11:11:14 -0700591 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
Jesse Barnes79e53942008-11-07 14:24:08 -0800592 sizeof(state));
Eric Anholt21d40d32010-03-25 11:11:14 -0700593 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800594
595 return (status == SDVO_CMD_STATUS_SUCCESS);
596}
597
Eric Anholt21d40d32010-03-25 11:11:14 -0700598static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800599 int *clock_min,
600 int *clock_max)
601{
602 struct intel_sdvo_pixel_clock_range clocks;
603 u8 status;
604
Eric Anholt21d40d32010-03-25 11:11:14 -0700605 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
Jesse Barnes79e53942008-11-07 14:24:08 -0800606 NULL, 0);
607
Eric Anholt21d40d32010-03-25 11:11:14 -0700608 status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks));
Jesse Barnes79e53942008-11-07 14:24:08 -0800609
610 if (status != SDVO_CMD_STATUS_SUCCESS)
611 return false;
612
613 /* Convert the values from units of 10 kHz to kHz. */
614 *clock_min = clocks.min * 10;
615 *clock_max = clocks.max * 10;
616
617 return true;
618}
619
Eric Anholt21d40d32010-03-25 11:11:14 -0700620static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800621 u16 outputs)
622{
623 u8 status;
624
Eric Anholt21d40d32010-03-25 11:11:14 -0700625 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800626 sizeof(outputs));
627
Eric Anholt21d40d32010-03-25 11:11:14 -0700628 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800629 return (status == SDVO_CMD_STATUS_SUCCESS);
630}
631
Eric Anholt21d40d32010-03-25 11:11:14 -0700632static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800633 struct intel_sdvo_dtd *dtd)
634{
635 u8 status;
636
Eric Anholt21d40d32010-03-25 11:11:14 -0700637 intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1));
638 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800639 if (status != SDVO_CMD_STATUS_SUCCESS)
640 return false;
641
Eric Anholt21d40d32010-03-25 11:11:14 -0700642 intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2));
643 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800644 if (status != SDVO_CMD_STATUS_SUCCESS)
645 return false;
646
647 return true;
648}
649
Eric Anholt21d40d32010-03-25 11:11:14 -0700650static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800651 struct intel_sdvo_dtd *dtd)
652{
Eric Anholt21d40d32010-03-25 11:11:14 -0700653 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800654 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
655}
656
Eric Anholt21d40d32010-03-25 11:11:14 -0700657static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800658 struct intel_sdvo_dtd *dtd)
659{
Eric Anholt21d40d32010-03-25 11:11:14 -0700660 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800661 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
662}
663
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800664static bool
Eric Anholtc751ce42010-03-25 11:48:48 -0700665intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800666 uint16_t clock,
667 uint16_t width,
668 uint16_t height)
669{
670 struct intel_sdvo_preferred_input_timing_args args;
Eric Anholtc751ce42010-03-25 11:48:48 -0700671 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800672 uint8_t status;
673
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800674 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800675 args.clock = clock;
676 args.width = width;
677 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800678 args.interlace = 0;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800679
680 if (sdvo_priv->is_lvds &&
681 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
682 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
683 args.scaled = 1;
684
Eric Anholtc751ce42010-03-25 11:48:48 -0700685 intel_sdvo_write_cmd(intel_encoder,
686 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800687 &args, sizeof(args));
Eric Anholtc751ce42010-03-25 11:48:48 -0700688 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800689 if (status != SDVO_CMD_STATUS_SUCCESS)
690 return false;
691
692 return true;
693}
694
Eric Anholtc751ce42010-03-25 11:48:48 -0700695static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800696 struct intel_sdvo_dtd *dtd)
697{
698 bool status;
699
Eric Anholtc751ce42010-03-25 11:48:48 -0700700 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800701 NULL, 0);
702
Eric Anholtc751ce42010-03-25 11:48:48 -0700703 status = intel_sdvo_read_response(intel_encoder, &dtd->part1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800704 sizeof(dtd->part1));
705 if (status != SDVO_CMD_STATUS_SUCCESS)
706 return false;
707
Eric Anholtc751ce42010-03-25 11:48:48 -0700708 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800709 NULL, 0);
710
Eric Anholtc751ce42010-03-25 11:48:48 -0700711 status = intel_sdvo_read_response(intel_encoder, &dtd->part2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800712 sizeof(dtd->part2));
713 if (status != SDVO_CMD_STATUS_SUCCESS)
714 return false;
715
716 return false;
717}
Jesse Barnes79e53942008-11-07 14:24:08 -0800718
Eric Anholt21d40d32010-03-25 11:11:14 -0700719static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800720{
721 u8 status;
722
Eric Anholt21d40d32010-03-25 11:11:14 -0700723 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
724 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800725 if (status != SDVO_CMD_STATUS_SUCCESS)
726 return false;
727
728 return true;
729}
730
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800731static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
732 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800733{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800734 uint16_t width, height;
735 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
736 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800737
738 width = mode->crtc_hdisplay;
739 height = mode->crtc_vdisplay;
740
741 /* do some mode translations */
742 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
743 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
744
745 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
746 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
747
748 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
749 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
750
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800751 dtd->part1.clock = mode->clock / 10;
752 dtd->part1.h_active = width & 0xff;
753 dtd->part1.h_blank = h_blank_len & 0xff;
754 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800755 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800756 dtd->part1.v_active = height & 0xff;
757 dtd->part1.v_blank = v_blank_len & 0xff;
758 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800759 ((v_blank_len >> 8) & 0xf);
760
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800761 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800762 dtd->part2.h_sync_width = h_sync_len & 0xff;
763 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800764 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800765 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800766 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
767 ((v_sync_len & 0x30) >> 4);
768
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800769 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800770 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800771 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800772 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800773 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800774
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800775 dtd->part2.sdvo_flags = 0;
776 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
777 dtd->part2.reserved = 0;
778}
Jesse Barnes79e53942008-11-07 14:24:08 -0800779
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800780static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
781 struct intel_sdvo_dtd *dtd)
782{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800783 mode->hdisplay = dtd->part1.h_active;
784 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
785 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800786 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800787 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
788 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
789 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
790 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
791
792 mode->vdisplay = dtd->part1.v_active;
793 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
794 mode->vsync_start = mode->vdisplay;
795 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800796 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800797 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
798 mode->vsync_end = mode->vsync_start +
799 (dtd->part2.v_sync_off_width & 0xf);
800 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
801 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
802 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
803
804 mode->clock = dtd->part1.clock * 10;
805
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800806 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800807 if (dtd->part2.dtd_flags & 0x2)
808 mode->flags |= DRM_MODE_FLAG_PHSYNC;
809 if (dtd->part2.dtd_flags & 0x4)
810 mode->flags |= DRM_MODE_FLAG_PVSYNC;
811}
812
Eric Anholtc751ce42010-03-25 11:48:48 -0700813static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800814 struct intel_sdvo_encode *encode)
815{
816 uint8_t status;
817
Eric Anholtc751ce42010-03-25 11:48:48 -0700818 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
819 status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800820 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
821 memset(encode, 0, sizeof(*encode));
822 return false;
823 }
824
825 return true;
826}
827
Eric Anholtc751ce42010-03-25 11:48:48 -0700828static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder,
829 uint8_t mode)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800830{
831 uint8_t status;
832
Eric Anholtc751ce42010-03-25 11:48:48 -0700833 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1);
834 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800835
836 return (status == SDVO_CMD_STATUS_SUCCESS);
837}
838
Eric Anholtc751ce42010-03-25 11:48:48 -0700839static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800840 uint8_t mode)
841{
842 uint8_t status;
843
Eric Anholtc751ce42010-03-25 11:48:48 -0700844 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
845 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800846
847 return (status == SDVO_CMD_STATUS_SUCCESS);
848}
849
850#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -0700851static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800852{
853 int i, j;
854 uint8_t set_buf_index[2];
855 uint8_t av_split;
856 uint8_t buf_size;
857 uint8_t buf[48];
858 uint8_t *pos;
859
Eric Anholtc751ce42010-03-25 11:48:48 -0700860 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
861 intel_sdvo_read_response(encoder, &av_split, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800862
863 for (i = 0; i <= av_split; i++) {
864 set_buf_index[0] = i; set_buf_index[1] = 0;
Eric Anholtc751ce42010-03-25 11:48:48 -0700865 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800866 set_buf_index, 2);
Eric Anholtc751ce42010-03-25 11:48:48 -0700867 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
868 intel_sdvo_read_response(encoder, &buf_size, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800869
870 pos = buf;
871 for (j = 0; j <= buf_size; j += 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700872 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800873 NULL, 0);
Eric Anholtc751ce42010-03-25 11:48:48 -0700874 intel_sdvo_read_response(encoder, pos, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800875 pos += 8;
876 }
877 }
878}
879#endif
880
Eric Anholtc751ce42010-03-25 11:48:48 -0700881static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder,
882 int index,
883 uint8_t *data, int8_t size, uint8_t tx_rate)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800884{
885 uint8_t set_buf_index[2];
886
887 set_buf_index[0] = index;
888 set_buf_index[1] = 0;
889
Eric Anholtc751ce42010-03-25 11:48:48 -0700890 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX,
891 set_buf_index, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800892
893 for (; size > 0; size -= 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700894 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800895 data += 8;
896 }
897
Eric Anholtc751ce42010-03-25 11:48:48 -0700898 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800899}
900
901static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
902{
903 uint8_t csum = 0;
904 int i;
905
906 for (i = 0; i < size; i++)
907 csum += data[i];
908
909 return 0x100 - csum;
910}
911
912#define DIP_TYPE_AVI 0x82
913#define DIP_VERSION_AVI 0x2
914#define DIP_LEN_AVI 13
915
916struct dip_infoframe {
917 uint8_t type;
918 uint8_t version;
919 uint8_t len;
920 uint8_t checksum;
921 union {
922 struct {
923 /* Packet Byte #1 */
924 uint8_t S:2;
925 uint8_t B:2;
926 uint8_t A:1;
927 uint8_t Y:2;
928 uint8_t rsvd1:1;
929 /* Packet Byte #2 */
930 uint8_t R:4;
931 uint8_t M:2;
932 uint8_t C:2;
933 /* Packet Byte #3 */
934 uint8_t SC:2;
935 uint8_t Q:2;
936 uint8_t EC:3;
937 uint8_t ITC:1;
938 /* Packet Byte #4 */
939 uint8_t VIC:7;
940 uint8_t rsvd2:1;
941 /* Packet Byte #5 */
942 uint8_t PR:4;
943 uint8_t rsvd3:4;
944 /* Packet Byte #6~13 */
945 uint16_t top_bar_end;
946 uint16_t bottom_bar_start;
947 uint16_t left_bar_end;
948 uint16_t right_bar_start;
949 } avi;
950 struct {
951 /* Packet Byte #1 */
952 uint8_t channel_count:3;
953 uint8_t rsvd1:1;
954 uint8_t coding_type:4;
955 /* Packet Byte #2 */
956 uint8_t sample_size:2; /* SS0, SS1 */
957 uint8_t sample_frequency:3;
958 uint8_t rsvd2:3;
959 /* Packet Byte #3 */
960 uint8_t coding_type_private:5;
961 uint8_t rsvd3:3;
962 /* Packet Byte #4 */
963 uint8_t channel_allocation;
964 /* Packet Byte #5 */
965 uint8_t rsvd4:3;
966 uint8_t level_shift:4;
967 uint8_t downmix_inhibit:1;
968 } audio;
969 uint8_t payload[28];
970 } __attribute__ ((packed)) u;
971} __attribute__((packed));
972
Eric Anholtc751ce42010-03-25 11:48:48 -0700973static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800974 struct drm_display_mode * mode)
975{
976 struct dip_infoframe avi_if = {
977 .type = DIP_TYPE_AVI,
978 .version = DIP_VERSION_AVI,
979 .len = DIP_LEN_AVI,
980 };
981
982 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
983 4 + avi_if.len);
Eric Anholtc751ce42010-03-25 11:48:48 -0700984 intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if,
985 4 + avi_if.len,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800986 SDVO_HBUF_TX_VSYNC);
987}
988
Eric Anholtc751ce42010-03-25 11:48:48 -0700989static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +0800990{
Zhenyu Wang7026d4a2009-03-24 14:02:43 +0800991
Zhao Yakuice6feab2009-08-24 13:50:26 +0800992 struct intel_sdvo_tv_format format;
Eric Anholtc751ce42010-03-25 11:48:48 -0700993 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +0800994 uint32_t format_map, i;
995 uint8_t status;
996
997 for (i = 0; i < TV_FORMAT_NUM; i++)
998 if (tv_format_names[i] == sdvo_priv->tv_format_name)
999 break;
1000
1001 format_map = 1 << i;
1002 memset(&format, 0, sizeof(format));
1003 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
1004 sizeof(format) : sizeof(format_map));
1005
Eric Anholtc751ce42010-03-25 11:48:48 -07001006 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format_map,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001007 sizeof(format));
1008
Eric Anholtc751ce42010-03-25 11:48:48 -07001009 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001010 if (status != SDVO_CMD_STATUS_SUCCESS)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001011 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
Zhao Yakuice6feab2009-08-24 13:50:26 +08001012 SDVO_NAME(sdvo_priv));
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001013}
1014
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001015static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1016 struct drm_display_mode *mode,
1017 struct drm_display_mode *adjusted_mode)
1018{
Eric Anholtc751ce42010-03-25 11:48:48 -07001019 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1020 struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001021
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001022 if (dev_priv->is_tv) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001023 struct intel_sdvo_dtd output_dtd;
1024 bool success;
1025
1026 /* We need to construct preferred input timings based on our
1027 * output timings. To do that, we have to set the output
1028 * timings, even though this isn't really the right place in
1029 * the sequence to do it. Oh well.
1030 */
1031
1032
1033 /* Set output timings */
1034 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
Eric Anholtc751ce42010-03-25 11:48:48 -07001035 intel_sdvo_set_target_output(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001036 dev_priv->controlled_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001037 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001038
1039 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001040 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001041
1042
Eric Anholtc751ce42010-03-25 11:48:48 -07001043 success = intel_sdvo_create_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001044 mode->clock / 10,
1045 mode->hdisplay,
1046 mode->vdisplay);
1047 if (success) {
1048 struct intel_sdvo_dtd input_dtd;
1049
Eric Anholtc751ce42010-03-25 11:48:48 -07001050 intel_sdvo_get_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001051 &input_dtd);
1052 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001053 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001054
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001055 drm_mode_set_crtcinfo(adjusted_mode, 0);
1056
1057 mode->clock = adjusted_mode->clock;
1058
1059 adjusted_mode->clock *=
1060 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001061 } else {
1062 return false;
1063 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001064 } else if (dev_priv->is_lvds) {
1065 struct intel_sdvo_dtd output_dtd;
1066 bool success;
1067
1068 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1069 /* Set output timings */
1070 intel_sdvo_get_dtd_from_mode(&output_dtd,
1071 dev_priv->sdvo_lvds_fixed_mode);
1072
Eric Anholtc751ce42010-03-25 11:48:48 -07001073 intel_sdvo_set_target_output(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001074 dev_priv->controlled_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001075 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001076
1077 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001078 intel_sdvo_set_target_input(intel_encoder, true, false);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001079
1080
1081 success = intel_sdvo_create_preferred_input_timing(
Eric Anholtc751ce42010-03-25 11:48:48 -07001082 intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001083 mode->clock / 10,
1084 mode->hdisplay,
1085 mode->vdisplay);
1086
1087 if (success) {
1088 struct intel_sdvo_dtd input_dtd;
1089
Eric Anholtc751ce42010-03-25 11:48:48 -07001090 intel_sdvo_get_preferred_input_timing(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001091 &input_dtd);
1092 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1093 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1094
1095 drm_mode_set_crtcinfo(adjusted_mode, 0);
1096
1097 mode->clock = adjusted_mode->clock;
1098
1099 adjusted_mode->clock *=
1100 intel_sdvo_get_pixel_multiplier(mode);
1101 } else {
1102 return false;
1103 }
1104
1105 } else {
1106 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1107 * SDVO device will be told of the multiplier during mode_set.
1108 */
1109 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001110 }
1111 return true;
1112}
1113
1114static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1115 struct drm_display_mode *mode,
1116 struct drm_display_mode *adjusted_mode)
1117{
1118 struct drm_device *dev = encoder->dev;
1119 struct drm_i915_private *dev_priv = dev->dev_private;
1120 struct drm_crtc *crtc = encoder->crtc;
1121 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Eric Anholtc751ce42010-03-25 11:48:48 -07001122 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1123 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001124 u32 sdvox = 0;
1125 int sdvo_pixel_multiply;
1126 struct intel_sdvo_in_out_map in_out;
1127 struct intel_sdvo_dtd input_dtd;
1128 u8 status;
1129
1130 if (!mode)
1131 return;
1132
1133 /* First, set the input mapping for the first input to our controlled
1134 * output. This is only correct if we're a single-input device, in
1135 * which case the first input is the output from the appropriate SDVO
1136 * channel on the motherboard. In a two-input device, the first input
1137 * will be SDVOB and the second SDVOC.
1138 */
1139 in_out.in0 = sdvo_priv->controlled_output;
1140 in_out.in1 = 0;
1141
Eric Anholtc751ce42010-03-25 11:48:48 -07001142 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001143 &in_out, sizeof(in_out));
Eric Anholtc751ce42010-03-25 11:48:48 -07001144 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001145
1146 if (sdvo_priv->is_hdmi) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001147 intel_sdvo_set_avi_infoframe(intel_encoder, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001148 sdvox |= SDVO_AUDIO_ENABLE;
1149 }
1150
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001151 /* We have tried to get input timing in mode_fixup, and filled into
1152 adjusted_mode */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001153 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001154 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001155 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
1156 } else
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001157 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001158
1159 /* If it's a TV, we already set the output timing in mode_fixup.
1160 * Otherwise, the output timing is equal to the input timing.
1161 */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001162 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001163 /* Set the output timing to the screen */
Eric Anholtc751ce42010-03-25 11:48:48 -07001164 intel_sdvo_set_target_output(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001165 sdvo_priv->controlled_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001166 intel_sdvo_set_output_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001167 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001168
1169 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001170 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001171
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001172 if (sdvo_priv->is_tv)
Eric Anholtc751ce42010-03-25 11:48:48 -07001173 intel_sdvo_set_tv_format(intel_encoder);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001174
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001175 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001176 * provide the device with a timing it can support, if it supports that
1177 * feature. However, presumably we would need to adjust the CRTC to
1178 * output the preferred timing, and we don't support that currently.
1179 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001180#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -07001181 success = intel_sdvo_create_preferred_input_timing(encoder, clock,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001182 width, height);
1183 if (success) {
1184 struct intel_sdvo_dtd *input_dtd;
1185
Eric Anholtc751ce42010-03-25 11:48:48 -07001186 intel_sdvo_get_preferred_input_timing(encoder, &input_dtd);
1187 intel_sdvo_set_input_timing(encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001188 }
1189#else
Eric Anholtc751ce42010-03-25 11:48:48 -07001190 intel_sdvo_set_input_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001191#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001192
1193 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1194 case 1:
Eric Anholtc751ce42010-03-25 11:48:48 -07001195 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001196 SDVO_CLOCK_RATE_MULT_1X);
1197 break;
1198 case 2:
Eric Anholtc751ce42010-03-25 11:48:48 -07001199 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001200 SDVO_CLOCK_RATE_MULT_2X);
1201 break;
1202 case 4:
Eric Anholtc751ce42010-03-25 11:48:48 -07001203 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001204 SDVO_CLOCK_RATE_MULT_4X);
1205 break;
1206 }
1207
1208 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001209 if (IS_I965G(dev)) {
1210 sdvox |= SDVO_BORDER_ENABLE |
1211 SDVO_VSYNC_ACTIVE_HIGH |
1212 SDVO_HSYNC_ACTIVE_HIGH;
1213 } else {
Eric Anholtc751ce42010-03-25 11:48:48 -07001214 sdvox |= I915_READ(sdvo_priv->sdvo_reg);
1215 switch (sdvo_priv->sdvo_reg) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001216 case SDVOB:
1217 sdvox &= SDVOB_PRESERVE_MASK;
1218 break;
1219 case SDVOC:
1220 sdvox &= SDVOC_PRESERVE_MASK;
1221 break;
1222 }
1223 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1224 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001225 if (intel_crtc->pipe == 1)
1226 sdvox |= SDVO_PIPE_B_SELECT;
1227
1228 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1229 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001230 /* done in crtc_mode_set as the dpll_md reg must be written early */
1231 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1232 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001233 } else {
1234 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1235 }
1236
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001237 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
1238 sdvox |= SDVO_STALL_SELECT;
Eric Anholtc751ce42010-03-25 11:48:48 -07001239 intel_sdvo_write_sdvox(intel_encoder, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001240}
1241
1242static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1243{
1244 struct drm_device *dev = encoder->dev;
1245 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001246 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1247 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001248 u32 temp;
1249
1250 if (mode != DRM_MODE_DPMS_ON) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001251 intel_sdvo_set_active_outputs(intel_encoder, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -08001252 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001253 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -08001254
1255 if (mode == DRM_MODE_DPMS_OFF) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001256 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001257 if ((temp & SDVO_ENABLE) != 0) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001258 intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001259 }
1260 }
1261 } else {
1262 bool input1, input2;
1263 int i;
1264 u8 status;
1265
Eric Anholtc751ce42010-03-25 11:48:48 -07001266 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001267 if ((temp & SDVO_ENABLE) == 0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001268 intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001269 for (i = 0; i < 2; i++)
1270 intel_wait_for_vblank(dev);
1271
Eric Anholt21d40d32010-03-25 11:11:14 -07001272 status = intel_sdvo_get_trained_inputs(intel_encoder, &input1,
Jesse Barnes79e53942008-11-07 14:24:08 -08001273 &input2);
1274
1275
1276 /* Warn if the device reported failure to sync.
1277 * A lot of SDVO devices fail to notify of sync, but it's
1278 * a given it the status is a success, we succeeded.
1279 */
1280 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001281 DRM_DEBUG_KMS("First %s output reported failure to "
1282 "sync\n", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -08001283 }
1284
1285 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001286 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
1287 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->controlled_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001288 }
1289 return;
1290}
1291
Jesse Barnes79e53942008-11-07 14:24:08 -08001292static int intel_sdvo_mode_valid(struct drm_connector *connector,
1293 struct drm_display_mode *mode)
1294{
Eric Anholt21d40d32010-03-25 11:11:14 -07001295 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1296 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001297
1298 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1299 return MODE_NO_DBLESCAN;
1300
1301 if (sdvo_priv->pixel_clock_min > mode->clock)
1302 return MODE_CLOCK_LOW;
1303
1304 if (sdvo_priv->pixel_clock_max < mode->clock)
1305 return MODE_CLOCK_HIGH;
1306
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001307 if (sdvo_priv->is_lvds == true) {
1308 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
1309 return MODE_PANEL;
1310
1311 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
1312 return MODE_PANEL;
1313
1314 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1315 return MODE_PANEL;
1316 }
1317
Jesse Barnes79e53942008-11-07 14:24:08 -08001318 return MODE_OK;
1319}
1320
Eric Anholt21d40d32010-03-25 11:11:14 -07001321static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps)
Jesse Barnes79e53942008-11-07 14:24:08 -08001322{
1323 u8 status;
1324
Eric Anholt21d40d32010-03-25 11:11:14 -07001325 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1326 status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps));
Jesse Barnes79e53942008-11-07 14:24:08 -08001327 if (status != SDVO_CMD_STATUS_SUCCESS)
1328 return false;
1329
1330 return true;
1331}
1332
1333struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1334{
1335 struct drm_connector *connector = NULL;
Eric Anholt21d40d32010-03-25 11:11:14 -07001336 struct intel_encoder *iout = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001337 struct intel_sdvo_priv *sdvo;
1338
1339 /* find the sdvo connector */
1340 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001341 iout = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001342
1343 if (iout->type != INTEL_OUTPUT_SDVO)
1344 continue;
1345
1346 sdvo = iout->dev_priv;
1347
Eric Anholtc751ce42010-03-25 11:48:48 -07001348 if (sdvo->sdvo_reg == SDVOB && sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001349 return connector;
1350
Eric Anholtc751ce42010-03-25 11:48:48 -07001351 if (sdvo->sdvo_reg == SDVOC && !sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001352 return connector;
1353
1354 }
1355
1356 return NULL;
1357}
1358
1359int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1360{
1361 u8 response[2];
1362 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001363 struct intel_encoder *intel_encoder;
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001364 DRM_DEBUG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -08001365
1366 if (!connector)
1367 return 0;
1368
Eric Anholt21d40d32010-03-25 11:11:14 -07001369 intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001370
Eric Anholt21d40d32010-03-25 11:11:14 -07001371 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1372 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001373
1374 if (response[0] !=0)
1375 return 1;
1376
1377 return 0;
1378}
1379
1380void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1381{
1382 u8 response[2];
1383 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001384 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001385
Eric Anholt21d40d32010-03-25 11:11:14 -07001386 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1387 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001388
1389 if (on) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001390 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1391 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001392
Eric Anholt21d40d32010-03-25 11:11:14 -07001393 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001394 } else {
1395 response[0] = 0;
1396 response[1] = 0;
Eric Anholt21d40d32010-03-25 11:11:14 -07001397 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001398 }
1399
Eric Anholt21d40d32010-03-25 11:11:14 -07001400 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1401 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001402}
1403
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001404static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07001405intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001406{
Eric Anholt21d40d32010-03-25 11:11:14 -07001407 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001408 int caps = 0;
1409
1410 if (sdvo_priv->caps.output_flags &
1411 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1412 caps++;
1413 if (sdvo_priv->caps.output_flags &
1414 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1415 caps++;
1416 if (sdvo_priv->caps.output_flags &
Roel Kluin19e1f882009-08-09 13:50:53 +02001417 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001418 caps++;
1419 if (sdvo_priv->caps.output_flags &
1420 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1421 caps++;
1422 if (sdvo_priv->caps.output_flags &
1423 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1424 caps++;
1425
1426 if (sdvo_priv->caps.output_flags &
1427 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1428 caps++;
1429
1430 if (sdvo_priv->caps.output_flags &
1431 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1432 caps++;
1433
1434 return (caps > 1);
1435}
1436
Keith Packard57cdaf92009-09-04 13:07:54 +08001437static struct drm_connector *
1438intel_find_analog_connector(struct drm_device *dev)
1439{
1440 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -07001441 struct intel_encoder *intel_encoder;
Keith Packard57cdaf92009-09-04 13:07:54 +08001442
1443 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001444 intel_encoder = to_intel_encoder(connector);
1445 if (intel_encoder->type == INTEL_OUTPUT_ANALOG)
Keith Packard57cdaf92009-09-04 13:07:54 +08001446 return connector;
1447 }
1448 return NULL;
1449}
1450
1451static int
1452intel_analog_is_connected(struct drm_device *dev)
1453{
1454 struct drm_connector *analog_connector;
1455 analog_connector = intel_find_analog_connector(dev);
1456
1457 if (!analog_connector)
1458 return false;
1459
1460 if (analog_connector->funcs->detect(analog_connector) ==
1461 connector_status_disconnected)
1462 return false;
1463
1464 return true;
1465}
1466
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001467enum drm_connector_status
1468intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
Ma Ling9dff6af2009-04-02 13:13:26 +08001469{
Eric Anholt21d40d32010-03-25 11:11:14 -07001470 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1471 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001472 enum drm_connector_status status = connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001473 struct edid *edid = NULL;
1474
Eric Anholt21d40d32010-03-25 11:11:14 -07001475 edid = drm_get_edid(&intel_encoder->base,
1476 intel_encoder->ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001477
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001478 /* This is only applied to SDVO cards with multiple outputs */
Eric Anholt21d40d32010-03-25 11:11:14 -07001479 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) {
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001480 uint8_t saved_ddc, temp_ddc;
1481 saved_ddc = sdvo_priv->ddc_bus;
1482 temp_ddc = sdvo_priv->ddc_bus >> 1;
1483 /*
1484 * Don't use the 1 as the argument of DDC bus switch to get
1485 * the EDID. It is used for SDVO SPD ROM.
1486 */
1487 while(temp_ddc > 1) {
1488 sdvo_priv->ddc_bus = temp_ddc;
Eric Anholt21d40d32010-03-25 11:11:14 -07001489 edid = drm_get_edid(&intel_encoder->base,
1490 intel_encoder->ddc_bus);
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001491 if (edid) {
1492 /*
1493 * When we can get the EDID, maybe it is the
1494 * correct DDC bus. Update it.
1495 */
1496 sdvo_priv->ddc_bus = temp_ddc;
1497 break;
1498 }
1499 temp_ddc >>= 1;
1500 }
1501 if (edid == NULL)
1502 sdvo_priv->ddc_bus = saved_ddc;
1503 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001504 /* when there is no edid and no monitor is connected with VGA
1505 * port, try to use the CRT ddc to read the EDID for DVI-connector
1506 */
1507 if (edid == NULL &&
1508 sdvo_priv->analog_ddc_bus &&
Eric Anholt21d40d32010-03-25 11:11:14 -07001509 !intel_analog_is_connected(intel_encoder->base.dev))
1510 edid = drm_get_edid(&intel_encoder->base,
Keith Packard57cdaf92009-09-04 13:07:54 +08001511 sdvo_priv->analog_ddc_bus);
Ma Ling9dff6af2009-04-02 13:13:26 +08001512 if (edid != NULL) {
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001513 /* Don't report the output as connected if it's a DVI-I
1514 * connector with a non-digital EDID coming out.
1515 */
1516 if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
1517 if (edid->input & DRM_EDID_INPUT_DIGITAL)
1518 sdvo_priv->is_hdmi =
1519 drm_detect_hdmi_monitor(edid);
1520 else
1521 status = connector_status_disconnected;
1522 }
1523
Ma Ling9dff6af2009-04-02 13:13:26 +08001524 kfree(edid);
Eric Anholt21d40d32010-03-25 11:11:14 -07001525 intel_encoder->base.display_info.raw_edid = NULL;
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001526
1527 } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1528 status = connector_status_disconnected;
1529
1530 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +08001531}
1532
Jesse Barnes79e53942008-11-07 14:24:08 -08001533static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1534{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001535 uint16_t response;
Jesse Barnes79e53942008-11-07 14:24:08 -08001536 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001537 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1538 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001539
Eric Anholt21d40d32010-03-25 11:11:14 -07001540 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001541 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
Zhao Yakuid09c23d2009-11-06 15:39:56 +08001542 if (sdvo_priv->is_tv) {
1543 /* add 30ms delay when the output type is SDVO-TV */
1544 mdelay(30);
1545 }
Eric Anholt21d40d32010-03-25 11:11:14 -07001546 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001547
Dave Airlie51c8b402009-08-20 13:38:04 +10001548 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001549
1550 if (status != SDVO_CMD_STATUS_SUCCESS)
1551 return connector_status_unknown;
1552
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001553 if (response == 0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001554 return connector_status_disconnected;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001555
Eric Anholt21d40d32010-03-25 11:11:14 -07001556 if (intel_sdvo_multifunc_encoder(intel_encoder) &&
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001557 sdvo_priv->attached_output != response) {
1558 if (sdvo_priv->controlled_output != response &&
Eric Anholt21d40d32010-03-25 11:11:14 -07001559 intel_sdvo_output_setup(intel_encoder, response) != true)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001560 return connector_status_unknown;
1561 sdvo_priv->attached_output = response;
1562 }
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001563 return intel_sdvo_hdmi_sink_detect(connector, response);
Jesse Barnes79e53942008-11-07 14:24:08 -08001564}
1565
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001566static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001567{
Eric Anholt21d40d32010-03-25 11:11:14 -07001568 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1569 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Keith Packard57cdaf92009-09-04 13:07:54 +08001570 int num_modes;
Jesse Barnes79e53942008-11-07 14:24:08 -08001571
1572 /* set the bus switch and get the modes */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001573 num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001574
Keith Packard57cdaf92009-09-04 13:07:54 +08001575 /*
1576 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1577 * link between analog and digital outputs. So, if the regular SDVO
1578 * DDC fails, check to see if the analog output is disconnected, in
1579 * which case we'll look there for the digital DDC data.
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001580 */
Keith Packard57cdaf92009-09-04 13:07:54 +08001581 if (num_modes == 0 &&
1582 sdvo_priv->analog_ddc_bus &&
Eric Anholt21d40d32010-03-25 11:11:14 -07001583 !intel_analog_is_connected(intel_encoder->base.dev)) {
Keith Packard57cdaf92009-09-04 13:07:54 +08001584 /* Switch to the analog ddc bus and try that
1585 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001586 (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001587 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001588}
1589
1590/*
1591 * Set of SDVO TV modes.
1592 * Note! This is in reply order (see loop in get_tv_modes).
1593 * XXX: all 60Hz refresh?
1594 */
1595struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001596 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1597 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001598 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001599 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1600 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001601 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001602 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1603 496, 0, 300, 301, 332, 333, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001604 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001605 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1606 736, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001607 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001608 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1609 736, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001610 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001611 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1612 736, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001613 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001614 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1615 800, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001616 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001617 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1618 800, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001619 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001620 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1621 816, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001622 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001623 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1624 816, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001625 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001626 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1627 816, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001628 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001629 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1630 816, 0, 540, 541, 572, 573, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001631 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001632 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1633 816, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001634 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001635 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1636 864, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001637 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001638 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1639 896, 0, 600, 601, 632, 633, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001640 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001641 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1642 928, 0, 624, 625, 656, 657, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001643 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001644 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1645 1016, 0, 766, 767, 798, 799, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001646 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001647 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1648 1120, 0, 768, 769, 800, 801, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001649 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001650 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1651 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001652 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1653};
1654
1655static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1656{
Eric Anholt21d40d32010-03-25 11:11:14 -07001657 struct intel_encoder *output = to_intel_encoder(connector);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001658 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
1659 struct intel_sdvo_sdtv_resolution_request tv_res;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001660 uint32_t reply = 0, format_map = 0;
1661 int i;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001662 uint8_t status;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001663
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001664
1665 /* Read the list of supported input resolutions for the selected TV
1666 * format.
1667 */
Zhao Yakuice6feab2009-08-24 13:50:26 +08001668 for (i = 0; i < TV_FORMAT_NUM; i++)
1669 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1670 break;
1671
1672 format_map = (1 << i);
1673 memcpy(&tv_res, &format_map,
1674 sizeof(struct intel_sdvo_sdtv_resolution_request) >
1675 sizeof(format_map) ? sizeof(format_map) :
1676 sizeof(struct intel_sdvo_sdtv_resolution_request));
1677
1678 intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
1679
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001680 intel_sdvo_write_cmd(output, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001681 &tv_res, sizeof(tv_res));
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001682 status = intel_sdvo_read_response(output, &reply, 3);
1683 if (status != SDVO_CMD_STATUS_SUCCESS)
1684 return;
1685
1686 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001687 if (reply & (1 << i)) {
1688 struct drm_display_mode *nmode;
1689 nmode = drm_mode_duplicate(connector->dev,
1690 &sdvo_tv_modes[i]);
1691 if (nmode)
1692 drm_mode_probed_add(connector, nmode);
1693 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001694
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001695}
1696
Ma Ling7086c872009-05-13 11:20:06 +08001697static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1698{
Eric Anholt21d40d32010-03-25 11:11:14 -07001699 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Ma Ling7086c872009-05-13 11:20:06 +08001700 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001701 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001702 struct drm_display_mode *newmode;
Ma Ling7086c872009-05-13 11:20:06 +08001703
1704 /*
1705 * Attempt to get the mode list from DDC.
1706 * Assume that the preferred modes are
1707 * arranged in priority order.
1708 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001709 intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Ma Ling7086c872009-05-13 11:20:06 +08001710 if (list_empty(&connector->probed_modes) == false)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001711 goto end;
Ma Ling7086c872009-05-13 11:20:06 +08001712
1713 /* Fetch modes from VBT */
1714 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
Ma Ling7086c872009-05-13 11:20:06 +08001715 newmode = drm_mode_duplicate(connector->dev,
1716 dev_priv->sdvo_lvds_vbt_mode);
1717 if (newmode != NULL) {
1718 /* Guarantee the mode is preferred */
1719 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1720 DRM_MODE_TYPE_DRIVER);
1721 drm_mode_probed_add(connector, newmode);
1722 }
1723 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001724
1725end:
1726 list_for_each_entry(newmode, &connector->probed_modes, head) {
1727 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1728 sdvo_priv->sdvo_lvds_fixed_mode =
1729 drm_mode_duplicate(connector->dev, newmode);
1730 break;
1731 }
1732 }
1733
Ma Ling7086c872009-05-13 11:20:06 +08001734}
1735
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001736static int intel_sdvo_get_modes(struct drm_connector *connector)
1737{
Eric Anholt21d40d32010-03-25 11:11:14 -07001738 struct intel_encoder *output = to_intel_encoder(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001739 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
1740
1741 if (sdvo_priv->is_tv)
1742 intel_sdvo_get_tv_modes(connector);
Ma Ling7086c872009-05-13 11:20:06 +08001743 else if (sdvo_priv->is_lvds == true)
1744 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001745 else
1746 intel_sdvo_get_ddc_modes(connector);
1747
Jesse Barnes79e53942008-11-07 14:24:08 -08001748 if (list_empty(&connector->probed_modes))
1749 return 0;
1750 return 1;
1751}
1752
Zhao Yakuib9219c52009-09-10 15:45:46 +08001753static
1754void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1755{
Eric Anholt21d40d32010-03-25 11:11:14 -07001756 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1757 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001758 struct drm_device *dev = connector->dev;
1759
1760 if (sdvo_priv->is_tv) {
1761 if (sdvo_priv->left_property)
1762 drm_property_destroy(dev, sdvo_priv->left_property);
1763 if (sdvo_priv->right_property)
1764 drm_property_destroy(dev, sdvo_priv->right_property);
1765 if (sdvo_priv->top_property)
1766 drm_property_destroy(dev, sdvo_priv->top_property);
1767 if (sdvo_priv->bottom_property)
1768 drm_property_destroy(dev, sdvo_priv->bottom_property);
1769 if (sdvo_priv->hpos_property)
1770 drm_property_destroy(dev, sdvo_priv->hpos_property);
1771 if (sdvo_priv->vpos_property)
1772 drm_property_destroy(dev, sdvo_priv->vpos_property);
1773 }
1774 if (sdvo_priv->is_tv) {
1775 if (sdvo_priv->saturation_property)
1776 drm_property_destroy(dev,
1777 sdvo_priv->saturation_property);
1778 if (sdvo_priv->contrast_property)
1779 drm_property_destroy(dev,
1780 sdvo_priv->contrast_property);
1781 if (sdvo_priv->hue_property)
1782 drm_property_destroy(dev, sdvo_priv->hue_property);
1783 }
Zhao Yakuid0cbde92009-09-10 15:45:47 +08001784 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001785 if (sdvo_priv->brightness_property)
1786 drm_property_destroy(dev,
1787 sdvo_priv->brightness_property);
1788 }
1789 return;
1790}
1791
Jesse Barnes79e53942008-11-07 14:24:08 -08001792static void intel_sdvo_destroy(struct drm_connector *connector)
1793{
Eric Anholt21d40d32010-03-25 11:11:14 -07001794 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1795 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001796
Eric Anholt21d40d32010-03-25 11:11:14 -07001797 if (intel_encoder->i2c_bus)
1798 intel_i2c_destroy(intel_encoder->i2c_bus);
1799 if (intel_encoder->ddc_bus)
1800 intel_i2c_destroy(intel_encoder->ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001801 if (sdvo_priv->analog_ddc_bus)
1802 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08001803
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001804 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
1805 drm_mode_destroy(connector->dev,
1806 sdvo_priv->sdvo_lvds_fixed_mode);
1807
Zhao Yakuice6feab2009-08-24 13:50:26 +08001808 if (sdvo_priv->tv_format_property)
1809 drm_property_destroy(connector->dev,
1810 sdvo_priv->tv_format_property);
1811
Zhao Yakuid0cbde92009-09-10 15:45:47 +08001812 if (sdvo_priv->is_tv || sdvo_priv->is_lvds)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001813 intel_sdvo_destroy_enhance_property(connector);
1814
Jesse Barnes79e53942008-11-07 14:24:08 -08001815 drm_sysfs_connector_remove(connector);
1816 drm_connector_cleanup(connector);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001817
Eric Anholt21d40d32010-03-25 11:11:14 -07001818 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08001819}
1820
Zhao Yakuice6feab2009-08-24 13:50:26 +08001821static int
1822intel_sdvo_set_property(struct drm_connector *connector,
1823 struct drm_property *property,
1824 uint64_t val)
1825{
Eric Anholt21d40d32010-03-25 11:11:14 -07001826 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
1827 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1828 struct drm_encoder *encoder = &intel_encoder->enc;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001829 struct drm_crtc *crtc = encoder->crtc;
1830 int ret = 0;
1831 bool changed = false;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001832 uint8_t cmd, status;
1833 uint16_t temp_value;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001834
1835 ret = drm_connector_property_set_value(connector, property, val);
1836 if (ret < 0)
1837 goto out;
1838
1839 if (property == sdvo_priv->tv_format_property) {
1840 if (val >= TV_FORMAT_NUM) {
1841 ret = -EINVAL;
1842 goto out;
1843 }
1844 if (sdvo_priv->tv_format_name ==
1845 sdvo_priv->tv_format_supported[val])
1846 goto out;
1847
1848 sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[val];
1849 changed = true;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001850 }
1851
Zhao Yakuid0cbde92009-09-10 15:45:47 +08001852 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001853 cmd = 0;
1854 temp_value = val;
1855 if (sdvo_priv->left_property == property) {
1856 drm_connector_property_set_value(connector,
1857 sdvo_priv->right_property, val);
1858 if (sdvo_priv->left_margin == temp_value)
1859 goto out;
1860
1861 sdvo_priv->left_margin = temp_value;
1862 sdvo_priv->right_margin = temp_value;
1863 temp_value = sdvo_priv->max_hscan -
1864 sdvo_priv->left_margin;
1865 cmd = SDVO_CMD_SET_OVERSCAN_H;
1866 } else if (sdvo_priv->right_property == property) {
1867 drm_connector_property_set_value(connector,
1868 sdvo_priv->left_property, val);
1869 if (sdvo_priv->right_margin == temp_value)
1870 goto out;
1871
1872 sdvo_priv->left_margin = temp_value;
1873 sdvo_priv->right_margin = temp_value;
1874 temp_value = sdvo_priv->max_hscan -
1875 sdvo_priv->left_margin;
1876 cmd = SDVO_CMD_SET_OVERSCAN_H;
1877 } else if (sdvo_priv->top_property == property) {
1878 drm_connector_property_set_value(connector,
1879 sdvo_priv->bottom_property, val);
1880 if (sdvo_priv->top_margin == temp_value)
1881 goto out;
1882
1883 sdvo_priv->top_margin = temp_value;
1884 sdvo_priv->bottom_margin = temp_value;
1885 temp_value = sdvo_priv->max_vscan -
1886 sdvo_priv->top_margin;
1887 cmd = SDVO_CMD_SET_OVERSCAN_V;
1888 } else if (sdvo_priv->bottom_property == property) {
1889 drm_connector_property_set_value(connector,
1890 sdvo_priv->top_property, val);
1891 if (sdvo_priv->bottom_margin == temp_value)
1892 goto out;
1893 sdvo_priv->top_margin = temp_value;
1894 sdvo_priv->bottom_margin = temp_value;
1895 temp_value = sdvo_priv->max_vscan -
1896 sdvo_priv->top_margin;
1897 cmd = SDVO_CMD_SET_OVERSCAN_V;
1898 } else if (sdvo_priv->hpos_property == property) {
1899 if (sdvo_priv->cur_hpos == temp_value)
1900 goto out;
1901
1902 cmd = SDVO_CMD_SET_POSITION_H;
1903 sdvo_priv->cur_hpos = temp_value;
1904 } else if (sdvo_priv->vpos_property == property) {
1905 if (sdvo_priv->cur_vpos == temp_value)
1906 goto out;
1907
1908 cmd = SDVO_CMD_SET_POSITION_V;
1909 sdvo_priv->cur_vpos = temp_value;
1910 } else if (sdvo_priv->saturation_property == property) {
1911 if (sdvo_priv->cur_saturation == temp_value)
1912 goto out;
1913
1914 cmd = SDVO_CMD_SET_SATURATION;
1915 sdvo_priv->cur_saturation = temp_value;
1916 } else if (sdvo_priv->contrast_property == property) {
1917 if (sdvo_priv->cur_contrast == temp_value)
1918 goto out;
1919
1920 cmd = SDVO_CMD_SET_CONTRAST;
1921 sdvo_priv->cur_contrast = temp_value;
1922 } else if (sdvo_priv->hue_property == property) {
1923 if (sdvo_priv->cur_hue == temp_value)
1924 goto out;
1925
1926 cmd = SDVO_CMD_SET_HUE;
1927 sdvo_priv->cur_hue = temp_value;
1928 } else if (sdvo_priv->brightness_property == property) {
1929 if (sdvo_priv->cur_brightness == temp_value)
1930 goto out;
1931
1932 cmd = SDVO_CMD_SET_BRIGHTNESS;
1933 sdvo_priv->cur_brightness = temp_value;
1934 }
1935 if (cmd) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001936 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
1937 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08001938 NULL, 0);
1939 if (status != SDVO_CMD_STATUS_SUCCESS) {
1940 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1941 return -EINVAL;
1942 }
1943 changed = true;
1944 }
1945 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001946 if (changed && crtc)
1947 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1948 crtc->y, crtc->fb);
1949out:
1950 return ret;
1951}
1952
Jesse Barnes79e53942008-11-07 14:24:08 -08001953static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1954 .dpms = intel_sdvo_dpms,
1955 .mode_fixup = intel_sdvo_mode_fixup,
1956 .prepare = intel_encoder_prepare,
1957 .mode_set = intel_sdvo_mode_set,
1958 .commit = intel_encoder_commit,
1959};
1960
1961static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -07001962 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -08001963 .detect = intel_sdvo_detect,
1964 .fill_modes = drm_helper_probe_single_connector_modes,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001965 .set_property = intel_sdvo_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -08001966 .destroy = intel_sdvo_destroy,
1967};
1968
1969static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
1970 .get_modes = intel_sdvo_get_modes,
1971 .mode_valid = intel_sdvo_mode_valid,
1972 .best_encoder = intel_best_encoder,
1973};
1974
Hannes Ederb358d0a2008-12-18 21:18:47 +01001975static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08001976{
1977 drm_encoder_cleanup(encoder);
1978}
1979
1980static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
1981 .destroy = intel_sdvo_enc_destroy,
1982};
1983
1984
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001985/**
1986 * Choose the appropriate DDC bus for control bus switch command for this
1987 * SDVO output based on the controlled output.
1988 *
1989 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
1990 * outputs, then LVDS outputs.
1991 */
1992static void
1993intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
1994{
1995 uint16_t mask = 0;
1996 unsigned int num_bits;
1997
1998 /* Make a mask of outputs less than or equal to our own priority in the
1999 * list.
2000 */
2001 switch (dev_priv->controlled_output) {
2002 case SDVO_OUTPUT_LVDS1:
2003 mask |= SDVO_OUTPUT_LVDS1;
2004 case SDVO_OUTPUT_LVDS0:
2005 mask |= SDVO_OUTPUT_LVDS0;
2006 case SDVO_OUTPUT_TMDS1:
2007 mask |= SDVO_OUTPUT_TMDS1;
2008 case SDVO_OUTPUT_TMDS0:
2009 mask |= SDVO_OUTPUT_TMDS0;
2010 case SDVO_OUTPUT_RGB1:
2011 mask |= SDVO_OUTPUT_RGB1;
2012 case SDVO_OUTPUT_RGB0:
2013 mask |= SDVO_OUTPUT_RGB0;
2014 break;
2015 }
2016
2017 /* Count bits to find what number we are in the priority list. */
2018 mask &= dev_priv->caps.output_flags;
2019 num_bits = hweight16(mask);
2020 if (num_bits > 3) {
2021 /* if more than 3 outputs, default to DDC bus 3 for now */
2022 num_bits = 3;
2023 }
2024
2025 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2026 dev_priv->ddc_bus = 1 << num_bits;
2027}
2028
2029static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07002030intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002031{
2032 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
2033 uint8_t status;
2034
2035 intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
2036
2037 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2038 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
2039 if (status != SDVO_CMD_STATUS_SUCCESS)
2040 return false;
2041 return true;
2042}
2043
Eric Anholt21d40d32010-03-25 11:11:14 -07002044static struct intel_encoder *
2045intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan)
Ma Ling619ac3b2009-05-18 16:12:46 +08002046{
2047 struct drm_device *dev = chan->drm_dev;
2048 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -07002049 struct intel_encoder *intel_encoder = NULL;
Ma Ling619ac3b2009-05-18 16:12:46 +08002050
2051 list_for_each_entry(connector,
2052 &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002053 if (to_intel_encoder(connector)->ddc_bus == &chan->adapter) {
2054 intel_encoder = to_intel_encoder(connector);
Ma Ling619ac3b2009-05-18 16:12:46 +08002055 break;
2056 }
2057 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002058 return intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002059}
2060
2061static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2062 struct i2c_msg msgs[], int num)
2063{
Eric Anholt21d40d32010-03-25 11:11:14 -07002064 struct intel_encoder *intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002065 struct intel_sdvo_priv *sdvo_priv;
2066 struct i2c_algo_bit_data *algo_data;
Keith Packardf9c10a92009-05-30 12:16:25 -07002067 const struct i2c_algorithm *algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002068
2069 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
Eric Anholt21d40d32010-03-25 11:11:14 -07002070 intel_encoder =
2071 intel_sdvo_chan_to_intel_encoder(
Ma Ling619ac3b2009-05-18 16:12:46 +08002072 (struct intel_i2c_chan *)(algo_data->data));
Eric Anholt21d40d32010-03-25 11:11:14 -07002073 if (intel_encoder == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002074 return -EINVAL;
2075
Eric Anholt21d40d32010-03-25 11:11:14 -07002076 sdvo_priv = intel_encoder->dev_priv;
2077 algo = intel_encoder->i2c_bus->algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002078
Eric Anholt21d40d32010-03-25 11:11:14 -07002079 intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08002080 return algo->master_xfer(i2c_adap, msgs, num);
2081}
2082
2083static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
2084 .master_xfer = intel_sdvo_master_xfer,
2085};
2086
yakui_zhao714605e2009-05-31 17:18:07 +08002087static u8
Eric Anholtc751ce42010-03-25 11:48:48 -07002088intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
yakui_zhao714605e2009-05-31 17:18:07 +08002089{
2090 struct drm_i915_private *dev_priv = dev->dev_private;
2091 struct sdvo_device_mapping *my_mapping, *other_mapping;
2092
Eric Anholtc751ce42010-03-25 11:48:48 -07002093 if (sdvo_reg == SDVOB) {
yakui_zhao714605e2009-05-31 17:18:07 +08002094 my_mapping = &dev_priv->sdvo_mappings[0];
2095 other_mapping = &dev_priv->sdvo_mappings[1];
2096 } else {
2097 my_mapping = &dev_priv->sdvo_mappings[1];
2098 other_mapping = &dev_priv->sdvo_mappings[0];
2099 }
2100
2101 /* If the BIOS described our SDVO device, take advantage of it. */
2102 if (my_mapping->slave_addr)
2103 return my_mapping->slave_addr;
2104
2105 /* If the BIOS only described a different SDVO device, use the
2106 * address that it isn't using.
2107 */
2108 if (other_mapping->slave_addr) {
2109 if (other_mapping->slave_addr == 0x70)
2110 return 0x72;
2111 else
2112 return 0x70;
2113 }
2114
2115 /* No SDVO device info is found for another DVO port,
2116 * so use mapping assumption we had before BIOS parsing.
2117 */
Eric Anholtc751ce42010-03-25 11:48:48 -07002118 if (sdvo_reg == SDVOB)
yakui_zhao714605e2009-05-31 17:18:07 +08002119 return 0x70;
2120 else
2121 return 0x72;
2122}
2123
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002124static int intel_sdvo_bad_tv_callback(const struct dmi_system_id *id)
2125{
2126 DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id->ident);
2127 return 1;
2128}
2129
2130static struct dmi_system_id intel_sdvo_bad_tv[] = {
2131 {
2132 .callback = intel_sdvo_bad_tv_callback,
2133 .ident = "IntelG45/ICH10R/DME1737",
2134 .matches = {
2135 DMI_MATCH(DMI_SYS_VENDOR, "IBM CORPORATION"),
2136 DMI_MATCH(DMI_PRODUCT_NAME, "4800784"),
2137 },
2138 },
2139
2140 { } /* terminating entry */
2141};
2142
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002143static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07002144intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002145{
Eric Anholt21d40d32010-03-25 11:11:14 -07002146 struct drm_connector *connector = &intel_encoder->base;
2147 struct drm_encoder *encoder = &intel_encoder->enc;
2148 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002149 bool ret = true, registered = false;
2150
2151 sdvo_priv->is_tv = false;
Eric Anholt21d40d32010-03-25 11:11:14 -07002152 intel_encoder->needs_tv_clock = false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002153 sdvo_priv->is_lvds = false;
2154
2155 if (device_is_registered(&connector->kdev)) {
2156 drm_sysfs_connector_remove(connector);
2157 registered = true;
2158 }
2159
2160 if (flags &
2161 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
2162 if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0)
2163 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0;
2164 else
2165 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1;
2166
2167 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2168 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2169
Eric Anholt21d40d32010-03-25 11:11:14 -07002170 if (intel_sdvo_get_supp_encode(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002171 &sdvo_priv->encode) &&
Eric Anholt21d40d32010-03-25 11:11:14 -07002172 intel_sdvo_get_digital_encoding_mode(intel_encoder) &&
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002173 sdvo_priv->is_hdmi) {
2174 /* enable hdmi encoding mode if supported */
Eric Anholt21d40d32010-03-25 11:11:14 -07002175 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI);
2176 intel_sdvo_set_colorimetry(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002177 SDVO_COLORIMETRY_RGB256);
2178 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
Eric Anholt21d40d32010-03-25 11:11:14 -07002179 intel_encoder->clone_mask =
Ma Lingf8aed702009-08-24 13:50:24 +08002180 (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2181 (1 << INTEL_ANALOG_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002182 }
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002183 } else if ((flags & SDVO_OUTPUT_SVID0) &&
2184 !dmi_check_system(intel_sdvo_bad_tv)) {
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002185
2186 sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0;
2187 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2188 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2189 sdvo_priv->is_tv = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002190 intel_encoder->needs_tv_clock = true;
2191 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002192 } else if (flags & SDVO_OUTPUT_RGB0) {
2193
2194 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0;
2195 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2196 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
Eric Anholt21d40d32010-03-25 11:11:14 -07002197 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +08002198 (1 << INTEL_ANALOG_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002199 } else if (flags & SDVO_OUTPUT_RGB1) {
2200
2201 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1;
2202 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2203 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
Eric Anholt21d40d32010-03-25 11:11:14 -07002204 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
Zhao Yakuie2708462009-09-10 15:45:48 +08002205 (1 << INTEL_ANALOG_CLONE_BIT);
Zhao Yakui2dd87382010-01-27 16:32:46 +08002206 } else if (flags & SDVO_OUTPUT_CVBS0) {
2207
2208 sdvo_priv->controlled_output = SDVO_OUTPUT_CVBS0;
2209 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2210 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2211 sdvo_priv->is_tv = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002212 intel_encoder->needs_tv_clock = true;
2213 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002214 } else if (flags & SDVO_OUTPUT_LVDS0) {
2215
2216 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0;
2217 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2218 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2219 sdvo_priv->is_lvds = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002220 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +08002221 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002222 } else if (flags & SDVO_OUTPUT_LVDS1) {
2223
2224 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1;
2225 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2226 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2227 sdvo_priv->is_lvds = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002228 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +08002229 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002230 } else {
2231
2232 unsigned char bytes[2];
2233
2234 sdvo_priv->controlled_output = 0;
2235 memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
Dave Airlie51c8b402009-08-20 13:38:04 +10002236 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2237 SDVO_NAME(sdvo_priv),
2238 bytes[0], bytes[1]);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002239 ret = false;
2240 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002241 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002242
2243 if (ret && registered)
2244 ret = drm_sysfs_connector_add(connector) == 0 ? true : false;
2245
2246
2247 return ret;
2248
2249}
2250
Zhao Yakuice6feab2009-08-24 13:50:26 +08002251static void intel_sdvo_tv_create_property(struct drm_connector *connector)
2252{
Eric Anholt21d40d32010-03-25 11:11:14 -07002253 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
2254 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002255 struct intel_sdvo_tv_format format;
2256 uint32_t format_map, i;
2257 uint8_t status;
2258
Eric Anholt21d40d32010-03-25 11:11:14 -07002259 intel_sdvo_set_target_output(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002260 sdvo_priv->controlled_output);
2261
Eric Anholt21d40d32010-03-25 11:11:14 -07002262 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002263 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002264 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002265 &format, sizeof(format));
2266 if (status != SDVO_CMD_STATUS_SUCCESS)
2267 return;
2268
2269 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
2270 sizeof(format_map) : sizeof(format));
2271
2272 if (format_map == 0)
2273 return;
2274
2275 sdvo_priv->format_supported_num = 0;
2276 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2277 if (format_map & (1 << i)) {
2278 sdvo_priv->tv_format_supported
2279 [sdvo_priv->format_supported_num++] =
2280 tv_format_names[i];
2281 }
2282
2283
2284 sdvo_priv->tv_format_property =
2285 drm_property_create(
2286 connector->dev, DRM_MODE_PROP_ENUM,
2287 "mode", sdvo_priv->format_supported_num);
2288
2289 for (i = 0; i < sdvo_priv->format_supported_num; i++)
2290 drm_property_add_enum(
2291 sdvo_priv->tv_format_property, i,
2292 i, sdvo_priv->tv_format_supported[i]);
2293
2294 sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[0];
2295 drm_connector_attach_property(
2296 connector, sdvo_priv->tv_format_property, 0);
2297
2298}
2299
Zhao Yakuib9219c52009-09-10 15:45:46 +08002300static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2301{
Eric Anholt21d40d32010-03-25 11:11:14 -07002302 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
2303 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuib9219c52009-09-10 15:45:46 +08002304 struct intel_sdvo_enhancements_reply sdvo_data;
2305 struct drm_device *dev = connector->dev;
2306 uint8_t status;
2307 uint16_t response, data_value[2];
2308
Eric Anholt21d40d32010-03-25 11:11:14 -07002309 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002310 NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002311 status = intel_sdvo_read_response(intel_encoder, &sdvo_data,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002312 sizeof(sdvo_data));
2313 if (status != SDVO_CMD_STATUS_SUCCESS) {
2314 DRM_DEBUG_KMS(" incorrect response is returned\n");
2315 return;
2316 }
2317 response = *((uint16_t *)&sdvo_data);
2318 if (!response) {
2319 DRM_DEBUG_KMS("No enhancement is supported\n");
2320 return;
2321 }
2322 if (sdvo_priv->is_tv) {
2323 /* when horizontal overscan is supported, Add the left/right
2324 * property
2325 */
2326 if (sdvo_data.overscan_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002327 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002328 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002329 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002330 &data_value, 4);
2331 if (status != SDVO_CMD_STATUS_SUCCESS) {
2332 DRM_DEBUG_KMS("Incorrect SDVO max "
2333 "h_overscan\n");
2334 return;
2335 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002336 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002337 SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002338 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002339 &response, 2);
2340 if (status != SDVO_CMD_STATUS_SUCCESS) {
2341 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2342 return;
2343 }
2344 sdvo_priv->max_hscan = data_value[0];
2345 sdvo_priv->left_margin = data_value[0] - response;
2346 sdvo_priv->right_margin = sdvo_priv->left_margin;
2347 sdvo_priv->left_property =
2348 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2349 "left_margin", 2);
2350 sdvo_priv->left_property->values[0] = 0;
2351 sdvo_priv->left_property->values[1] = data_value[0];
2352 drm_connector_attach_property(connector,
2353 sdvo_priv->left_property,
2354 sdvo_priv->left_margin);
2355 sdvo_priv->right_property =
2356 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2357 "right_margin", 2);
2358 sdvo_priv->right_property->values[0] = 0;
2359 sdvo_priv->right_property->values[1] = data_value[0];
2360 drm_connector_attach_property(connector,
2361 sdvo_priv->right_property,
2362 sdvo_priv->right_margin);
2363 DRM_DEBUG_KMS("h_overscan: max %d, "
2364 "default %d, current %d\n",
2365 data_value[0], data_value[1], response);
2366 }
2367 if (sdvo_data.overscan_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002368 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002369 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002370 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002371 &data_value, 4);
2372 if (status != SDVO_CMD_STATUS_SUCCESS) {
2373 DRM_DEBUG_KMS("Incorrect SDVO max "
2374 "v_overscan\n");
2375 return;
2376 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002377 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002378 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002379 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002380 &response, 2);
2381 if (status != SDVO_CMD_STATUS_SUCCESS) {
2382 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2383 return;
2384 }
2385 sdvo_priv->max_vscan = data_value[0];
2386 sdvo_priv->top_margin = data_value[0] - response;
2387 sdvo_priv->bottom_margin = sdvo_priv->top_margin;
2388 sdvo_priv->top_property =
2389 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2390 "top_margin", 2);
2391 sdvo_priv->top_property->values[0] = 0;
2392 sdvo_priv->top_property->values[1] = data_value[0];
2393 drm_connector_attach_property(connector,
2394 sdvo_priv->top_property,
2395 sdvo_priv->top_margin);
2396 sdvo_priv->bottom_property =
2397 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2398 "bottom_margin", 2);
2399 sdvo_priv->bottom_property->values[0] = 0;
2400 sdvo_priv->bottom_property->values[1] = data_value[0];
2401 drm_connector_attach_property(connector,
2402 sdvo_priv->bottom_property,
2403 sdvo_priv->bottom_margin);
2404 DRM_DEBUG_KMS("v_overscan: max %d, "
2405 "default %d, current %d\n",
2406 data_value[0], data_value[1], response);
2407 }
2408 if (sdvo_data.position_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002409 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002410 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002411 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002412 &data_value, 4);
2413 if (status != SDVO_CMD_STATUS_SUCCESS) {
2414 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2415 return;
2416 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002417 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002418 SDVO_CMD_GET_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002419 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002420 &response, 2);
2421 if (status != SDVO_CMD_STATUS_SUCCESS) {
2422 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2423 return;
2424 }
2425 sdvo_priv->max_hpos = data_value[0];
2426 sdvo_priv->cur_hpos = response;
2427 sdvo_priv->hpos_property =
2428 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2429 "hpos", 2);
2430 sdvo_priv->hpos_property->values[0] = 0;
2431 sdvo_priv->hpos_property->values[1] = data_value[0];
2432 drm_connector_attach_property(connector,
2433 sdvo_priv->hpos_property,
2434 sdvo_priv->cur_hpos);
2435 DRM_DEBUG_KMS("h_position: max %d, "
2436 "default %d, current %d\n",
2437 data_value[0], data_value[1], response);
2438 }
2439 if (sdvo_data.position_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002440 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002441 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002442 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002443 &data_value, 4);
2444 if (status != SDVO_CMD_STATUS_SUCCESS) {
2445 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2446 return;
2447 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002448 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002449 SDVO_CMD_GET_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002450 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002451 &response, 2);
2452 if (status != SDVO_CMD_STATUS_SUCCESS) {
2453 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2454 return;
2455 }
2456 sdvo_priv->max_vpos = data_value[0];
2457 sdvo_priv->cur_vpos = response;
2458 sdvo_priv->vpos_property =
2459 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2460 "vpos", 2);
2461 sdvo_priv->vpos_property->values[0] = 0;
2462 sdvo_priv->vpos_property->values[1] = data_value[0];
2463 drm_connector_attach_property(connector,
2464 sdvo_priv->vpos_property,
2465 sdvo_priv->cur_vpos);
2466 DRM_DEBUG_KMS("v_position: max %d, "
2467 "default %d, current %d\n",
2468 data_value[0], data_value[1], response);
2469 }
2470 }
2471 if (sdvo_priv->is_tv) {
2472 if (sdvo_data.saturation) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002473 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002474 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002475 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002476 &data_value, 4);
2477 if (status != SDVO_CMD_STATUS_SUCCESS) {
2478 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2479 return;
2480 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002481 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002482 SDVO_CMD_GET_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002483 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002484 &response, 2);
2485 if (status != SDVO_CMD_STATUS_SUCCESS) {
2486 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2487 return;
2488 }
2489 sdvo_priv->max_saturation = data_value[0];
2490 sdvo_priv->cur_saturation = response;
2491 sdvo_priv->saturation_property =
2492 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2493 "saturation", 2);
2494 sdvo_priv->saturation_property->values[0] = 0;
2495 sdvo_priv->saturation_property->values[1] =
2496 data_value[0];
2497 drm_connector_attach_property(connector,
2498 sdvo_priv->saturation_property,
2499 sdvo_priv->cur_saturation);
2500 DRM_DEBUG_KMS("saturation: max %d, "
2501 "default %d, current %d\n",
2502 data_value[0], data_value[1], response);
2503 }
2504 if (sdvo_data.contrast) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002505 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002506 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002507 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002508 &data_value, 4);
2509 if (status != SDVO_CMD_STATUS_SUCCESS) {
2510 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2511 return;
2512 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002513 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002514 SDVO_CMD_GET_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002515 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002516 &response, 2);
2517 if (status != SDVO_CMD_STATUS_SUCCESS) {
2518 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2519 return;
2520 }
2521 sdvo_priv->max_contrast = data_value[0];
2522 sdvo_priv->cur_contrast = response;
2523 sdvo_priv->contrast_property =
2524 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2525 "contrast", 2);
2526 sdvo_priv->contrast_property->values[0] = 0;
2527 sdvo_priv->contrast_property->values[1] = data_value[0];
2528 drm_connector_attach_property(connector,
2529 sdvo_priv->contrast_property,
2530 sdvo_priv->cur_contrast);
2531 DRM_DEBUG_KMS("contrast: max %d, "
2532 "default %d, current %d\n",
2533 data_value[0], data_value[1], response);
2534 }
2535 if (sdvo_data.hue) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002536 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002537 SDVO_CMD_GET_MAX_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002538 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002539 &data_value, 4);
2540 if (status != SDVO_CMD_STATUS_SUCCESS) {
2541 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2542 return;
2543 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002544 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002545 SDVO_CMD_GET_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002546 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002547 &response, 2);
2548 if (status != SDVO_CMD_STATUS_SUCCESS) {
2549 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2550 return;
2551 }
2552 sdvo_priv->max_hue = data_value[0];
2553 sdvo_priv->cur_hue = response;
2554 sdvo_priv->hue_property =
2555 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2556 "hue", 2);
2557 sdvo_priv->hue_property->values[0] = 0;
2558 sdvo_priv->hue_property->values[1] =
2559 data_value[0];
2560 drm_connector_attach_property(connector,
2561 sdvo_priv->hue_property,
2562 sdvo_priv->cur_hue);
2563 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2564 data_value[0], data_value[1], response);
2565 }
2566 }
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002567 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002568 if (sdvo_data.brightness) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002569 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002570 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002571 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002572 &data_value, 4);
2573 if (status != SDVO_CMD_STATUS_SUCCESS) {
2574 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2575 return;
2576 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002577 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002578 SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002579 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002580 &response, 2);
2581 if (status != SDVO_CMD_STATUS_SUCCESS) {
2582 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2583 return;
2584 }
2585 sdvo_priv->max_brightness = data_value[0];
2586 sdvo_priv->cur_brightness = response;
2587 sdvo_priv->brightness_property =
2588 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2589 "brightness", 2);
2590 sdvo_priv->brightness_property->values[0] = 0;
2591 sdvo_priv->brightness_property->values[1] =
2592 data_value[0];
2593 drm_connector_attach_property(connector,
2594 sdvo_priv->brightness_property,
2595 sdvo_priv->cur_brightness);
2596 DRM_DEBUG_KMS("brightness: max %d, "
2597 "default %d, current %d\n",
2598 data_value[0], data_value[1], response);
2599 }
2600 }
2601 return;
2602}
2603
Eric Anholtc751ce42010-03-25 11:48:48 -07002604bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
Jesse Barnes79e53942008-11-07 14:24:08 -08002605{
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002606 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes79e53942008-11-07 14:24:08 -08002607 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -07002608 struct intel_encoder *intel_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -08002609 struct intel_sdvo_priv *sdvo_priv;
Keith Packardf9c10a92009-05-30 12:16:25 -07002610
Jesse Barnes79e53942008-11-07 14:24:08 -08002611 u8 ch[0x40];
2612 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -08002613
Eric Anholt21d40d32010-03-25 11:11:14 -07002614 intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
2615 if (!intel_encoder) {
Eric Anholt7d573822009-01-02 13:33:00 -08002616 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002617 }
2618
Eric Anholt21d40d32010-03-25 11:11:14 -07002619 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1);
Eric Anholtc751ce42010-03-25 11:48:48 -07002620 sdvo_priv->sdvo_reg = sdvo_reg;
Keith Packard308cd3a2009-06-14 11:56:18 -07002621
Eric Anholt21d40d32010-03-25 11:11:14 -07002622 intel_encoder->dev_priv = sdvo_priv;
2623 intel_encoder->type = INTEL_OUTPUT_SDVO;
Jesse Barnes79e53942008-11-07 14:24:08 -08002624
Jesse Barnes79e53942008-11-07 14:24:08 -08002625 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002626 if (sdvo_reg == SDVOB)
Eric Anholt21d40d32010-03-25 11:11:14 -07002627 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
Keith Packard308cd3a2009-06-14 11:56:18 -07002628 else
Eric Anholt21d40d32010-03-25 11:11:14 -07002629 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
Keith Packard308cd3a2009-06-14 11:56:18 -07002630
Eric Anholt21d40d32010-03-25 11:11:14 -07002631 if (!intel_encoder->i2c_bus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002632 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08002633
Eric Anholtc751ce42010-03-25 11:48:48 -07002634 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08002635
Keith Packard308cd3a2009-06-14 11:56:18 -07002636 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
Eric Anholt21d40d32010-03-25 11:11:14 -07002637 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
Jesse Barnes79e53942008-11-07 14:24:08 -08002638
Jesse Barnes79e53942008-11-07 14:24:08 -08002639 /* Read the regs to test if we can talk to the device */
2640 for (i = 0; i < 0x40; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002641 if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002642 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002643 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002644 goto err_i2c;
2645 }
2646 }
2647
Ma Ling619ac3b2009-05-18 16:12:46 +08002648 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002649 if (sdvo_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002650 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002651 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2652 "SDVOB/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002653 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002654 } else {
Eric Anholt21d40d32010-03-25 11:11:14 -07002655 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002656 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2657 "SDVOC/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002658 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002659 }
Ma Ling619ac3b2009-05-18 16:12:46 +08002660
Eric Anholt21d40d32010-03-25 11:11:14 -07002661 if (intel_encoder->ddc_bus == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002662 goto err_i2c;
2663
Keith Packard308cd3a2009-06-14 11:56:18 -07002664 /* Wrap with our custom algo which switches to DDC mode */
Eric Anholt21d40d32010-03-25 11:11:14 -07002665 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002666
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002667 /* In default case sdvo lvds is false */
Eric Anholt21d40d32010-03-25 11:11:14 -07002668 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps);
Jesse Barnes79e53942008-11-07 14:24:08 -08002669
Eric Anholt21d40d32010-03-25 11:11:14 -07002670 if (intel_sdvo_output_setup(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002671 sdvo_priv->caps.output_flags) != true) {
Dave Airlie51c8b402009-08-20 13:38:04 +10002672 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002673 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002674 goto err_i2c;
2675 }
2676
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002677
Eric Anholt21d40d32010-03-25 11:11:14 -07002678 connector = &intel_encoder->base;
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002679 drm_connector_init(dev, connector, &intel_sdvo_connector_funcs,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002680 connector->connector_type);
2681
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002682 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2683 connector->interlace_allowed = 0;
2684 connector->doublescan_allowed = 0;
2685 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2686
Eric Anholt21d40d32010-03-25 11:11:14 -07002687 drm_encoder_init(dev, &intel_encoder->enc,
2688 &intel_sdvo_enc_funcs, intel_encoder->enc.encoder_type);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002689
Eric Anholt21d40d32010-03-25 11:11:14 -07002690 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -08002691
Eric Anholt21d40d32010-03-25 11:11:14 -07002692 drm_mode_connector_attach_encoder(&intel_encoder->base, &intel_encoder->enc);
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002693 if (sdvo_priv->is_tv)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002694 intel_sdvo_tv_create_property(connector);
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002695
2696 if (sdvo_priv->is_tv || sdvo_priv->is_lvds)
Zhao Yakuib9219c52009-09-10 15:45:46 +08002697 intel_sdvo_create_enhance_property(connector);
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002698
Jesse Barnes79e53942008-11-07 14:24:08 -08002699 drm_sysfs_connector_add(connector);
2700
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002701 intel_sdvo_select_ddc_bus(sdvo_priv);
2702
Jesse Barnes79e53942008-11-07 14:24:08 -08002703 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholt21d40d32010-03-25 11:11:14 -07002704 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08002705
Eric Anholt21d40d32010-03-25 11:11:14 -07002706 intel_sdvo_get_input_pixel_clock_range(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002707 &sdvo_priv->pixel_clock_min,
2708 &sdvo_priv->pixel_clock_max);
2709
2710
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002711 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
yakui_zhao342dc382009-06-02 14:12:00 +08002712 "clock range %dMHz - %dMHz, "
2713 "input 1: %c, input 2: %c, "
2714 "output 1: %c, output 2: %c\n",
2715 SDVO_NAME(sdvo_priv),
2716 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
2717 sdvo_priv->caps.device_rev_id,
2718 sdvo_priv->pixel_clock_min / 1000,
2719 sdvo_priv->pixel_clock_max / 1000,
2720 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2721 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
2722 /* check currently supported outputs */
2723 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002724 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
yakui_zhao342dc382009-06-02 14:12:00 +08002725 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002726 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2727
Eric Anholt7d573822009-01-02 13:33:00 -08002728 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08002729
2730err_i2c:
Keith Packard57cdaf92009-09-04 13:07:54 +08002731 if (sdvo_priv->analog_ddc_bus != NULL)
2732 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
Eric Anholt21d40d32010-03-25 11:11:14 -07002733 if (intel_encoder->ddc_bus != NULL)
2734 intel_i2c_destroy(intel_encoder->ddc_bus);
2735 if (intel_encoder->i2c_bus != NULL)
2736 intel_i2c_destroy(intel_encoder->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002737err_inteloutput:
Eric Anholt21d40d32010-03-25 11:11:14 -07002738 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002739
Eric Anholt7d573822009-01-02 13:33:00 -08002740 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002741}