blob: 602056a88dd0601cf64e0c9cd93b59cfaf2cabc4 [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
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800159intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
160 struct intel_connector *intel_connector,
161 uint16_t flags);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800162
Jesse Barnes79e53942008-11-07 14:24:08 -0800163/**
164 * Writes the SDVOB or SDVOC with the given value, but always writes both
165 * SDVOB and SDVOC to work around apparent hardware issues (according to
166 * comments in the BIOS).
167 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700168static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800169{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800170 struct drm_device *dev = intel_encoder->enc.dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800171 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -0700172 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800173 u32 bval = val, cval = val;
174 int i;
175
Eric Anholtc751ce42010-03-25 11:48:48 -0700176 if (sdvo_priv->sdvo_reg == SDVOB) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800177 cval = I915_READ(SDVOC);
178 } else {
179 bval = I915_READ(SDVOB);
180 }
181 /*
182 * Write the registers twice for luck. Sometimes,
183 * writing them only once doesn't appear to 'stick'.
184 * The BIOS does this too. Yay, magic
185 */
186 for (i = 0; i < 2; i++)
187 {
188 I915_WRITE(SDVOB, bval);
189 I915_READ(SDVOB);
190 I915_WRITE(SDVOC, cval);
191 I915_READ(SDVOC);
192 }
193}
194
Eric Anholt21d40d32010-03-25 11:11:14 -0700195static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800196 u8 *ch)
197{
Eric Anholt21d40d32010-03-25 11:11:14 -0700198 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800199 u8 out_buf[2];
200 u8 buf[2];
201 int ret;
202
203 struct i2c_msg msgs[] = {
204 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700205 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800206 .flags = 0,
207 .len = 1,
208 .buf = out_buf,
209 },
210 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700211 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800212 .flags = I2C_M_RD,
213 .len = 1,
214 .buf = buf,
215 }
216 };
217
218 out_buf[0] = addr;
219 out_buf[1] = 0;
220
Eric Anholt21d40d32010-03-25 11:11:14 -0700221 if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800222 {
223 *ch = buf[0];
224 return true;
225 }
226
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800227 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
Jesse Barnes79e53942008-11-07 14:24:08 -0800228 return false;
229}
230
Eric Anholt21d40d32010-03-25 11:11:14 -0700231static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800232 u8 ch)
233{
Eric Anholt21d40d32010-03-25 11:11:14 -0700234 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800235 u8 out_buf[2];
236 struct i2c_msg msgs[] = {
237 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700238 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800239 .flags = 0,
240 .len = 2,
241 .buf = out_buf,
242 }
243 };
244
245 out_buf[0] = addr;
246 out_buf[1] = ch;
247
Eric Anholt21d40d32010-03-25 11:11:14 -0700248 if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800249 {
250 return true;
251 }
252 return false;
253}
254
255#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
256/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100257static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800258 u8 cmd;
259 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800260} sdvo_cmd_names[] = {
261 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
262 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
263 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
264 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
265 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
266 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
267 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
268 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
269 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
270 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
271 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
272 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
273 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
274 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
275 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
276 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
277 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
278 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
279 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
280 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
281 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
Zhao Yakuib9219c52009-09-10 15:45:46 +0800304 /* Add the op code for SDVO enhancements */
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800329 /* HDMI op code */
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800350};
351
Eric Anholtc751ce42010-03-25 11:48:48 -0700352#define SDVO_NAME(dev_priv) ((dev_priv)->sdvo_reg == SDVOB ? "SDVOB" : "SDVOC")
353#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -0800354
Eric Anholt21d40d32010-03-25 11:11:14 -0700355static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800356 void *args, int args_len)
357{
Eric Anholt21d40d32010-03-25 11:11:14 -0700358 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800359 int i;
360
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800361 DRM_DEBUG_KMS("%s: W: %02X ",
yakui_zhao342dc382009-06-02 14:12:00 +0800362 SDVO_NAME(sdvo_priv), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800363 for (i = 0; i < args_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800364 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800365 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800366 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800367 for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
368 if (cmd == sdvo_cmd_names[i].cmd) {
yakui_zhao342dc382009-06-02 14:12:00 +0800369 DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800370 break;
371 }
372 }
373 if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
yakui_zhao342dc382009-06-02 14:12:00 +0800374 DRM_LOG_KMS("(%02X)", cmd);
375 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800376}
Jesse Barnes79e53942008-11-07 14:24:08 -0800377
Eric Anholt21d40d32010-03-25 11:11:14 -0700378static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800379 void *args, int args_len)
380{
381 int i;
382
Eric Anholt21d40d32010-03-25 11:11:14 -0700383 intel_sdvo_debug_write(intel_encoder, cmd, args, args_len);
Jesse Barnes79e53942008-11-07 14:24:08 -0800384
385 for (i = 0; i < args_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700386 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i,
Jesse Barnes79e53942008-11-07 14:24:08 -0800387 ((u8*)args)[i]);
388 }
389
Eric Anholt21d40d32010-03-25 11:11:14 -0700390 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800391}
392
Jesse Barnes79e53942008-11-07 14:24:08 -0800393static const char *cmd_status_names[] = {
394 "Power on",
395 "Success",
396 "Not supported",
397 "Invalid arg",
398 "Pending",
399 "Target not specified",
400 "Scaling not supported"
401};
402
Eric Anholt21d40d32010-03-25 11:11:14 -0700403static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800404 void *response, int response_len,
405 u8 status)
406{
Eric Anholt21d40d32010-03-25 11:11:14 -0700407 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang33b52962009-03-24 14:02:40 +0800408 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800409
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800410 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -0800411 for (i = 0; i < response_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800412 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800413 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800414 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800415 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
yakui_zhao342dc382009-06-02 14:12:00 +0800416 DRM_LOG_KMS("(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800417 else
yakui_zhao342dc382009-06-02 14:12:00 +0800418 DRM_LOG_KMS("(??? %d)", status);
419 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800420}
Jesse Barnes79e53942008-11-07 14:24:08 -0800421
Eric Anholt21d40d32010-03-25 11:11:14 -0700422static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800423 void *response, int response_len)
424{
425 int i;
426 u8 status;
427 u8 retry = 50;
428
429 while (retry--) {
430 /* Read the command response */
431 for (i = 0; i < response_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700432 intel_sdvo_read_byte(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800433 SDVO_I2C_RETURN_0 + i,
434 &((u8 *)response)[i]);
435 }
436
437 /* read the return status */
Eric Anholt21d40d32010-03-25 11:11:14 -0700438 intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS,
Jesse Barnes79e53942008-11-07 14:24:08 -0800439 &status);
440
Eric Anholt21d40d32010-03-25 11:11:14 -0700441 intel_sdvo_debug_response(intel_encoder, response, response_len,
Jesse Barnes79e53942008-11-07 14:24:08 -0800442 status);
443 if (status != SDVO_CMD_STATUS_PENDING)
444 return status;
445
446 mdelay(50);
447 }
448
449 return status;
450}
451
Hannes Ederb358d0a2008-12-18 21:18:47 +0100452static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800453{
454 if (mode->clock >= 100000)
455 return 1;
456 else if (mode->clock >= 50000)
457 return 2;
458 else
459 return 4;
460}
461
462/**
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800463 * Try to read the response after issuie the DDC switch command. But it
464 * is noted that we must do the action of reading response and issuing DDC
465 * switch command in one I2C transaction. Otherwise when we try to start
466 * another I2C transaction after issuing the DDC bus switch, it will be
467 * switched to the internal SDVO register.
Jesse Barnes79e53942008-11-07 14:24:08 -0800468 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700469static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder,
Hannes Ederb358d0a2008-12-18 21:18:47 +0100470 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800471{
Eric Anholt21d40d32010-03-25 11:11:14 -0700472 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800473 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
474 struct i2c_msg msgs[] = {
475 {
476 .addr = sdvo_priv->slave_addr >> 1,
477 .flags = 0,
478 .len = 2,
479 .buf = out_buf,
480 },
481 /* the following two are to read the response */
482 {
483 .addr = sdvo_priv->slave_addr >> 1,
484 .flags = 0,
485 .len = 1,
486 .buf = cmd_buf,
487 },
488 {
489 .addr = sdvo_priv->slave_addr >> 1,
490 .flags = I2C_M_RD,
491 .len = 1,
492 .buf = ret_value,
493 },
494 };
495
Eric Anholt21d40d32010-03-25 11:11:14 -0700496 intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800497 &target, 1);
498 /* write the DDC switch command argument */
Eric Anholt21d40d32010-03-25 11:11:14 -0700499 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800500
501 out_buf[0] = SDVO_I2C_OPCODE;
502 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
503 cmd_buf[0] = SDVO_I2C_CMD_STATUS;
504 cmd_buf[1] = 0;
505 ret_value[0] = 0;
506 ret_value[1] = 0;
507
Eric Anholt21d40d32010-03-25 11:11:14 -0700508 ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800509 if (ret != 3) {
510 /* failure in I2C transfer */
511 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
512 return;
513 }
514 if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
515 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
516 ret_value[0]);
517 return;
518 }
519 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800520}
521
Eric Anholt21d40d32010-03-25 11:11:14 -0700522static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800523{
524 struct intel_sdvo_set_target_input_args targets = {0};
525 u8 status;
526
527 if (target_0 && target_1)
528 return SDVO_CMD_STATUS_NOTSUPP;
529
530 if (target_1)
531 targets.target_1 = 1;
532
Eric Anholt21d40d32010-03-25 11:11:14 -0700533 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets,
Jesse Barnes79e53942008-11-07 14:24:08 -0800534 sizeof(targets));
535
Eric Anholt21d40d32010-03-25 11:11:14 -0700536 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800537
538 return (status == SDVO_CMD_STATUS_SUCCESS);
539}
540
541/**
542 * Return whether each input is trained.
543 *
544 * This function is making an assumption about the layout of the response,
545 * which should be checked against the docs.
546 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700547static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800548{
549 struct intel_sdvo_get_trained_inputs_response response;
550 u8 status;
551
Eric Anholt21d40d32010-03-25 11:11:14 -0700552 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
553 status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response));
Jesse Barnes79e53942008-11-07 14:24:08 -0800554 if (status != SDVO_CMD_STATUS_SUCCESS)
555 return false;
556
557 *input_1 = response.input0_trained;
558 *input_2 = response.input1_trained;
559 return true;
560}
561
Eric Anholt21d40d32010-03-25 11:11:14 -0700562static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800563 u16 outputs)
564{
565 u8 status;
566
Eric Anholt21d40d32010-03-25 11:11:14 -0700567 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800568 sizeof(outputs));
Eric Anholt21d40d32010-03-25 11:11:14 -0700569 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800570 return (status == SDVO_CMD_STATUS_SUCCESS);
571}
572
Eric Anholt21d40d32010-03-25 11:11:14 -0700573static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800574 int mode)
575{
576 u8 status, state = SDVO_ENCODER_STATE_ON;
577
578 switch (mode) {
579 case DRM_MODE_DPMS_ON:
580 state = SDVO_ENCODER_STATE_ON;
581 break;
582 case DRM_MODE_DPMS_STANDBY:
583 state = SDVO_ENCODER_STATE_STANDBY;
584 break;
585 case DRM_MODE_DPMS_SUSPEND:
586 state = SDVO_ENCODER_STATE_SUSPEND;
587 break;
588 case DRM_MODE_DPMS_OFF:
589 state = SDVO_ENCODER_STATE_OFF;
590 break;
591 }
592
Eric Anholt21d40d32010-03-25 11:11:14 -0700593 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
Jesse Barnes79e53942008-11-07 14:24:08 -0800594 sizeof(state));
Eric Anholt21d40d32010-03-25 11:11:14 -0700595 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800596
597 return (status == SDVO_CMD_STATUS_SUCCESS);
598}
599
Eric Anholt21d40d32010-03-25 11:11:14 -0700600static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800601 int *clock_min,
602 int *clock_max)
603{
604 struct intel_sdvo_pixel_clock_range clocks;
605 u8 status;
606
Eric Anholt21d40d32010-03-25 11:11:14 -0700607 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
Jesse Barnes79e53942008-11-07 14:24:08 -0800608 NULL, 0);
609
Eric Anholt21d40d32010-03-25 11:11:14 -0700610 status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks));
Jesse Barnes79e53942008-11-07 14:24:08 -0800611
612 if (status != SDVO_CMD_STATUS_SUCCESS)
613 return false;
614
615 /* Convert the values from units of 10 kHz to kHz. */
616 *clock_min = clocks.min * 10;
617 *clock_max = clocks.max * 10;
618
619 return true;
620}
621
Eric Anholt21d40d32010-03-25 11:11:14 -0700622static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800623 u16 outputs)
624{
625 u8 status;
626
Eric Anholt21d40d32010-03-25 11:11:14 -0700627 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800628 sizeof(outputs));
629
Eric Anholt21d40d32010-03-25 11:11:14 -0700630 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800631 return (status == SDVO_CMD_STATUS_SUCCESS);
632}
633
Eric Anholt21d40d32010-03-25 11:11:14 -0700634static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800635 struct intel_sdvo_dtd *dtd)
636{
637 u8 status;
638
Eric Anholt21d40d32010-03-25 11:11:14 -0700639 intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1));
640 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800641 if (status != SDVO_CMD_STATUS_SUCCESS)
642 return false;
643
Eric Anholt21d40d32010-03-25 11:11:14 -0700644 intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2));
645 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800646 if (status != SDVO_CMD_STATUS_SUCCESS)
647 return false;
648
649 return true;
650}
651
Eric Anholt21d40d32010-03-25 11:11:14 -0700652static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800653 struct intel_sdvo_dtd *dtd)
654{
Eric Anholt21d40d32010-03-25 11:11:14 -0700655 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800656 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
657}
658
Eric Anholt21d40d32010-03-25 11:11:14 -0700659static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800660 struct intel_sdvo_dtd *dtd)
661{
Eric Anholt21d40d32010-03-25 11:11:14 -0700662 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800663 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
664}
665
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800666static bool
Eric Anholtc751ce42010-03-25 11:48:48 -0700667intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800668 uint16_t clock,
669 uint16_t width,
670 uint16_t height)
671{
672 struct intel_sdvo_preferred_input_timing_args args;
Eric Anholtc751ce42010-03-25 11:48:48 -0700673 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800674 uint8_t status;
675
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800676 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800677 args.clock = clock;
678 args.width = width;
679 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800680 args.interlace = 0;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800681
682 if (sdvo_priv->is_lvds &&
683 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
684 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
685 args.scaled = 1;
686
Eric Anholtc751ce42010-03-25 11:48:48 -0700687 intel_sdvo_write_cmd(intel_encoder,
688 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800689 &args, sizeof(args));
Eric Anholtc751ce42010-03-25 11:48:48 -0700690 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800691 if (status != SDVO_CMD_STATUS_SUCCESS)
692 return false;
693
694 return true;
695}
696
Eric Anholtc751ce42010-03-25 11:48:48 -0700697static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800698 struct intel_sdvo_dtd *dtd)
699{
700 bool status;
701
Eric Anholtc751ce42010-03-25 11:48:48 -0700702 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800703 NULL, 0);
704
Eric Anholtc751ce42010-03-25 11:48:48 -0700705 status = intel_sdvo_read_response(intel_encoder, &dtd->part1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800706 sizeof(dtd->part1));
707 if (status != SDVO_CMD_STATUS_SUCCESS)
708 return false;
709
Eric Anholtc751ce42010-03-25 11:48:48 -0700710 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800711 NULL, 0);
712
Eric Anholtc751ce42010-03-25 11:48:48 -0700713 status = intel_sdvo_read_response(intel_encoder, &dtd->part2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800714 sizeof(dtd->part2));
715 if (status != SDVO_CMD_STATUS_SUCCESS)
716 return false;
717
718 return false;
719}
Jesse Barnes79e53942008-11-07 14:24:08 -0800720
Eric Anholt21d40d32010-03-25 11:11:14 -0700721static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800722{
723 u8 status;
724
Eric Anholt21d40d32010-03-25 11:11:14 -0700725 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
726 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800727 if (status != SDVO_CMD_STATUS_SUCCESS)
728 return false;
729
730 return true;
731}
732
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800733static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
734 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800735{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800736 uint16_t width, height;
737 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
738 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800739
740 width = mode->crtc_hdisplay;
741 height = mode->crtc_vdisplay;
742
743 /* do some mode translations */
744 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
745 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
746
747 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
748 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
749
750 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
751 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
752
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800753 dtd->part1.clock = mode->clock / 10;
754 dtd->part1.h_active = width & 0xff;
755 dtd->part1.h_blank = h_blank_len & 0xff;
756 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800757 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800758 dtd->part1.v_active = height & 0xff;
759 dtd->part1.v_blank = v_blank_len & 0xff;
760 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800761 ((v_blank_len >> 8) & 0xf);
762
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800763 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800764 dtd->part2.h_sync_width = h_sync_len & 0xff;
765 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800766 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800767 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800768 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
769 ((v_sync_len & 0x30) >> 4);
770
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800771 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800772 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800773 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800774 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800775 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800776
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800777 dtd->part2.sdvo_flags = 0;
778 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
779 dtd->part2.reserved = 0;
780}
Jesse Barnes79e53942008-11-07 14:24:08 -0800781
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800782static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
783 struct intel_sdvo_dtd *dtd)
784{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800785 mode->hdisplay = dtd->part1.h_active;
786 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
787 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800788 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800789 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
790 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
791 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
792 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
793
794 mode->vdisplay = dtd->part1.v_active;
795 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
796 mode->vsync_start = mode->vdisplay;
797 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800798 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800799 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
800 mode->vsync_end = mode->vsync_start +
801 (dtd->part2.v_sync_off_width & 0xf);
802 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
803 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
804 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
805
806 mode->clock = dtd->part1.clock * 10;
807
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800808 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800809 if (dtd->part2.dtd_flags & 0x2)
810 mode->flags |= DRM_MODE_FLAG_PHSYNC;
811 if (dtd->part2.dtd_flags & 0x4)
812 mode->flags |= DRM_MODE_FLAG_PVSYNC;
813}
814
Eric Anholtc751ce42010-03-25 11:48:48 -0700815static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800816 struct intel_sdvo_encode *encode)
817{
818 uint8_t status;
819
Eric Anholtc751ce42010-03-25 11:48:48 -0700820 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
821 status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800822 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
823 memset(encode, 0, sizeof(*encode));
824 return false;
825 }
826
827 return true;
828}
829
Eric Anholtc751ce42010-03-25 11:48:48 -0700830static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder,
831 uint8_t mode)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800832{
833 uint8_t status;
834
Eric Anholtc751ce42010-03-25 11:48:48 -0700835 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1);
836 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800837
838 return (status == SDVO_CMD_STATUS_SUCCESS);
839}
840
Eric Anholtc751ce42010-03-25 11:48:48 -0700841static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800842 uint8_t mode)
843{
844 uint8_t status;
845
Eric Anholtc751ce42010-03-25 11:48:48 -0700846 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
847 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800848
849 return (status == SDVO_CMD_STATUS_SUCCESS);
850}
851
852#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -0700853static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800854{
855 int i, j;
856 uint8_t set_buf_index[2];
857 uint8_t av_split;
858 uint8_t buf_size;
859 uint8_t buf[48];
860 uint8_t *pos;
861
Eric Anholtc751ce42010-03-25 11:48:48 -0700862 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
863 intel_sdvo_read_response(encoder, &av_split, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800864
865 for (i = 0; i <= av_split; i++) {
866 set_buf_index[0] = i; set_buf_index[1] = 0;
Eric Anholtc751ce42010-03-25 11:48:48 -0700867 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800868 set_buf_index, 2);
Eric Anholtc751ce42010-03-25 11:48:48 -0700869 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
870 intel_sdvo_read_response(encoder, &buf_size, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800871
872 pos = buf;
873 for (j = 0; j <= buf_size; j += 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700874 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800875 NULL, 0);
Eric Anholtc751ce42010-03-25 11:48:48 -0700876 intel_sdvo_read_response(encoder, pos, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800877 pos += 8;
878 }
879 }
880}
881#endif
882
Eric Anholtc751ce42010-03-25 11:48:48 -0700883static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder,
884 int index,
885 uint8_t *data, int8_t size, uint8_t tx_rate)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800886{
887 uint8_t set_buf_index[2];
888
889 set_buf_index[0] = index;
890 set_buf_index[1] = 0;
891
Eric Anholtc751ce42010-03-25 11:48:48 -0700892 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX,
893 set_buf_index, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800894
895 for (; size > 0; size -= 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700896 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800897 data += 8;
898 }
899
Eric Anholtc751ce42010-03-25 11:48:48 -0700900 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800901}
902
903static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
904{
905 uint8_t csum = 0;
906 int i;
907
908 for (i = 0; i < size; i++)
909 csum += data[i];
910
911 return 0x100 - csum;
912}
913
914#define DIP_TYPE_AVI 0x82
915#define DIP_VERSION_AVI 0x2
916#define DIP_LEN_AVI 13
917
918struct dip_infoframe {
919 uint8_t type;
920 uint8_t version;
921 uint8_t len;
922 uint8_t checksum;
923 union {
924 struct {
925 /* Packet Byte #1 */
926 uint8_t S:2;
927 uint8_t B:2;
928 uint8_t A:1;
929 uint8_t Y:2;
930 uint8_t rsvd1:1;
931 /* Packet Byte #2 */
932 uint8_t R:4;
933 uint8_t M:2;
934 uint8_t C:2;
935 /* Packet Byte #3 */
936 uint8_t SC:2;
937 uint8_t Q:2;
938 uint8_t EC:3;
939 uint8_t ITC:1;
940 /* Packet Byte #4 */
941 uint8_t VIC:7;
942 uint8_t rsvd2:1;
943 /* Packet Byte #5 */
944 uint8_t PR:4;
945 uint8_t rsvd3:4;
946 /* Packet Byte #6~13 */
947 uint16_t top_bar_end;
948 uint16_t bottom_bar_start;
949 uint16_t left_bar_end;
950 uint16_t right_bar_start;
951 } avi;
952 struct {
953 /* Packet Byte #1 */
954 uint8_t channel_count:3;
955 uint8_t rsvd1:1;
956 uint8_t coding_type:4;
957 /* Packet Byte #2 */
958 uint8_t sample_size:2; /* SS0, SS1 */
959 uint8_t sample_frequency:3;
960 uint8_t rsvd2:3;
961 /* Packet Byte #3 */
962 uint8_t coding_type_private:5;
963 uint8_t rsvd3:3;
964 /* Packet Byte #4 */
965 uint8_t channel_allocation;
966 /* Packet Byte #5 */
967 uint8_t rsvd4:3;
968 uint8_t level_shift:4;
969 uint8_t downmix_inhibit:1;
970 } audio;
971 uint8_t payload[28];
972 } __attribute__ ((packed)) u;
973} __attribute__((packed));
974
Eric Anholtc751ce42010-03-25 11:48:48 -0700975static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800976 struct drm_display_mode * mode)
977{
978 struct dip_infoframe avi_if = {
979 .type = DIP_TYPE_AVI,
980 .version = DIP_VERSION_AVI,
981 .len = DIP_LEN_AVI,
982 };
983
984 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
985 4 + avi_if.len);
Eric Anholtc751ce42010-03-25 11:48:48 -0700986 intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if,
987 4 + avi_if.len,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800988 SDVO_HBUF_TX_VSYNC);
989}
990
Eric Anholtc751ce42010-03-25 11:48:48 -0700991static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +0800992{
Zhenyu Wang7026d4a2009-03-24 14:02:43 +0800993
Zhao Yakuice6feab2009-08-24 13:50:26 +0800994 struct intel_sdvo_tv_format format;
Eric Anholtc751ce42010-03-25 11:48:48 -0700995 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +0800996 uint32_t format_map, i;
997 uint8_t status;
998
999 for (i = 0; i < TV_FORMAT_NUM; i++)
1000 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1001 break;
1002
1003 format_map = 1 << i;
1004 memset(&format, 0, sizeof(format));
1005 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
1006 sizeof(format) : sizeof(format_map));
1007
Eric Anholtc751ce42010-03-25 11:48:48 -07001008 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format_map,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001009 sizeof(format));
1010
Eric Anholtc751ce42010-03-25 11:48:48 -07001011 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001012 if (status != SDVO_CMD_STATUS_SUCCESS)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001013 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
Zhao Yakuice6feab2009-08-24 13:50:26 +08001014 SDVO_NAME(sdvo_priv));
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001015}
1016
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001017static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1018 struct drm_display_mode *mode,
1019 struct drm_display_mode *adjusted_mode)
1020{
Eric Anholtc751ce42010-03-25 11:48:48 -07001021 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1022 struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001023
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001024 if (dev_priv->is_tv) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001025 struct intel_sdvo_dtd output_dtd;
1026 bool success;
1027
1028 /* We need to construct preferred input timings based on our
1029 * output timings. To do that, we have to set the output
1030 * timings, even though this isn't really the right place in
1031 * the sequence to do it. Oh well.
1032 */
1033
1034
1035 /* Set output timings */
1036 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
Eric Anholtc751ce42010-03-25 11:48:48 -07001037 intel_sdvo_set_target_output(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001038 dev_priv->controlled_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001039 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001040
1041 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001042 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001043
1044
Eric Anholtc751ce42010-03-25 11:48:48 -07001045 success = intel_sdvo_create_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001046 mode->clock / 10,
1047 mode->hdisplay,
1048 mode->vdisplay);
1049 if (success) {
1050 struct intel_sdvo_dtd input_dtd;
1051
Eric Anholtc751ce42010-03-25 11:48:48 -07001052 intel_sdvo_get_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001053 &input_dtd);
1054 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001055 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001056
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001057 drm_mode_set_crtcinfo(adjusted_mode, 0);
1058
1059 mode->clock = adjusted_mode->clock;
1060
1061 adjusted_mode->clock *=
1062 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001063 } else {
1064 return false;
1065 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001066 } else if (dev_priv->is_lvds) {
1067 struct intel_sdvo_dtd output_dtd;
1068 bool success;
1069
1070 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1071 /* Set output timings */
1072 intel_sdvo_get_dtd_from_mode(&output_dtd,
1073 dev_priv->sdvo_lvds_fixed_mode);
1074
Eric Anholtc751ce42010-03-25 11:48:48 -07001075 intel_sdvo_set_target_output(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001076 dev_priv->controlled_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001077 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001078
1079 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001080 intel_sdvo_set_target_input(intel_encoder, true, false);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001081
1082
1083 success = intel_sdvo_create_preferred_input_timing(
Eric Anholtc751ce42010-03-25 11:48:48 -07001084 intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001085 mode->clock / 10,
1086 mode->hdisplay,
1087 mode->vdisplay);
1088
1089 if (success) {
1090 struct intel_sdvo_dtd input_dtd;
1091
Eric Anholtc751ce42010-03-25 11:48:48 -07001092 intel_sdvo_get_preferred_input_timing(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001093 &input_dtd);
1094 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1095 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1096
1097 drm_mode_set_crtcinfo(adjusted_mode, 0);
1098
1099 mode->clock = adjusted_mode->clock;
1100
1101 adjusted_mode->clock *=
1102 intel_sdvo_get_pixel_multiplier(mode);
1103 } else {
1104 return false;
1105 }
1106
1107 } else {
1108 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1109 * SDVO device will be told of the multiplier during mode_set.
1110 */
1111 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001112 }
1113 return true;
1114}
1115
1116static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1117 struct drm_display_mode *mode,
1118 struct drm_display_mode *adjusted_mode)
1119{
1120 struct drm_device *dev = encoder->dev;
1121 struct drm_i915_private *dev_priv = dev->dev_private;
1122 struct drm_crtc *crtc = encoder->crtc;
1123 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Eric Anholtc751ce42010-03-25 11:48:48 -07001124 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1125 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001126 u32 sdvox = 0;
1127 int sdvo_pixel_multiply;
1128 struct intel_sdvo_in_out_map in_out;
1129 struct intel_sdvo_dtd input_dtd;
1130 u8 status;
1131
1132 if (!mode)
1133 return;
1134
1135 /* First, set the input mapping for the first input to our controlled
1136 * output. This is only correct if we're a single-input device, in
1137 * which case the first input is the output from the appropriate SDVO
1138 * channel on the motherboard. In a two-input device, the first input
1139 * will be SDVOB and the second SDVOC.
1140 */
1141 in_out.in0 = sdvo_priv->controlled_output;
1142 in_out.in1 = 0;
1143
Eric Anholtc751ce42010-03-25 11:48:48 -07001144 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001145 &in_out, sizeof(in_out));
Eric Anholtc751ce42010-03-25 11:48:48 -07001146 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001147
1148 if (sdvo_priv->is_hdmi) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001149 intel_sdvo_set_avi_infoframe(intel_encoder, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001150 sdvox |= SDVO_AUDIO_ENABLE;
1151 }
1152
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001153 /* We have tried to get input timing in mode_fixup, and filled into
1154 adjusted_mode */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001155 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001156 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001157 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
1158 } else
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001159 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001160
1161 /* If it's a TV, we already set the output timing in mode_fixup.
1162 * Otherwise, the output timing is equal to the input timing.
1163 */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001164 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001165 /* Set the output timing to the screen */
Eric Anholtc751ce42010-03-25 11:48:48 -07001166 intel_sdvo_set_target_output(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001167 sdvo_priv->controlled_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001168 intel_sdvo_set_output_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001169 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001170
1171 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001172 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001173
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001174 if (sdvo_priv->is_tv)
Eric Anholtc751ce42010-03-25 11:48:48 -07001175 intel_sdvo_set_tv_format(intel_encoder);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001176
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001177 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001178 * provide the device with a timing it can support, if it supports that
1179 * feature. However, presumably we would need to adjust the CRTC to
1180 * output the preferred timing, and we don't support that currently.
1181 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001182#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -07001183 success = intel_sdvo_create_preferred_input_timing(encoder, clock,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001184 width, height);
1185 if (success) {
1186 struct intel_sdvo_dtd *input_dtd;
1187
Eric Anholtc751ce42010-03-25 11:48:48 -07001188 intel_sdvo_get_preferred_input_timing(encoder, &input_dtd);
1189 intel_sdvo_set_input_timing(encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001190 }
1191#else
Eric Anholtc751ce42010-03-25 11:48:48 -07001192 intel_sdvo_set_input_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001193#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001194
1195 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1196 case 1:
Eric Anholtc751ce42010-03-25 11:48:48 -07001197 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001198 SDVO_CLOCK_RATE_MULT_1X);
1199 break;
1200 case 2:
Eric Anholtc751ce42010-03-25 11:48:48 -07001201 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001202 SDVO_CLOCK_RATE_MULT_2X);
1203 break;
1204 case 4:
Eric Anholtc751ce42010-03-25 11:48:48 -07001205 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001206 SDVO_CLOCK_RATE_MULT_4X);
1207 break;
1208 }
1209
1210 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001211 if (IS_I965G(dev)) {
1212 sdvox |= SDVO_BORDER_ENABLE |
1213 SDVO_VSYNC_ACTIVE_HIGH |
1214 SDVO_HSYNC_ACTIVE_HIGH;
1215 } else {
Eric Anholtc751ce42010-03-25 11:48:48 -07001216 sdvox |= I915_READ(sdvo_priv->sdvo_reg);
1217 switch (sdvo_priv->sdvo_reg) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001218 case SDVOB:
1219 sdvox &= SDVOB_PRESERVE_MASK;
1220 break;
1221 case SDVOC:
1222 sdvox &= SDVOC_PRESERVE_MASK;
1223 break;
1224 }
1225 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1226 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001227 if (intel_crtc->pipe == 1)
1228 sdvox |= SDVO_PIPE_B_SELECT;
1229
1230 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1231 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001232 /* done in crtc_mode_set as the dpll_md reg must be written early */
1233 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1234 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001235 } else {
1236 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1237 }
1238
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001239 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
1240 sdvox |= SDVO_STALL_SELECT;
Eric Anholtc751ce42010-03-25 11:48:48 -07001241 intel_sdvo_write_sdvox(intel_encoder, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001242}
1243
1244static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1245{
1246 struct drm_device *dev = encoder->dev;
1247 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001248 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1249 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001250 u32 temp;
1251
1252 if (mode != DRM_MODE_DPMS_ON) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001253 intel_sdvo_set_active_outputs(intel_encoder, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -08001254 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001255 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -08001256
1257 if (mode == DRM_MODE_DPMS_OFF) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001258 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001259 if ((temp & SDVO_ENABLE) != 0) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001260 intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001261 }
1262 }
1263 } else {
1264 bool input1, input2;
1265 int i;
1266 u8 status;
1267
Eric Anholtc751ce42010-03-25 11:48:48 -07001268 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001269 if ((temp & SDVO_ENABLE) == 0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001270 intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001271 for (i = 0; i < 2; i++)
1272 intel_wait_for_vblank(dev);
1273
Eric Anholt21d40d32010-03-25 11:11:14 -07001274 status = intel_sdvo_get_trained_inputs(intel_encoder, &input1,
Jesse Barnes79e53942008-11-07 14:24:08 -08001275 &input2);
1276
1277
1278 /* Warn if the device reported failure to sync.
1279 * A lot of SDVO devices fail to notify of sync, but it's
1280 * a given it the status is a success, we succeeded.
1281 */
1282 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001283 DRM_DEBUG_KMS("First %s output reported failure to "
1284 "sync\n", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -08001285 }
1286
1287 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001288 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
1289 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->controlled_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001290 }
1291 return;
1292}
1293
Jesse Barnes79e53942008-11-07 14:24:08 -08001294static int intel_sdvo_mode_valid(struct drm_connector *connector,
1295 struct drm_display_mode *mode)
1296{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001297 struct drm_encoder *encoder = intel_attached_encoder(connector);
1298 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001299 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001300
1301 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1302 return MODE_NO_DBLESCAN;
1303
1304 if (sdvo_priv->pixel_clock_min > mode->clock)
1305 return MODE_CLOCK_LOW;
1306
1307 if (sdvo_priv->pixel_clock_max < mode->clock)
1308 return MODE_CLOCK_HIGH;
1309
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001310 if (sdvo_priv->is_lvds == true) {
1311 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
1312 return MODE_PANEL;
1313
1314 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
1315 return MODE_PANEL;
1316
1317 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1318 return MODE_PANEL;
1319 }
1320
Jesse Barnes79e53942008-11-07 14:24:08 -08001321 return MODE_OK;
1322}
1323
Eric Anholt21d40d32010-03-25 11:11:14 -07001324static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps)
Jesse Barnes79e53942008-11-07 14:24:08 -08001325{
1326 u8 status;
1327
Eric Anholt21d40d32010-03-25 11:11:14 -07001328 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1329 status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps));
Jesse Barnes79e53942008-11-07 14:24:08 -08001330 if (status != SDVO_CMD_STATUS_SUCCESS)
1331 return false;
1332
1333 return true;
1334}
1335
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001336/* No use! */
1337#if 0
Jesse Barnes79e53942008-11-07 14:24:08 -08001338struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1339{
1340 struct drm_connector *connector = NULL;
Eric Anholt21d40d32010-03-25 11:11:14 -07001341 struct intel_encoder *iout = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001342 struct intel_sdvo_priv *sdvo;
1343
1344 /* find the sdvo connector */
1345 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001346 iout = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001347
1348 if (iout->type != INTEL_OUTPUT_SDVO)
1349 continue;
1350
1351 sdvo = iout->dev_priv;
1352
Eric Anholtc751ce42010-03-25 11:48:48 -07001353 if (sdvo->sdvo_reg == SDVOB && sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001354 return connector;
1355
Eric Anholtc751ce42010-03-25 11:48:48 -07001356 if (sdvo->sdvo_reg == SDVOC && !sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001357 return connector;
1358
1359 }
1360
1361 return NULL;
1362}
1363
1364int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1365{
1366 u8 response[2];
1367 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001368 struct intel_encoder *intel_encoder;
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001369 DRM_DEBUG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -08001370
1371 if (!connector)
1372 return 0;
1373
Eric Anholt21d40d32010-03-25 11:11:14 -07001374 intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001375
Eric Anholt21d40d32010-03-25 11:11:14 -07001376 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1377 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001378
1379 if (response[0] !=0)
1380 return 1;
1381
1382 return 0;
1383}
1384
1385void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1386{
1387 u8 response[2];
1388 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001389 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001390
Eric Anholt21d40d32010-03-25 11:11:14 -07001391 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1392 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001393
1394 if (on) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001395 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1396 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001397
Eric Anholt21d40d32010-03-25 11:11:14 -07001398 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001399 } else {
1400 response[0] = 0;
1401 response[1] = 0;
Eric Anholt21d40d32010-03-25 11:11:14 -07001402 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001403 }
1404
Eric Anholt21d40d32010-03-25 11:11:14 -07001405 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1406 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001407}
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001408#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001409
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001410static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07001411intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001412{
Eric Anholt21d40d32010-03-25 11:11:14 -07001413 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001414 int caps = 0;
1415
1416 if (sdvo_priv->caps.output_flags &
1417 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1418 caps++;
1419 if (sdvo_priv->caps.output_flags &
1420 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1421 caps++;
1422 if (sdvo_priv->caps.output_flags &
Roel Kluin19e1f882009-08-09 13:50:53 +02001423 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001424 caps++;
1425 if (sdvo_priv->caps.output_flags &
1426 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1427 caps++;
1428 if (sdvo_priv->caps.output_flags &
1429 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1430 caps++;
1431
1432 if (sdvo_priv->caps.output_flags &
1433 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1434 caps++;
1435
1436 if (sdvo_priv->caps.output_flags &
1437 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1438 caps++;
1439
1440 return (caps > 1);
1441}
1442
Keith Packard57cdaf92009-09-04 13:07:54 +08001443static struct drm_connector *
1444intel_find_analog_connector(struct drm_device *dev)
1445{
1446 struct drm_connector *connector;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001447 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07001448 struct intel_encoder *intel_encoder;
Keith Packard57cdaf92009-09-04 13:07:54 +08001449
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001450 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1451 intel_encoder = enc_to_intel_encoder(encoder);
1452 if (intel_encoder->type == INTEL_OUTPUT_ANALOG) {
1453 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1454 if (connector && encoder == intel_attached_encoder(connector))
1455 return connector;
1456 }
1457 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001458 }
1459 return NULL;
1460}
1461
1462static int
1463intel_analog_is_connected(struct drm_device *dev)
1464{
1465 struct drm_connector *analog_connector;
1466 analog_connector = intel_find_analog_connector(dev);
1467
1468 if (!analog_connector)
1469 return false;
1470
1471 if (analog_connector->funcs->detect(analog_connector) ==
1472 connector_status_disconnected)
1473 return false;
1474
1475 return true;
1476}
1477
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001478enum drm_connector_status
1479intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
Ma Ling9dff6af2009-04-02 13:13:26 +08001480{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001481 struct drm_encoder *encoder = intel_attached_encoder(connector);
1482 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001483 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001484 enum drm_connector_status status = connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001485 struct edid *edid = NULL;
1486
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001487 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001488 intel_encoder->ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001489
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001490 /* This is only applied to SDVO cards with multiple outputs */
Eric Anholt21d40d32010-03-25 11:11:14 -07001491 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) {
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001492 uint8_t saved_ddc, temp_ddc;
1493 saved_ddc = sdvo_priv->ddc_bus;
1494 temp_ddc = sdvo_priv->ddc_bus >> 1;
1495 /*
1496 * Don't use the 1 as the argument of DDC bus switch to get
1497 * the EDID. It is used for SDVO SPD ROM.
1498 */
1499 while(temp_ddc > 1) {
1500 sdvo_priv->ddc_bus = temp_ddc;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001501 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001502 intel_encoder->ddc_bus);
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001503 if (edid) {
1504 /*
1505 * When we can get the EDID, maybe it is the
1506 * correct DDC bus. Update it.
1507 */
1508 sdvo_priv->ddc_bus = temp_ddc;
1509 break;
1510 }
1511 temp_ddc >>= 1;
1512 }
1513 if (edid == NULL)
1514 sdvo_priv->ddc_bus = saved_ddc;
1515 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001516 /* when there is no edid and no monitor is connected with VGA
1517 * port, try to use the CRT ddc to read the EDID for DVI-connector
1518 */
1519 if (edid == NULL &&
1520 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001521 !intel_analog_is_connected(connector->dev))
1522 edid = drm_get_edid(connector,
Keith Packard57cdaf92009-09-04 13:07:54 +08001523 sdvo_priv->analog_ddc_bus);
Ma Ling9dff6af2009-04-02 13:13:26 +08001524 if (edid != NULL) {
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001525 /* Don't report the output as connected if it's a DVI-I
1526 * connector with a non-digital EDID coming out.
1527 */
1528 if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
1529 if (edid->input & DRM_EDID_INPUT_DIGITAL)
1530 sdvo_priv->is_hdmi =
1531 drm_detect_hdmi_monitor(edid);
1532 else
1533 status = connector_status_disconnected;
1534 }
1535
Ma Ling9dff6af2009-04-02 13:13:26 +08001536 kfree(edid);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001537 connector->display_info.raw_edid = NULL;
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001538
1539 } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1540 status = connector_status_disconnected;
1541
1542 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +08001543}
1544
Jesse Barnes79e53942008-11-07 14:24:08 -08001545static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1546{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001547 uint16_t response;
Jesse Barnes79e53942008-11-07 14:24:08 -08001548 u8 status;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001549 struct drm_encoder *encoder = intel_attached_encoder(connector);
1550 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1551 struct intel_connector *intel_connector = to_intel_connector(connector);
Eric Anholt21d40d32010-03-25 11:11:14 -07001552 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001553
Eric Anholt21d40d32010-03-25 11:11:14 -07001554 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001555 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
Zhao Yakuid09c23d2009-11-06 15:39:56 +08001556 if (sdvo_priv->is_tv) {
1557 /* add 30ms delay when the output type is SDVO-TV */
1558 mdelay(30);
1559 }
Eric Anholt21d40d32010-03-25 11:11:14 -07001560 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001561
Dave Airlie51c8b402009-08-20 13:38:04 +10001562 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001563
1564 if (status != SDVO_CMD_STATUS_SUCCESS)
1565 return connector_status_unknown;
1566
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001567 if (response == 0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001568 return connector_status_disconnected;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001569
Eric Anholt21d40d32010-03-25 11:11:14 -07001570 if (intel_sdvo_multifunc_encoder(intel_encoder) &&
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001571 sdvo_priv->attached_output != response) {
1572 if (sdvo_priv->controlled_output != response &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001573 intel_sdvo_output_setup(intel_encoder, intel_connector,
1574 response) != true)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001575 return connector_status_unknown;
1576 sdvo_priv->attached_output = response;
1577 }
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001578 return intel_sdvo_hdmi_sink_detect(connector, response);
Jesse Barnes79e53942008-11-07 14:24:08 -08001579}
1580
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001581static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001582{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001583 struct drm_encoder *encoder = intel_attached_encoder(connector);
1584 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001585 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Keith Packard57cdaf92009-09-04 13:07:54 +08001586 int num_modes;
Jesse Barnes79e53942008-11-07 14:24:08 -08001587
1588 /* set the bus switch and get the modes */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001589 num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001590
Keith Packard57cdaf92009-09-04 13:07:54 +08001591 /*
1592 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1593 * link between analog and digital outputs. So, if the regular SDVO
1594 * DDC fails, check to see if the analog output is disconnected, in
1595 * which case we'll look there for the digital DDC data.
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001596 */
Keith Packard57cdaf92009-09-04 13:07:54 +08001597 if (num_modes == 0 &&
1598 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001599 !intel_analog_is_connected(connector->dev)) {
Keith Packard57cdaf92009-09-04 13:07:54 +08001600 /* Switch to the analog ddc bus and try that
1601 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001602 (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001603 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001604}
1605
1606/*
1607 * Set of SDVO TV modes.
1608 * Note! This is in reply order (see loop in get_tv_modes).
1609 * XXX: all 60Hz refresh?
1610 */
1611struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001612 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1613 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001614 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001615 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1616 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001617 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001618 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1619 496, 0, 300, 301, 332, 333, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001620 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001621 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1622 736, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001623 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001624 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1625 736, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001626 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001627 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1628 736, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001629 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001630 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1631 800, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001632 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001633 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1634 800, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001635 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001636 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1637 816, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001638 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001639 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1640 816, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001641 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001642 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1643 816, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001644 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001645 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1646 816, 0, 540, 541, 572, 573, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001647 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001648 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1649 816, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001650 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001651 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1652 864, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001653 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001654 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1655 896, 0, 600, 601, 632, 633, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001656 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001657 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1658 928, 0, 624, 625, 656, 657, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001659 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001660 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1661 1016, 0, 766, 767, 798, 799, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001662 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001663 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1664 1120, 0, 768, 769, 800, 801, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001665 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001666 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1667 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001668 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1669};
1670
1671static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1672{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001673 struct drm_encoder *encoder = intel_attached_encoder(connector);
1674 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1675 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001676 struct intel_sdvo_sdtv_resolution_request tv_res;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001677 uint32_t reply = 0, format_map = 0;
1678 int i;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001679 uint8_t status;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001680
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001681
1682 /* Read the list of supported input resolutions for the selected TV
1683 * format.
1684 */
Zhao Yakuice6feab2009-08-24 13:50:26 +08001685 for (i = 0; i < TV_FORMAT_NUM; i++)
1686 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1687 break;
1688
1689 format_map = (1 << i);
1690 memcpy(&tv_res, &format_map,
1691 sizeof(struct intel_sdvo_sdtv_resolution_request) >
1692 sizeof(format_map) ? sizeof(format_map) :
1693 sizeof(struct intel_sdvo_sdtv_resolution_request));
1694
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001695 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->controlled_output);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001696
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001697 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001698 &tv_res, sizeof(tv_res));
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001699 status = intel_sdvo_read_response(intel_encoder, &reply, 3);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001700 if (status != SDVO_CMD_STATUS_SUCCESS)
1701 return;
1702
1703 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001704 if (reply & (1 << i)) {
1705 struct drm_display_mode *nmode;
1706 nmode = drm_mode_duplicate(connector->dev,
1707 &sdvo_tv_modes[i]);
1708 if (nmode)
1709 drm_mode_probed_add(connector, nmode);
1710 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001711
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001712}
1713
Ma Ling7086c872009-05-13 11:20:06 +08001714static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1715{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001716 struct drm_encoder *encoder = intel_attached_encoder(connector);
1717 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Ma Ling7086c872009-05-13 11:20:06 +08001718 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001719 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001720 struct drm_display_mode *newmode;
Ma Ling7086c872009-05-13 11:20:06 +08001721
1722 /*
1723 * Attempt to get the mode list from DDC.
1724 * Assume that the preferred modes are
1725 * arranged in priority order.
1726 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001727 intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Ma Ling7086c872009-05-13 11:20:06 +08001728 if (list_empty(&connector->probed_modes) == false)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001729 goto end;
Ma Ling7086c872009-05-13 11:20:06 +08001730
1731 /* Fetch modes from VBT */
1732 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
Ma Ling7086c872009-05-13 11:20:06 +08001733 newmode = drm_mode_duplicate(connector->dev,
1734 dev_priv->sdvo_lvds_vbt_mode);
1735 if (newmode != NULL) {
1736 /* Guarantee the mode is preferred */
1737 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1738 DRM_MODE_TYPE_DRIVER);
1739 drm_mode_probed_add(connector, newmode);
1740 }
1741 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001742
1743end:
1744 list_for_each_entry(newmode, &connector->probed_modes, head) {
1745 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1746 sdvo_priv->sdvo_lvds_fixed_mode =
1747 drm_mode_duplicate(connector->dev, newmode);
1748 break;
1749 }
1750 }
1751
Ma Ling7086c872009-05-13 11:20:06 +08001752}
1753
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001754static int intel_sdvo_get_modes(struct drm_connector *connector)
1755{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001756 struct drm_encoder *encoder = intel_attached_encoder(connector);
1757 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1758 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001759
1760 if (sdvo_priv->is_tv)
1761 intel_sdvo_get_tv_modes(connector);
Ma Ling7086c872009-05-13 11:20:06 +08001762 else if (sdvo_priv->is_lvds == true)
1763 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001764 else
1765 intel_sdvo_get_ddc_modes(connector);
1766
Jesse Barnes79e53942008-11-07 14:24:08 -08001767 if (list_empty(&connector->probed_modes))
1768 return 0;
1769 return 1;
1770}
1771
Zhao Yakuib9219c52009-09-10 15:45:46 +08001772static
1773void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1774{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001775 struct drm_encoder *encoder = intel_attached_encoder(connector);
1776 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001777 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001778 struct drm_device *dev = encoder->dev;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001779
1780 if (sdvo_priv->is_tv) {
1781 if (sdvo_priv->left_property)
1782 drm_property_destroy(dev, sdvo_priv->left_property);
1783 if (sdvo_priv->right_property)
1784 drm_property_destroy(dev, sdvo_priv->right_property);
1785 if (sdvo_priv->top_property)
1786 drm_property_destroy(dev, sdvo_priv->top_property);
1787 if (sdvo_priv->bottom_property)
1788 drm_property_destroy(dev, sdvo_priv->bottom_property);
1789 if (sdvo_priv->hpos_property)
1790 drm_property_destroy(dev, sdvo_priv->hpos_property);
1791 if (sdvo_priv->vpos_property)
1792 drm_property_destroy(dev, sdvo_priv->vpos_property);
1793 }
1794 if (sdvo_priv->is_tv) {
1795 if (sdvo_priv->saturation_property)
1796 drm_property_destroy(dev,
1797 sdvo_priv->saturation_property);
1798 if (sdvo_priv->contrast_property)
1799 drm_property_destroy(dev,
1800 sdvo_priv->contrast_property);
1801 if (sdvo_priv->hue_property)
1802 drm_property_destroy(dev, sdvo_priv->hue_property);
1803 }
Zhao Yakuid0cbde92009-09-10 15:45:47 +08001804 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001805 if (sdvo_priv->brightness_property)
1806 drm_property_destroy(dev,
1807 sdvo_priv->brightness_property);
1808 }
1809 return;
1810}
1811
Jesse Barnes79e53942008-11-07 14:24:08 -08001812static void intel_sdvo_destroy(struct drm_connector *connector)
1813{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001814 intel_sdvo_destroy_enhance_property(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001815 drm_sysfs_connector_remove(connector);
1816 drm_connector_cleanup(connector);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001817 kfree(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001818}
1819
Zhao Yakuice6feab2009-08-24 13:50:26 +08001820static int
1821intel_sdvo_set_property(struct drm_connector *connector,
1822 struct drm_property *property,
1823 uint64_t val)
1824{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001825 struct drm_encoder *encoder = intel_attached_encoder(connector);
1826 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001827 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001828 struct drm_crtc *crtc = encoder->crtc;
1829 int ret = 0;
1830 bool changed = false;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001831 uint8_t cmd, status;
1832 uint16_t temp_value;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001833
1834 ret = drm_connector_property_set_value(connector, property, val);
1835 if (ret < 0)
1836 goto out;
1837
1838 if (property == sdvo_priv->tv_format_property) {
1839 if (val >= TV_FORMAT_NUM) {
1840 ret = -EINVAL;
1841 goto out;
1842 }
1843 if (sdvo_priv->tv_format_name ==
1844 sdvo_priv->tv_format_supported[val])
1845 goto out;
1846
1847 sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[val];
1848 changed = true;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001849 }
1850
Zhao Yakuid0cbde92009-09-10 15:45:47 +08001851 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001852 cmd = 0;
1853 temp_value = val;
1854 if (sdvo_priv->left_property == property) {
1855 drm_connector_property_set_value(connector,
1856 sdvo_priv->right_property, val);
1857 if (sdvo_priv->left_margin == temp_value)
1858 goto out;
1859
1860 sdvo_priv->left_margin = temp_value;
1861 sdvo_priv->right_margin = temp_value;
1862 temp_value = sdvo_priv->max_hscan -
1863 sdvo_priv->left_margin;
1864 cmd = SDVO_CMD_SET_OVERSCAN_H;
1865 } else if (sdvo_priv->right_property == property) {
1866 drm_connector_property_set_value(connector,
1867 sdvo_priv->left_property, val);
1868 if (sdvo_priv->right_margin == temp_value)
1869 goto out;
1870
1871 sdvo_priv->left_margin = temp_value;
1872 sdvo_priv->right_margin = temp_value;
1873 temp_value = sdvo_priv->max_hscan -
1874 sdvo_priv->left_margin;
1875 cmd = SDVO_CMD_SET_OVERSCAN_H;
1876 } else if (sdvo_priv->top_property == property) {
1877 drm_connector_property_set_value(connector,
1878 sdvo_priv->bottom_property, val);
1879 if (sdvo_priv->top_margin == temp_value)
1880 goto out;
1881
1882 sdvo_priv->top_margin = temp_value;
1883 sdvo_priv->bottom_margin = temp_value;
1884 temp_value = sdvo_priv->max_vscan -
1885 sdvo_priv->top_margin;
1886 cmd = SDVO_CMD_SET_OVERSCAN_V;
1887 } else if (sdvo_priv->bottom_property == property) {
1888 drm_connector_property_set_value(connector,
1889 sdvo_priv->top_property, val);
1890 if (sdvo_priv->bottom_margin == temp_value)
1891 goto out;
1892 sdvo_priv->top_margin = temp_value;
1893 sdvo_priv->bottom_margin = temp_value;
1894 temp_value = sdvo_priv->max_vscan -
1895 sdvo_priv->top_margin;
1896 cmd = SDVO_CMD_SET_OVERSCAN_V;
1897 } else if (sdvo_priv->hpos_property == property) {
1898 if (sdvo_priv->cur_hpos == temp_value)
1899 goto out;
1900
1901 cmd = SDVO_CMD_SET_POSITION_H;
1902 sdvo_priv->cur_hpos = temp_value;
1903 } else if (sdvo_priv->vpos_property == property) {
1904 if (sdvo_priv->cur_vpos == temp_value)
1905 goto out;
1906
1907 cmd = SDVO_CMD_SET_POSITION_V;
1908 sdvo_priv->cur_vpos = temp_value;
1909 } else if (sdvo_priv->saturation_property == property) {
1910 if (sdvo_priv->cur_saturation == temp_value)
1911 goto out;
1912
1913 cmd = SDVO_CMD_SET_SATURATION;
1914 sdvo_priv->cur_saturation = temp_value;
1915 } else if (sdvo_priv->contrast_property == property) {
1916 if (sdvo_priv->cur_contrast == temp_value)
1917 goto out;
1918
1919 cmd = SDVO_CMD_SET_CONTRAST;
1920 sdvo_priv->cur_contrast = temp_value;
1921 } else if (sdvo_priv->hue_property == property) {
1922 if (sdvo_priv->cur_hue == temp_value)
1923 goto out;
1924
1925 cmd = SDVO_CMD_SET_HUE;
1926 sdvo_priv->cur_hue = temp_value;
1927 } else if (sdvo_priv->brightness_property == property) {
1928 if (sdvo_priv->cur_brightness == temp_value)
1929 goto out;
1930
1931 cmd = SDVO_CMD_SET_BRIGHTNESS;
1932 sdvo_priv->cur_brightness = temp_value;
1933 }
1934 if (cmd) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001935 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
1936 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08001937 NULL, 0);
1938 if (status != SDVO_CMD_STATUS_SUCCESS) {
1939 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1940 return -EINVAL;
1941 }
1942 changed = true;
1943 }
1944 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001945 if (changed && crtc)
1946 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1947 crtc->y, crtc->fb);
1948out:
1949 return ret;
1950}
1951
Jesse Barnes79e53942008-11-07 14:24:08 -08001952static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1953 .dpms = intel_sdvo_dpms,
1954 .mode_fixup = intel_sdvo_mode_fixup,
1955 .prepare = intel_encoder_prepare,
1956 .mode_set = intel_sdvo_mode_set,
1957 .commit = intel_encoder_commit,
1958};
1959
1960static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -07001961 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -08001962 .detect = intel_sdvo_detect,
1963 .fill_modes = drm_helper_probe_single_connector_modes,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001964 .set_property = intel_sdvo_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -08001965 .destroy = intel_sdvo_destroy,
1966};
1967
1968static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
1969 .get_modes = intel_sdvo_get_modes,
1970 .mode_valid = intel_sdvo_mode_valid,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001971 .best_encoder = intel_attached_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001972};
1973
Hannes Ederb358d0a2008-12-18 21:18:47 +01001974static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08001975{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001976 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1977 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1978
1979 if (intel_encoder->i2c_bus)
1980 intel_i2c_destroy(intel_encoder->i2c_bus);
1981 if (intel_encoder->ddc_bus)
1982 intel_i2c_destroy(intel_encoder->ddc_bus);
1983 if (sdvo_priv->analog_ddc_bus)
1984 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
1985
1986 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
1987 drm_mode_destroy(encoder->dev,
1988 sdvo_priv->sdvo_lvds_fixed_mode);
1989
1990 if (sdvo_priv->tv_format_property)
1991 drm_property_destroy(encoder->dev,
1992 sdvo_priv->tv_format_property);
1993
Jesse Barnes79e53942008-11-07 14:24:08 -08001994 drm_encoder_cleanup(encoder);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001995 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08001996}
1997
1998static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
1999 .destroy = intel_sdvo_enc_destroy,
2000};
2001
2002
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002003/**
2004 * Choose the appropriate DDC bus for control bus switch command for this
2005 * SDVO output based on the controlled output.
2006 *
2007 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2008 * outputs, then LVDS outputs.
2009 */
2010static void
2011intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
2012{
2013 uint16_t mask = 0;
2014 unsigned int num_bits;
2015
2016 /* Make a mask of outputs less than or equal to our own priority in the
2017 * list.
2018 */
2019 switch (dev_priv->controlled_output) {
2020 case SDVO_OUTPUT_LVDS1:
2021 mask |= SDVO_OUTPUT_LVDS1;
2022 case SDVO_OUTPUT_LVDS0:
2023 mask |= SDVO_OUTPUT_LVDS0;
2024 case SDVO_OUTPUT_TMDS1:
2025 mask |= SDVO_OUTPUT_TMDS1;
2026 case SDVO_OUTPUT_TMDS0:
2027 mask |= SDVO_OUTPUT_TMDS0;
2028 case SDVO_OUTPUT_RGB1:
2029 mask |= SDVO_OUTPUT_RGB1;
2030 case SDVO_OUTPUT_RGB0:
2031 mask |= SDVO_OUTPUT_RGB0;
2032 break;
2033 }
2034
2035 /* Count bits to find what number we are in the priority list. */
2036 mask &= dev_priv->caps.output_flags;
2037 num_bits = hweight16(mask);
2038 if (num_bits > 3) {
2039 /* if more than 3 outputs, default to DDC bus 3 for now */
2040 num_bits = 3;
2041 }
2042
2043 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2044 dev_priv->ddc_bus = 1 << num_bits;
2045}
2046
2047static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07002048intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002049{
2050 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
2051 uint8_t status;
2052
2053 intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
2054
2055 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2056 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
2057 if (status != SDVO_CMD_STATUS_SUCCESS)
2058 return false;
2059 return true;
2060}
2061
Eric Anholt21d40d32010-03-25 11:11:14 -07002062static struct intel_encoder *
2063intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan)
Ma Ling619ac3b2009-05-18 16:12:46 +08002064{
2065 struct drm_device *dev = chan->drm_dev;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002066 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07002067 struct intel_encoder *intel_encoder = NULL;
Ma Ling619ac3b2009-05-18 16:12:46 +08002068
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002069 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2070 intel_encoder = enc_to_intel_encoder(encoder);
2071 if (intel_encoder->ddc_bus == &chan->adapter)
Ma Ling619ac3b2009-05-18 16:12:46 +08002072 break;
Ma Ling619ac3b2009-05-18 16:12:46 +08002073 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002074 return intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002075}
2076
2077static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2078 struct i2c_msg msgs[], int num)
2079{
Eric Anholt21d40d32010-03-25 11:11:14 -07002080 struct intel_encoder *intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002081 struct intel_sdvo_priv *sdvo_priv;
2082 struct i2c_algo_bit_data *algo_data;
Keith Packardf9c10a92009-05-30 12:16:25 -07002083 const struct i2c_algorithm *algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002084
2085 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
Eric Anholt21d40d32010-03-25 11:11:14 -07002086 intel_encoder =
2087 intel_sdvo_chan_to_intel_encoder(
Ma Ling619ac3b2009-05-18 16:12:46 +08002088 (struct intel_i2c_chan *)(algo_data->data));
Eric Anholt21d40d32010-03-25 11:11:14 -07002089 if (intel_encoder == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002090 return -EINVAL;
2091
Eric Anholt21d40d32010-03-25 11:11:14 -07002092 sdvo_priv = intel_encoder->dev_priv;
2093 algo = intel_encoder->i2c_bus->algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002094
Eric Anholt21d40d32010-03-25 11:11:14 -07002095 intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08002096 return algo->master_xfer(i2c_adap, msgs, num);
2097}
2098
2099static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
2100 .master_xfer = intel_sdvo_master_xfer,
2101};
2102
yakui_zhao714605e2009-05-31 17:18:07 +08002103static u8
Eric Anholtc751ce42010-03-25 11:48:48 -07002104intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
yakui_zhao714605e2009-05-31 17:18:07 +08002105{
2106 struct drm_i915_private *dev_priv = dev->dev_private;
2107 struct sdvo_device_mapping *my_mapping, *other_mapping;
2108
Eric Anholtc751ce42010-03-25 11:48:48 -07002109 if (sdvo_reg == SDVOB) {
yakui_zhao714605e2009-05-31 17:18:07 +08002110 my_mapping = &dev_priv->sdvo_mappings[0];
2111 other_mapping = &dev_priv->sdvo_mappings[1];
2112 } else {
2113 my_mapping = &dev_priv->sdvo_mappings[1];
2114 other_mapping = &dev_priv->sdvo_mappings[0];
2115 }
2116
2117 /* If the BIOS described our SDVO device, take advantage of it. */
2118 if (my_mapping->slave_addr)
2119 return my_mapping->slave_addr;
2120
2121 /* If the BIOS only described a different SDVO device, use the
2122 * address that it isn't using.
2123 */
2124 if (other_mapping->slave_addr) {
2125 if (other_mapping->slave_addr == 0x70)
2126 return 0x72;
2127 else
2128 return 0x70;
2129 }
2130
2131 /* No SDVO device info is found for another DVO port,
2132 * so use mapping assumption we had before BIOS parsing.
2133 */
Eric Anholtc751ce42010-03-25 11:48:48 -07002134 if (sdvo_reg == SDVOB)
yakui_zhao714605e2009-05-31 17:18:07 +08002135 return 0x70;
2136 else
2137 return 0x72;
2138}
2139
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002140static int intel_sdvo_bad_tv_callback(const struct dmi_system_id *id)
2141{
2142 DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id->ident);
2143 return 1;
2144}
2145
2146static struct dmi_system_id intel_sdvo_bad_tv[] = {
2147 {
2148 .callback = intel_sdvo_bad_tv_callback,
2149 .ident = "IntelG45/ICH10R/DME1737",
2150 .matches = {
2151 DMI_MATCH(DMI_SYS_VENDOR, "IBM CORPORATION"),
2152 DMI_MATCH(DMI_PRODUCT_NAME, "4800784"),
2153 },
2154 },
2155
2156 { } /* terminating entry */
2157};
2158
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002159static bool
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002160intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
2161 struct intel_connector *intel_connector,
2162 uint16_t flags)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002163{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002164 struct drm_connector *connector = &intel_connector->base;
Eric Anholt21d40d32010-03-25 11:11:14 -07002165 struct drm_encoder *encoder = &intel_encoder->enc;
2166 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002167 bool ret = true, registered = false;
2168
2169 sdvo_priv->is_tv = false;
Eric Anholt21d40d32010-03-25 11:11:14 -07002170 intel_encoder->needs_tv_clock = false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002171 sdvo_priv->is_lvds = false;
2172
2173 if (device_is_registered(&connector->kdev)) {
2174 drm_sysfs_connector_remove(connector);
2175 registered = true;
2176 }
2177
2178 if (flags &
2179 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
2180 if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0)
2181 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0;
2182 else
2183 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1;
2184
2185 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2186 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2187
Eric Anholt21d40d32010-03-25 11:11:14 -07002188 if (intel_sdvo_get_supp_encode(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002189 &sdvo_priv->encode) &&
Eric Anholt21d40d32010-03-25 11:11:14 -07002190 intel_sdvo_get_digital_encoding_mode(intel_encoder) &&
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002191 sdvo_priv->is_hdmi) {
2192 /* enable hdmi encoding mode if supported */
Eric Anholt21d40d32010-03-25 11:11:14 -07002193 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI);
2194 intel_sdvo_set_colorimetry(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002195 SDVO_COLORIMETRY_RGB256);
2196 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
Eric Anholt21d40d32010-03-25 11:11:14 -07002197 intel_encoder->clone_mask =
Ma Lingf8aed702009-08-24 13:50:24 +08002198 (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2199 (1 << INTEL_ANALOG_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002200 }
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002201 } else if ((flags & SDVO_OUTPUT_SVID0) &&
2202 !dmi_check_system(intel_sdvo_bad_tv)) {
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002203
2204 sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0;
2205 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2206 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2207 sdvo_priv->is_tv = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002208 intel_encoder->needs_tv_clock = true;
2209 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002210 } else if (flags & SDVO_OUTPUT_RGB0) {
2211
2212 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0;
2213 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2214 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
Eric Anholt21d40d32010-03-25 11:11:14 -07002215 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +08002216 (1 << INTEL_ANALOG_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002217 } else if (flags & SDVO_OUTPUT_RGB1) {
2218
2219 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1;
2220 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2221 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
Eric Anholt21d40d32010-03-25 11:11:14 -07002222 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
Zhao Yakuie2708462009-09-10 15:45:48 +08002223 (1 << INTEL_ANALOG_CLONE_BIT);
Zhao Yakui2dd87382010-01-27 16:32:46 +08002224 } else if (flags & SDVO_OUTPUT_CVBS0) {
2225
2226 sdvo_priv->controlled_output = SDVO_OUTPUT_CVBS0;
2227 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2228 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2229 sdvo_priv->is_tv = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002230 intel_encoder->needs_tv_clock = true;
2231 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002232 } else if (flags & SDVO_OUTPUT_LVDS0) {
2233
2234 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0;
2235 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2236 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2237 sdvo_priv->is_lvds = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002238 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +08002239 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002240 } else if (flags & SDVO_OUTPUT_LVDS1) {
2241
2242 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1;
2243 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2244 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2245 sdvo_priv->is_lvds = true;
Eric Anholt21d40d32010-03-25 11:11:14 -07002246 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
Ma Lingf8aed702009-08-24 13:50:24 +08002247 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002248 } else {
2249
2250 unsigned char bytes[2];
2251
2252 sdvo_priv->controlled_output = 0;
2253 memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
Dave Airlie51c8b402009-08-20 13:38:04 +10002254 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2255 SDVO_NAME(sdvo_priv),
2256 bytes[0], bytes[1]);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002257 ret = false;
2258 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002259 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002260
2261 if (ret && registered)
2262 ret = drm_sysfs_connector_add(connector) == 0 ? true : false;
2263
2264
2265 return ret;
2266
2267}
2268
Zhao Yakuice6feab2009-08-24 13:50:26 +08002269static void intel_sdvo_tv_create_property(struct drm_connector *connector)
2270{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002271 struct drm_encoder *encoder = intel_attached_encoder(connector);
2272 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07002273 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002274 struct intel_sdvo_tv_format format;
2275 uint32_t format_map, i;
2276 uint8_t status;
2277
Eric Anholt21d40d32010-03-25 11:11:14 -07002278 intel_sdvo_set_target_output(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002279 sdvo_priv->controlled_output);
2280
Eric Anholt21d40d32010-03-25 11:11:14 -07002281 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002282 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002283 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002284 &format, sizeof(format));
2285 if (status != SDVO_CMD_STATUS_SUCCESS)
2286 return;
2287
2288 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
2289 sizeof(format_map) : sizeof(format));
2290
2291 if (format_map == 0)
2292 return;
2293
2294 sdvo_priv->format_supported_num = 0;
2295 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2296 if (format_map & (1 << i)) {
2297 sdvo_priv->tv_format_supported
2298 [sdvo_priv->format_supported_num++] =
2299 tv_format_names[i];
2300 }
2301
2302
2303 sdvo_priv->tv_format_property =
2304 drm_property_create(
2305 connector->dev, DRM_MODE_PROP_ENUM,
2306 "mode", sdvo_priv->format_supported_num);
2307
2308 for (i = 0; i < sdvo_priv->format_supported_num; i++)
2309 drm_property_add_enum(
2310 sdvo_priv->tv_format_property, i,
2311 i, sdvo_priv->tv_format_supported[i]);
2312
2313 sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[0];
2314 drm_connector_attach_property(
2315 connector, sdvo_priv->tv_format_property, 0);
2316
2317}
2318
Zhao Yakuib9219c52009-09-10 15:45:46 +08002319static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2320{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002321 struct drm_encoder *encoder = intel_attached_encoder(connector);
2322 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07002323 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuib9219c52009-09-10 15:45:46 +08002324 struct intel_sdvo_enhancements_reply sdvo_data;
2325 struct drm_device *dev = connector->dev;
2326 uint8_t status;
2327 uint16_t response, data_value[2];
2328
Eric Anholt21d40d32010-03-25 11:11:14 -07002329 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002330 NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002331 status = intel_sdvo_read_response(intel_encoder, &sdvo_data,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002332 sizeof(sdvo_data));
2333 if (status != SDVO_CMD_STATUS_SUCCESS) {
2334 DRM_DEBUG_KMS(" incorrect response is returned\n");
2335 return;
2336 }
2337 response = *((uint16_t *)&sdvo_data);
2338 if (!response) {
2339 DRM_DEBUG_KMS("No enhancement is supported\n");
2340 return;
2341 }
2342 if (sdvo_priv->is_tv) {
2343 /* when horizontal overscan is supported, Add the left/right
2344 * property
2345 */
2346 if (sdvo_data.overscan_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002347 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002348 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002349 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002350 &data_value, 4);
2351 if (status != SDVO_CMD_STATUS_SUCCESS) {
2352 DRM_DEBUG_KMS("Incorrect SDVO max "
2353 "h_overscan\n");
2354 return;
2355 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002356 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002357 SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002358 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002359 &response, 2);
2360 if (status != SDVO_CMD_STATUS_SUCCESS) {
2361 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2362 return;
2363 }
2364 sdvo_priv->max_hscan = data_value[0];
2365 sdvo_priv->left_margin = data_value[0] - response;
2366 sdvo_priv->right_margin = sdvo_priv->left_margin;
2367 sdvo_priv->left_property =
2368 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2369 "left_margin", 2);
2370 sdvo_priv->left_property->values[0] = 0;
2371 sdvo_priv->left_property->values[1] = data_value[0];
2372 drm_connector_attach_property(connector,
2373 sdvo_priv->left_property,
2374 sdvo_priv->left_margin);
2375 sdvo_priv->right_property =
2376 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2377 "right_margin", 2);
2378 sdvo_priv->right_property->values[0] = 0;
2379 sdvo_priv->right_property->values[1] = data_value[0];
2380 drm_connector_attach_property(connector,
2381 sdvo_priv->right_property,
2382 sdvo_priv->right_margin);
2383 DRM_DEBUG_KMS("h_overscan: max %d, "
2384 "default %d, current %d\n",
2385 data_value[0], data_value[1], response);
2386 }
2387 if (sdvo_data.overscan_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002388 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002389 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002390 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002391 &data_value, 4);
2392 if (status != SDVO_CMD_STATUS_SUCCESS) {
2393 DRM_DEBUG_KMS("Incorrect SDVO max "
2394 "v_overscan\n");
2395 return;
2396 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002397 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002398 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002399 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002400 &response, 2);
2401 if (status != SDVO_CMD_STATUS_SUCCESS) {
2402 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2403 return;
2404 }
2405 sdvo_priv->max_vscan = data_value[0];
2406 sdvo_priv->top_margin = data_value[0] - response;
2407 sdvo_priv->bottom_margin = sdvo_priv->top_margin;
2408 sdvo_priv->top_property =
2409 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2410 "top_margin", 2);
2411 sdvo_priv->top_property->values[0] = 0;
2412 sdvo_priv->top_property->values[1] = data_value[0];
2413 drm_connector_attach_property(connector,
2414 sdvo_priv->top_property,
2415 sdvo_priv->top_margin);
2416 sdvo_priv->bottom_property =
2417 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2418 "bottom_margin", 2);
2419 sdvo_priv->bottom_property->values[0] = 0;
2420 sdvo_priv->bottom_property->values[1] = data_value[0];
2421 drm_connector_attach_property(connector,
2422 sdvo_priv->bottom_property,
2423 sdvo_priv->bottom_margin);
2424 DRM_DEBUG_KMS("v_overscan: max %d, "
2425 "default %d, current %d\n",
2426 data_value[0], data_value[1], response);
2427 }
2428 if (sdvo_data.position_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002429 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002430 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002431 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002432 &data_value, 4);
2433 if (status != SDVO_CMD_STATUS_SUCCESS) {
2434 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2435 return;
2436 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002437 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002438 SDVO_CMD_GET_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002439 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002440 &response, 2);
2441 if (status != SDVO_CMD_STATUS_SUCCESS) {
2442 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2443 return;
2444 }
2445 sdvo_priv->max_hpos = data_value[0];
2446 sdvo_priv->cur_hpos = response;
2447 sdvo_priv->hpos_property =
2448 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2449 "hpos", 2);
2450 sdvo_priv->hpos_property->values[0] = 0;
2451 sdvo_priv->hpos_property->values[1] = data_value[0];
2452 drm_connector_attach_property(connector,
2453 sdvo_priv->hpos_property,
2454 sdvo_priv->cur_hpos);
2455 DRM_DEBUG_KMS("h_position: max %d, "
2456 "default %d, current %d\n",
2457 data_value[0], data_value[1], response);
2458 }
2459 if (sdvo_data.position_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002460 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002461 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002462 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002463 &data_value, 4);
2464 if (status != SDVO_CMD_STATUS_SUCCESS) {
2465 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2466 return;
2467 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002468 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002469 SDVO_CMD_GET_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002470 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002471 &response, 2);
2472 if (status != SDVO_CMD_STATUS_SUCCESS) {
2473 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2474 return;
2475 }
2476 sdvo_priv->max_vpos = data_value[0];
2477 sdvo_priv->cur_vpos = response;
2478 sdvo_priv->vpos_property =
2479 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2480 "vpos", 2);
2481 sdvo_priv->vpos_property->values[0] = 0;
2482 sdvo_priv->vpos_property->values[1] = data_value[0];
2483 drm_connector_attach_property(connector,
2484 sdvo_priv->vpos_property,
2485 sdvo_priv->cur_vpos);
2486 DRM_DEBUG_KMS("v_position: max %d, "
2487 "default %d, current %d\n",
2488 data_value[0], data_value[1], response);
2489 }
2490 }
2491 if (sdvo_priv->is_tv) {
2492 if (sdvo_data.saturation) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002493 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002494 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002495 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002496 &data_value, 4);
2497 if (status != SDVO_CMD_STATUS_SUCCESS) {
2498 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2499 return;
2500 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002501 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002502 SDVO_CMD_GET_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002503 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002504 &response, 2);
2505 if (status != SDVO_CMD_STATUS_SUCCESS) {
2506 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2507 return;
2508 }
2509 sdvo_priv->max_saturation = data_value[0];
2510 sdvo_priv->cur_saturation = response;
2511 sdvo_priv->saturation_property =
2512 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2513 "saturation", 2);
2514 sdvo_priv->saturation_property->values[0] = 0;
2515 sdvo_priv->saturation_property->values[1] =
2516 data_value[0];
2517 drm_connector_attach_property(connector,
2518 sdvo_priv->saturation_property,
2519 sdvo_priv->cur_saturation);
2520 DRM_DEBUG_KMS("saturation: max %d, "
2521 "default %d, current %d\n",
2522 data_value[0], data_value[1], response);
2523 }
2524 if (sdvo_data.contrast) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002525 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002526 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002527 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002528 &data_value, 4);
2529 if (status != SDVO_CMD_STATUS_SUCCESS) {
2530 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2531 return;
2532 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002533 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002534 SDVO_CMD_GET_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002535 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002536 &response, 2);
2537 if (status != SDVO_CMD_STATUS_SUCCESS) {
2538 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2539 return;
2540 }
2541 sdvo_priv->max_contrast = data_value[0];
2542 sdvo_priv->cur_contrast = response;
2543 sdvo_priv->contrast_property =
2544 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2545 "contrast", 2);
2546 sdvo_priv->contrast_property->values[0] = 0;
2547 sdvo_priv->contrast_property->values[1] = data_value[0];
2548 drm_connector_attach_property(connector,
2549 sdvo_priv->contrast_property,
2550 sdvo_priv->cur_contrast);
2551 DRM_DEBUG_KMS("contrast: max %d, "
2552 "default %d, current %d\n",
2553 data_value[0], data_value[1], response);
2554 }
2555 if (sdvo_data.hue) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002556 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002557 SDVO_CMD_GET_MAX_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002558 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002559 &data_value, 4);
2560 if (status != SDVO_CMD_STATUS_SUCCESS) {
2561 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2562 return;
2563 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002564 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002565 SDVO_CMD_GET_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002566 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002567 &response, 2);
2568 if (status != SDVO_CMD_STATUS_SUCCESS) {
2569 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2570 return;
2571 }
2572 sdvo_priv->max_hue = data_value[0];
2573 sdvo_priv->cur_hue = response;
2574 sdvo_priv->hue_property =
2575 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2576 "hue", 2);
2577 sdvo_priv->hue_property->values[0] = 0;
2578 sdvo_priv->hue_property->values[1] =
2579 data_value[0];
2580 drm_connector_attach_property(connector,
2581 sdvo_priv->hue_property,
2582 sdvo_priv->cur_hue);
2583 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2584 data_value[0], data_value[1], response);
2585 }
2586 }
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002587 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002588 if (sdvo_data.brightness) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002589 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002590 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002591 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002592 &data_value, 4);
2593 if (status != SDVO_CMD_STATUS_SUCCESS) {
2594 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2595 return;
2596 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002597 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002598 SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002599 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002600 &response, 2);
2601 if (status != SDVO_CMD_STATUS_SUCCESS) {
2602 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2603 return;
2604 }
2605 sdvo_priv->max_brightness = data_value[0];
2606 sdvo_priv->cur_brightness = response;
2607 sdvo_priv->brightness_property =
2608 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2609 "brightness", 2);
2610 sdvo_priv->brightness_property->values[0] = 0;
2611 sdvo_priv->brightness_property->values[1] =
2612 data_value[0];
2613 drm_connector_attach_property(connector,
2614 sdvo_priv->brightness_property,
2615 sdvo_priv->cur_brightness);
2616 DRM_DEBUG_KMS("brightness: max %d, "
2617 "default %d, current %d\n",
2618 data_value[0], data_value[1], response);
2619 }
2620 }
2621 return;
2622}
2623
Eric Anholtc751ce42010-03-25 11:48:48 -07002624bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
Jesse Barnes79e53942008-11-07 14:24:08 -08002625{
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002626 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes79e53942008-11-07 14:24:08 -08002627 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -07002628 struct intel_encoder *intel_encoder;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002629 struct intel_connector *intel_connector;
Jesse Barnes79e53942008-11-07 14:24:08 -08002630 struct intel_sdvo_priv *sdvo_priv;
Keith Packardf9c10a92009-05-30 12:16:25 -07002631
Jesse Barnes79e53942008-11-07 14:24:08 -08002632 u8 ch[0x40];
2633 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -08002634
Eric Anholt21d40d32010-03-25 11:11:14 -07002635 intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
2636 if (!intel_encoder) {
Eric Anholt7d573822009-01-02 13:33:00 -08002637 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002638 }
2639
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002640 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2641 if (!intel_connector) {
2642 kfree(intel_encoder);
2643 return false;
2644 }
2645
Eric Anholt21d40d32010-03-25 11:11:14 -07002646 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1);
Eric Anholtc751ce42010-03-25 11:48:48 -07002647 sdvo_priv->sdvo_reg = sdvo_reg;
Keith Packard308cd3a2009-06-14 11:56:18 -07002648
Eric Anholt21d40d32010-03-25 11:11:14 -07002649 intel_encoder->dev_priv = sdvo_priv;
2650 intel_encoder->type = INTEL_OUTPUT_SDVO;
Jesse Barnes79e53942008-11-07 14:24:08 -08002651
Jesse Barnes79e53942008-11-07 14:24:08 -08002652 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002653 if (sdvo_reg == SDVOB)
Eric Anholt21d40d32010-03-25 11:11:14 -07002654 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
Keith Packard308cd3a2009-06-14 11:56:18 -07002655 else
Eric Anholt21d40d32010-03-25 11:11:14 -07002656 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
Keith Packard308cd3a2009-06-14 11:56:18 -07002657
Eric Anholt21d40d32010-03-25 11:11:14 -07002658 if (!intel_encoder->i2c_bus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002659 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08002660
Eric Anholtc751ce42010-03-25 11:48:48 -07002661 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08002662
Keith Packard308cd3a2009-06-14 11:56:18 -07002663 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
Eric Anholt21d40d32010-03-25 11:11:14 -07002664 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
Jesse Barnes79e53942008-11-07 14:24:08 -08002665
Jesse Barnes79e53942008-11-07 14:24:08 -08002666 /* Read the regs to test if we can talk to the device */
2667 for (i = 0; i < 0x40; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002668 if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002669 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002670 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002671 goto err_i2c;
2672 }
2673 }
2674
Ma Ling619ac3b2009-05-18 16:12:46 +08002675 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002676 if (sdvo_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002677 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002678 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2679 "SDVOB/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002680 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002681 } else {
Eric Anholt21d40d32010-03-25 11:11:14 -07002682 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002683 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2684 "SDVOC/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002685 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002686 }
Ma Ling619ac3b2009-05-18 16:12:46 +08002687
Eric Anholt21d40d32010-03-25 11:11:14 -07002688 if (intel_encoder->ddc_bus == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002689 goto err_i2c;
2690
Keith Packard308cd3a2009-06-14 11:56:18 -07002691 /* Wrap with our custom algo which switches to DDC mode */
Eric Anholt21d40d32010-03-25 11:11:14 -07002692 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002693
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002694 /* In default case sdvo lvds is false */
Eric Anholt21d40d32010-03-25 11:11:14 -07002695 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps);
Jesse Barnes79e53942008-11-07 14:24:08 -08002696
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002697 if (intel_sdvo_output_setup(intel_encoder, intel_connector,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002698 sdvo_priv->caps.output_flags) != true) {
Dave Airlie51c8b402009-08-20 13:38:04 +10002699 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002700 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002701 goto err_i2c;
2702 }
2703
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002704
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002705 connector = &intel_connector->base;
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002706 drm_connector_init(dev, connector, &intel_sdvo_connector_funcs,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002707 connector->connector_type);
2708
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002709 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2710 connector->interlace_allowed = 0;
2711 connector->doublescan_allowed = 0;
2712 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2713
Eric Anholt21d40d32010-03-25 11:11:14 -07002714 drm_encoder_init(dev, &intel_encoder->enc,
2715 &intel_sdvo_enc_funcs, intel_encoder->enc.encoder_type);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002716
Eric Anholt21d40d32010-03-25 11:11:14 -07002717 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -08002718
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002719 drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc);
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002720 if (sdvo_priv->is_tv)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002721 intel_sdvo_tv_create_property(connector);
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002722
2723 if (sdvo_priv->is_tv || sdvo_priv->is_lvds)
Zhao Yakuib9219c52009-09-10 15:45:46 +08002724 intel_sdvo_create_enhance_property(connector);
Zhao Yakuid0cbde92009-09-10 15:45:47 +08002725
Jesse Barnes79e53942008-11-07 14:24:08 -08002726 drm_sysfs_connector_add(connector);
2727
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002728 intel_sdvo_select_ddc_bus(sdvo_priv);
2729
Jesse Barnes79e53942008-11-07 14:24:08 -08002730 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholt21d40d32010-03-25 11:11:14 -07002731 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08002732
Eric Anholt21d40d32010-03-25 11:11:14 -07002733 intel_sdvo_get_input_pixel_clock_range(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002734 &sdvo_priv->pixel_clock_min,
2735 &sdvo_priv->pixel_clock_max);
2736
2737
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002738 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
yakui_zhao342dc382009-06-02 14:12:00 +08002739 "clock range %dMHz - %dMHz, "
2740 "input 1: %c, input 2: %c, "
2741 "output 1: %c, output 2: %c\n",
2742 SDVO_NAME(sdvo_priv),
2743 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
2744 sdvo_priv->caps.device_rev_id,
2745 sdvo_priv->pixel_clock_min / 1000,
2746 sdvo_priv->pixel_clock_max / 1000,
2747 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2748 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
2749 /* check currently supported outputs */
2750 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002751 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
yakui_zhao342dc382009-06-02 14:12:00 +08002752 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002753 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2754
Eric Anholt7d573822009-01-02 13:33:00 -08002755 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08002756
2757err_i2c:
Keith Packard57cdaf92009-09-04 13:07:54 +08002758 if (sdvo_priv->analog_ddc_bus != NULL)
2759 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
Eric Anholt21d40d32010-03-25 11:11:14 -07002760 if (intel_encoder->ddc_bus != NULL)
2761 intel_i2c_destroy(intel_encoder->ddc_bus);
2762 if (intel_encoder->i2c_bus != NULL)
2763 intel_i2c_destroy(intel_encoder->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002764err_inteloutput:
Eric Anholt21d40d32010-03-25 11:11:14 -07002765 kfree(intel_encoder);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002766 kfree(intel_connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08002767
Eric Anholt7d573822009-01-02 13:33:00 -08002768 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002769}