blob: 5628de27538ceb5fa8dbc682a60c007246eea1fe [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
Zhenyu Wang14571b42010-03-30 14:06:33 +080040#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
41#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
42#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
43#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
44
45#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
46 SDVO_TV_MASK)
47
48#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
49#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
50
51
Zhao Yakuice6feab2009-08-24 13:50:26 +080052static char *tv_format_names[] = {
53 "NTSC_M" , "NTSC_J" , "NTSC_443",
54 "PAL_B" , "PAL_D" , "PAL_G" ,
55 "PAL_H" , "PAL_I" , "PAL_M" ,
56 "PAL_N" , "PAL_NC" , "PAL_60" ,
57 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
58 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
59 "SECAM_60"
60};
61
62#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
63
Jesse Barnes79e53942008-11-07 14:24:08 -080064struct intel_sdvo_priv {
Keith Packardf9c10a92009-05-30 12:16:25 -070065 u8 slave_addr;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080066
67 /* Register for the SDVO device: SDVOB or SDVOC */
Eric Anholtc751ce42010-03-25 11:48:48 -070068 int sdvo_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080069
Jesse Barnese2f0ba92009-02-02 15:11:52 -080070 /* Active outputs controlled by this SDVO output */
71 uint16_t controlled_output;
Jesse Barnes79e53942008-11-07 14:24:08 -080072
Jesse Barnese2f0ba92009-02-02 15:11:52 -080073 /*
74 * Capabilities of the SDVO device returned by
75 * i830_sdvo_get_capabilities()
76 */
Jesse Barnes79e53942008-11-07 14:24:08 -080077 struct intel_sdvo_caps caps;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080078
79 /* Pixel clock limitations reported by the SDVO device, in kHz */
Jesse Barnes79e53942008-11-07 14:24:08 -080080 int pixel_clock_min, pixel_clock_max;
81
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +080082 /*
83 * For multiple function SDVO device,
84 * this is for current attached outputs.
85 */
86 uint16_t attached_output;
87
Jesse Barnese2f0ba92009-02-02 15:11:52 -080088 /**
89 * This is set if we're going to treat the device as TV-out.
90 *
91 * While we have these nice friendly flags for output types that ought
92 * to decide this for us, the S-Video output on our HDMI+S-Video card
93 * shows up as RGB1 (VGA).
94 */
95 bool is_tv;
96
Zhao Yakuice6feab2009-08-24 13:50:26 +080097 /* This is for current tv format name */
98 char *tv_format_name;
99
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800100 /**
101 * This is set if we treat the device as HDMI, instead of DVI.
102 */
103 bool is_hdmi;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800104
Ma Ling7086c872009-05-13 11:20:06 +0800105 /**
106 * This is set if we detect output of sdvo device as LVDS.
107 */
108 bool is_lvds;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800109
110 /**
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800111 * This is sdvo flags for input timing.
112 */
113 uint8_t sdvo_flags;
114
115 /**
116 * This is sdvo fixed pannel mode pointer
117 */
118 struct drm_display_mode *sdvo_lvds_fixed_mode;
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
Zhenyu Wang14571b42010-03-30 14:06:33 +0800132};
133
134struct intel_sdvo_connector {
135 /* Mark the type of connector */
136 uint16_t output_flag;
137
138 /* This contains all current supported TV format */
139 char *tv_format_supported[TV_FORMAT_NUM];
140 int format_supported_num;
141 struct drm_property *tv_format_property;
142 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
143
144 /**
145 * Returned SDTV resolutions allowed for the current format, if the
146 * device reported it.
147 */
148 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
149
Zhao Yakuib9219c52009-09-10 15:45:46 +0800150 /* add the property for the SDVO-TV */
151 struct drm_property *left_property;
152 struct drm_property *right_property;
153 struct drm_property *top_property;
154 struct drm_property *bottom_property;
155 struct drm_property *hpos_property;
156 struct drm_property *vpos_property;
157
158 /* add the property for the SDVO-TV/LVDS */
159 struct drm_property *brightness_property;
160 struct drm_property *contrast_property;
161 struct drm_property *saturation_property;
162 struct drm_property *hue_property;
163
164 /* Add variable to record current setting for the above property */
165 u32 left_margin, right_margin, top_margin, bottom_margin;
166 /* this is to get the range of margin.*/
167 u32 max_hscan, max_vscan;
168 u32 max_hpos, cur_hpos;
169 u32 max_vpos, cur_vpos;
170 u32 cur_brightness, max_brightness;
171 u32 cur_contrast, max_contrast;
172 u32 cur_saturation, max_saturation;
173 u32 cur_hue, max_hue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800174};
175
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800176static bool
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800177intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800178 uint16_t flags);
Zhenyu Wang14571b42010-03-30 14:06:33 +0800179static void
180intel_sdvo_tv_create_property(struct drm_connector *connector, int type);
181static void
182intel_sdvo_create_enhance_property(struct drm_connector *connector);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800183
Jesse Barnes79e53942008-11-07 14:24:08 -0800184/**
185 * Writes the SDVOB or SDVOC with the given value, but always writes both
186 * SDVOB and SDVOC to work around apparent hardware issues (according to
187 * comments in the BIOS).
188 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700189static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800190{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800191 struct drm_device *dev = intel_encoder->enc.dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800192 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -0700193 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800194 u32 bval = val, cval = val;
195 int i;
196
Eric Anholtc751ce42010-03-25 11:48:48 -0700197 if (sdvo_priv->sdvo_reg == SDVOB) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800198 cval = I915_READ(SDVOC);
199 } else {
200 bval = I915_READ(SDVOB);
201 }
202 /*
203 * Write the registers twice for luck. Sometimes,
204 * writing them only once doesn't appear to 'stick'.
205 * The BIOS does this too. Yay, magic
206 */
207 for (i = 0; i < 2; i++)
208 {
209 I915_WRITE(SDVOB, bval);
210 I915_READ(SDVOB);
211 I915_WRITE(SDVOC, cval);
212 I915_READ(SDVOC);
213 }
214}
215
Eric Anholt21d40d32010-03-25 11:11:14 -0700216static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800217 u8 *ch)
218{
Eric Anholt21d40d32010-03-25 11:11:14 -0700219 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800220 u8 out_buf[2];
221 u8 buf[2];
222 int ret;
223
224 struct i2c_msg msgs[] = {
225 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700226 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800227 .flags = 0,
228 .len = 1,
229 .buf = out_buf,
230 },
231 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700232 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800233 .flags = I2C_M_RD,
234 .len = 1,
235 .buf = buf,
236 }
237 };
238
239 out_buf[0] = addr;
240 out_buf[1] = 0;
241
Eric Anholt21d40d32010-03-25 11:11:14 -0700242 if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800243 {
244 *ch = buf[0];
245 return true;
246 }
247
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800248 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
Jesse Barnes79e53942008-11-07 14:24:08 -0800249 return false;
250}
251
Eric Anholt21d40d32010-03-25 11:11:14 -0700252static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800253 u8 ch)
254{
Eric Anholt21d40d32010-03-25 11:11:14 -0700255 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800256 u8 out_buf[2];
257 struct i2c_msg msgs[] = {
258 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700259 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800260 .flags = 0,
261 .len = 2,
262 .buf = out_buf,
263 }
264 };
265
266 out_buf[0] = addr;
267 out_buf[1] = ch;
268
Eric Anholt21d40d32010-03-25 11:11:14 -0700269 if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800270 {
271 return true;
272 }
273 return false;
274}
275
276#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
277/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100278static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800279 u8 cmd;
280 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800281} sdvo_cmd_names[] = {
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
Zhao Yakuib9219c52009-09-10 15:45:46 +0800325 /* Add the op code for SDVO enhancements */
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800350 /* HDMI op code */
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
355 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
356 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
359 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
360 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
361 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
362 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
366 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
368 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
369 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
370 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800371};
372
Eric Anholtc751ce42010-03-25 11:48:48 -0700373#define SDVO_NAME(dev_priv) ((dev_priv)->sdvo_reg == SDVOB ? "SDVOB" : "SDVOC")
374#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -0800375
Eric Anholt21d40d32010-03-25 11:11:14 -0700376static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800377 void *args, int args_len)
378{
Eric Anholt21d40d32010-03-25 11:11:14 -0700379 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800380 int i;
381
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800382 DRM_DEBUG_KMS("%s: W: %02X ",
yakui_zhao342dc382009-06-02 14:12:00 +0800383 SDVO_NAME(sdvo_priv), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800384 for (i = 0; i < args_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800385 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800386 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800387 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800388 for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
389 if (cmd == sdvo_cmd_names[i].cmd) {
yakui_zhao342dc382009-06-02 14:12:00 +0800390 DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800391 break;
392 }
393 }
394 if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
yakui_zhao342dc382009-06-02 14:12:00 +0800395 DRM_LOG_KMS("(%02X)", cmd);
396 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800397}
Jesse Barnes79e53942008-11-07 14:24:08 -0800398
Eric Anholt21d40d32010-03-25 11:11:14 -0700399static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800400 void *args, int args_len)
401{
402 int i;
403
Eric Anholt21d40d32010-03-25 11:11:14 -0700404 intel_sdvo_debug_write(intel_encoder, cmd, args, args_len);
Jesse Barnes79e53942008-11-07 14:24:08 -0800405
406 for (i = 0; i < args_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700407 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i,
Jesse Barnes79e53942008-11-07 14:24:08 -0800408 ((u8*)args)[i]);
409 }
410
Eric Anholt21d40d32010-03-25 11:11:14 -0700411 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800412}
413
Jesse Barnes79e53942008-11-07 14:24:08 -0800414static const char *cmd_status_names[] = {
415 "Power on",
416 "Success",
417 "Not supported",
418 "Invalid arg",
419 "Pending",
420 "Target not specified",
421 "Scaling not supported"
422};
423
Eric Anholt21d40d32010-03-25 11:11:14 -0700424static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800425 void *response, int response_len,
426 u8 status)
427{
Eric Anholt21d40d32010-03-25 11:11:14 -0700428 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang33b52962009-03-24 14:02:40 +0800429 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800430
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800431 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -0800432 for (i = 0; i < response_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800433 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800434 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800435 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800436 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
yakui_zhao342dc382009-06-02 14:12:00 +0800437 DRM_LOG_KMS("(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800438 else
yakui_zhao342dc382009-06-02 14:12:00 +0800439 DRM_LOG_KMS("(??? %d)", status);
440 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800441}
Jesse Barnes79e53942008-11-07 14:24:08 -0800442
Eric Anholt21d40d32010-03-25 11:11:14 -0700443static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800444 void *response, int response_len)
445{
446 int i;
447 u8 status;
448 u8 retry = 50;
449
450 while (retry--) {
451 /* Read the command response */
452 for (i = 0; i < response_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700453 intel_sdvo_read_byte(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800454 SDVO_I2C_RETURN_0 + i,
455 &((u8 *)response)[i]);
456 }
457
458 /* read the return status */
Eric Anholt21d40d32010-03-25 11:11:14 -0700459 intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS,
Jesse Barnes79e53942008-11-07 14:24:08 -0800460 &status);
461
Eric Anholt21d40d32010-03-25 11:11:14 -0700462 intel_sdvo_debug_response(intel_encoder, response, response_len,
Jesse Barnes79e53942008-11-07 14:24:08 -0800463 status);
464 if (status != SDVO_CMD_STATUS_PENDING)
465 return status;
466
467 mdelay(50);
468 }
469
470 return status;
471}
472
Hannes Ederb358d0a2008-12-18 21:18:47 +0100473static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800474{
475 if (mode->clock >= 100000)
476 return 1;
477 else if (mode->clock >= 50000)
478 return 2;
479 else
480 return 4;
481}
482
483/**
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800484 * Try to read the response after issuie the DDC switch command. But it
485 * is noted that we must do the action of reading response and issuing DDC
486 * switch command in one I2C transaction. Otherwise when we try to start
487 * another I2C transaction after issuing the DDC bus switch, it will be
488 * switched to the internal SDVO register.
Jesse Barnes79e53942008-11-07 14:24:08 -0800489 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700490static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder,
Hannes Ederb358d0a2008-12-18 21:18:47 +0100491 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800492{
Eric Anholt21d40d32010-03-25 11:11:14 -0700493 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800494 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
495 struct i2c_msg msgs[] = {
496 {
497 .addr = sdvo_priv->slave_addr >> 1,
498 .flags = 0,
499 .len = 2,
500 .buf = out_buf,
501 },
502 /* the following two are to read the response */
503 {
504 .addr = sdvo_priv->slave_addr >> 1,
505 .flags = 0,
506 .len = 1,
507 .buf = cmd_buf,
508 },
509 {
510 .addr = sdvo_priv->slave_addr >> 1,
511 .flags = I2C_M_RD,
512 .len = 1,
513 .buf = ret_value,
514 },
515 };
516
Eric Anholt21d40d32010-03-25 11:11:14 -0700517 intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800518 &target, 1);
519 /* write the DDC switch command argument */
Eric Anholt21d40d32010-03-25 11:11:14 -0700520 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800521
522 out_buf[0] = SDVO_I2C_OPCODE;
523 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
524 cmd_buf[0] = SDVO_I2C_CMD_STATUS;
525 cmd_buf[1] = 0;
526 ret_value[0] = 0;
527 ret_value[1] = 0;
528
Eric Anholt21d40d32010-03-25 11:11:14 -0700529 ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800530 if (ret != 3) {
531 /* failure in I2C transfer */
532 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
533 return;
534 }
535 if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
536 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
537 ret_value[0]);
538 return;
539 }
540 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800541}
542
Eric Anholt21d40d32010-03-25 11:11:14 -0700543static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800544{
545 struct intel_sdvo_set_target_input_args targets = {0};
546 u8 status;
547
548 if (target_0 && target_1)
549 return SDVO_CMD_STATUS_NOTSUPP;
550
551 if (target_1)
552 targets.target_1 = 1;
553
Eric Anholt21d40d32010-03-25 11:11:14 -0700554 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets,
Jesse Barnes79e53942008-11-07 14:24:08 -0800555 sizeof(targets));
556
Eric Anholt21d40d32010-03-25 11:11:14 -0700557 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800558
559 return (status == SDVO_CMD_STATUS_SUCCESS);
560}
561
562/**
563 * Return whether each input is trained.
564 *
565 * This function is making an assumption about the layout of the response,
566 * which should be checked against the docs.
567 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700568static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800569{
570 struct intel_sdvo_get_trained_inputs_response response;
571 u8 status;
572
Eric Anholt21d40d32010-03-25 11:11:14 -0700573 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
574 status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response));
Jesse Barnes79e53942008-11-07 14:24:08 -0800575 if (status != SDVO_CMD_STATUS_SUCCESS)
576 return false;
577
578 *input_1 = response.input0_trained;
579 *input_2 = response.input1_trained;
580 return true;
581}
582
Eric Anholt21d40d32010-03-25 11:11:14 -0700583static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800584 u16 outputs)
585{
586 u8 status;
587
Eric Anholt21d40d32010-03-25 11:11:14 -0700588 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800589 sizeof(outputs));
Eric Anholt21d40d32010-03-25 11:11:14 -0700590 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800591 return (status == SDVO_CMD_STATUS_SUCCESS);
592}
593
Eric Anholt21d40d32010-03-25 11:11:14 -0700594static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800595 int mode)
596{
597 u8 status, state = SDVO_ENCODER_STATE_ON;
598
599 switch (mode) {
600 case DRM_MODE_DPMS_ON:
601 state = SDVO_ENCODER_STATE_ON;
602 break;
603 case DRM_MODE_DPMS_STANDBY:
604 state = SDVO_ENCODER_STATE_STANDBY;
605 break;
606 case DRM_MODE_DPMS_SUSPEND:
607 state = SDVO_ENCODER_STATE_SUSPEND;
608 break;
609 case DRM_MODE_DPMS_OFF:
610 state = SDVO_ENCODER_STATE_OFF;
611 break;
612 }
613
Eric Anholt21d40d32010-03-25 11:11:14 -0700614 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
Jesse Barnes79e53942008-11-07 14:24:08 -0800615 sizeof(state));
Eric Anholt21d40d32010-03-25 11:11:14 -0700616 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800617
618 return (status == SDVO_CMD_STATUS_SUCCESS);
619}
620
Eric Anholt21d40d32010-03-25 11:11:14 -0700621static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800622 int *clock_min,
623 int *clock_max)
624{
625 struct intel_sdvo_pixel_clock_range clocks;
626 u8 status;
627
Eric Anholt21d40d32010-03-25 11:11:14 -0700628 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
Jesse Barnes79e53942008-11-07 14:24:08 -0800629 NULL, 0);
630
Eric Anholt21d40d32010-03-25 11:11:14 -0700631 status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks));
Jesse Barnes79e53942008-11-07 14:24:08 -0800632
633 if (status != SDVO_CMD_STATUS_SUCCESS)
634 return false;
635
636 /* Convert the values from units of 10 kHz to kHz. */
637 *clock_min = clocks.min * 10;
638 *clock_max = clocks.max * 10;
639
640 return true;
641}
642
Eric Anholt21d40d32010-03-25 11:11:14 -0700643static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800644 u16 outputs)
645{
646 u8 status;
647
Eric Anholt21d40d32010-03-25 11:11:14 -0700648 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800649 sizeof(outputs));
650
Eric Anholt21d40d32010-03-25 11:11:14 -0700651 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800652 return (status == SDVO_CMD_STATUS_SUCCESS);
653}
654
Eric Anholt21d40d32010-03-25 11:11:14 -0700655static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800656 struct intel_sdvo_dtd *dtd)
657{
658 u8 status;
659
Eric Anholt21d40d32010-03-25 11:11:14 -0700660 intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1));
661 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800662 if (status != SDVO_CMD_STATUS_SUCCESS)
663 return false;
664
Eric Anholt21d40d32010-03-25 11:11:14 -0700665 intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2));
666 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800667 if (status != SDVO_CMD_STATUS_SUCCESS)
668 return false;
669
670 return true;
671}
672
Eric Anholt21d40d32010-03-25 11:11:14 -0700673static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800674 struct intel_sdvo_dtd *dtd)
675{
Eric Anholt21d40d32010-03-25 11:11:14 -0700676 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800677 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
678}
679
Eric Anholt21d40d32010-03-25 11:11:14 -0700680static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800681 struct intel_sdvo_dtd *dtd)
682{
Eric Anholt21d40d32010-03-25 11:11:14 -0700683 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800684 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
685}
686
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800687static bool
Eric Anholtc751ce42010-03-25 11:48:48 -0700688intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800689 uint16_t clock,
690 uint16_t width,
691 uint16_t height)
692{
693 struct intel_sdvo_preferred_input_timing_args args;
Eric Anholtc751ce42010-03-25 11:48:48 -0700694 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800695 uint8_t status;
696
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800697 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800698 args.clock = clock;
699 args.width = width;
700 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800701 args.interlace = 0;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800702
703 if (sdvo_priv->is_lvds &&
704 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
705 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
706 args.scaled = 1;
707
Eric Anholtc751ce42010-03-25 11:48:48 -0700708 intel_sdvo_write_cmd(intel_encoder,
709 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800710 &args, sizeof(args));
Eric Anholtc751ce42010-03-25 11:48:48 -0700711 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800712 if (status != SDVO_CMD_STATUS_SUCCESS)
713 return false;
714
715 return true;
716}
717
Eric Anholtc751ce42010-03-25 11:48:48 -0700718static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800719 struct intel_sdvo_dtd *dtd)
720{
721 bool status;
722
Eric Anholtc751ce42010-03-25 11:48:48 -0700723 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800724 NULL, 0);
725
Eric Anholtc751ce42010-03-25 11:48:48 -0700726 status = intel_sdvo_read_response(intel_encoder, &dtd->part1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800727 sizeof(dtd->part1));
728 if (status != SDVO_CMD_STATUS_SUCCESS)
729 return false;
730
Eric Anholtc751ce42010-03-25 11:48:48 -0700731 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800732 NULL, 0);
733
Eric Anholtc751ce42010-03-25 11:48:48 -0700734 status = intel_sdvo_read_response(intel_encoder, &dtd->part2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800735 sizeof(dtd->part2));
736 if (status != SDVO_CMD_STATUS_SUCCESS)
737 return false;
738
739 return false;
740}
Jesse Barnes79e53942008-11-07 14:24:08 -0800741
Eric Anholt21d40d32010-03-25 11:11:14 -0700742static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800743{
744 u8 status;
745
Eric Anholt21d40d32010-03-25 11:11:14 -0700746 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
747 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800748 if (status != SDVO_CMD_STATUS_SUCCESS)
749 return false;
750
751 return true;
752}
753
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800754static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
755 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800756{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800757 uint16_t width, height;
758 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
759 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800760
761 width = mode->crtc_hdisplay;
762 height = mode->crtc_vdisplay;
763
764 /* do some mode translations */
765 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
766 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
767
768 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
769 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
770
771 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
772 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
773
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800774 dtd->part1.clock = mode->clock / 10;
775 dtd->part1.h_active = width & 0xff;
776 dtd->part1.h_blank = h_blank_len & 0xff;
777 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800778 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800779 dtd->part1.v_active = height & 0xff;
780 dtd->part1.v_blank = v_blank_len & 0xff;
781 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800782 ((v_blank_len >> 8) & 0xf);
783
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800784 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800785 dtd->part2.h_sync_width = h_sync_len & 0xff;
786 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800787 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800788 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800789 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
790 ((v_sync_len & 0x30) >> 4);
791
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800792 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800793 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800794 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800795 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800796 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800797
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800798 dtd->part2.sdvo_flags = 0;
799 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
800 dtd->part2.reserved = 0;
801}
Jesse Barnes79e53942008-11-07 14:24:08 -0800802
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800803static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
804 struct intel_sdvo_dtd *dtd)
805{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800806 mode->hdisplay = dtd->part1.h_active;
807 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
808 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800809 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800810 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
811 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
812 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
813 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
814
815 mode->vdisplay = dtd->part1.v_active;
816 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
817 mode->vsync_start = mode->vdisplay;
818 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800819 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800820 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
821 mode->vsync_end = mode->vsync_start +
822 (dtd->part2.v_sync_off_width & 0xf);
823 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
824 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
825 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
826
827 mode->clock = dtd->part1.clock * 10;
828
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800829 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800830 if (dtd->part2.dtd_flags & 0x2)
831 mode->flags |= DRM_MODE_FLAG_PHSYNC;
832 if (dtd->part2.dtd_flags & 0x4)
833 mode->flags |= DRM_MODE_FLAG_PVSYNC;
834}
835
Eric Anholtc751ce42010-03-25 11:48:48 -0700836static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800837 struct intel_sdvo_encode *encode)
838{
839 uint8_t status;
840
Eric Anholtc751ce42010-03-25 11:48:48 -0700841 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
842 status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800843 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
844 memset(encode, 0, sizeof(*encode));
845 return false;
846 }
847
848 return true;
849}
850
Eric Anholtc751ce42010-03-25 11:48:48 -0700851static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder,
852 uint8_t mode)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800853{
854 uint8_t status;
855
Eric Anholtc751ce42010-03-25 11:48:48 -0700856 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1);
857 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800858
859 return (status == SDVO_CMD_STATUS_SUCCESS);
860}
861
Eric Anholtc751ce42010-03-25 11:48:48 -0700862static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800863 uint8_t mode)
864{
865 uint8_t status;
866
Eric Anholtc751ce42010-03-25 11:48:48 -0700867 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
868 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800869
870 return (status == SDVO_CMD_STATUS_SUCCESS);
871}
872
873#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -0700874static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800875{
876 int i, j;
877 uint8_t set_buf_index[2];
878 uint8_t av_split;
879 uint8_t buf_size;
880 uint8_t buf[48];
881 uint8_t *pos;
882
Eric Anholtc751ce42010-03-25 11:48:48 -0700883 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
884 intel_sdvo_read_response(encoder, &av_split, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800885
886 for (i = 0; i <= av_split; i++) {
887 set_buf_index[0] = i; set_buf_index[1] = 0;
Eric Anholtc751ce42010-03-25 11:48:48 -0700888 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800889 set_buf_index, 2);
Eric Anholtc751ce42010-03-25 11:48:48 -0700890 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
891 intel_sdvo_read_response(encoder, &buf_size, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800892
893 pos = buf;
894 for (j = 0; j <= buf_size; j += 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700895 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800896 NULL, 0);
Eric Anholtc751ce42010-03-25 11:48:48 -0700897 intel_sdvo_read_response(encoder, pos, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800898 pos += 8;
899 }
900 }
901}
902#endif
903
Eric Anholtc751ce42010-03-25 11:48:48 -0700904static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder,
905 int index,
906 uint8_t *data, int8_t size, uint8_t tx_rate)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800907{
908 uint8_t set_buf_index[2];
909
910 set_buf_index[0] = index;
911 set_buf_index[1] = 0;
912
Eric Anholtc751ce42010-03-25 11:48:48 -0700913 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX,
914 set_buf_index, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800915
916 for (; size > 0; size -= 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700917 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800918 data += 8;
919 }
920
Eric Anholtc751ce42010-03-25 11:48:48 -0700921 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800922}
923
924static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
925{
926 uint8_t csum = 0;
927 int i;
928
929 for (i = 0; i < size; i++)
930 csum += data[i];
931
932 return 0x100 - csum;
933}
934
935#define DIP_TYPE_AVI 0x82
936#define DIP_VERSION_AVI 0x2
937#define DIP_LEN_AVI 13
938
939struct dip_infoframe {
940 uint8_t type;
941 uint8_t version;
942 uint8_t len;
943 uint8_t checksum;
944 union {
945 struct {
946 /* Packet Byte #1 */
947 uint8_t S:2;
948 uint8_t B:2;
949 uint8_t A:1;
950 uint8_t Y:2;
951 uint8_t rsvd1:1;
952 /* Packet Byte #2 */
953 uint8_t R:4;
954 uint8_t M:2;
955 uint8_t C:2;
956 /* Packet Byte #3 */
957 uint8_t SC:2;
958 uint8_t Q:2;
959 uint8_t EC:3;
960 uint8_t ITC:1;
961 /* Packet Byte #4 */
962 uint8_t VIC:7;
963 uint8_t rsvd2:1;
964 /* Packet Byte #5 */
965 uint8_t PR:4;
966 uint8_t rsvd3:4;
967 /* Packet Byte #6~13 */
968 uint16_t top_bar_end;
969 uint16_t bottom_bar_start;
970 uint16_t left_bar_end;
971 uint16_t right_bar_start;
972 } avi;
973 struct {
974 /* Packet Byte #1 */
975 uint8_t channel_count:3;
976 uint8_t rsvd1:1;
977 uint8_t coding_type:4;
978 /* Packet Byte #2 */
979 uint8_t sample_size:2; /* SS0, SS1 */
980 uint8_t sample_frequency:3;
981 uint8_t rsvd2:3;
982 /* Packet Byte #3 */
983 uint8_t coding_type_private:5;
984 uint8_t rsvd3:3;
985 /* Packet Byte #4 */
986 uint8_t channel_allocation;
987 /* Packet Byte #5 */
988 uint8_t rsvd4:3;
989 uint8_t level_shift:4;
990 uint8_t downmix_inhibit:1;
991 } audio;
992 uint8_t payload[28];
993 } __attribute__ ((packed)) u;
994} __attribute__((packed));
995
Eric Anholtc751ce42010-03-25 11:48:48 -0700996static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800997 struct drm_display_mode * mode)
998{
999 struct dip_infoframe avi_if = {
1000 .type = DIP_TYPE_AVI,
1001 .version = DIP_VERSION_AVI,
1002 .len = DIP_LEN_AVI,
1003 };
1004
1005 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
1006 4 + avi_if.len);
Eric Anholtc751ce42010-03-25 11:48:48 -07001007 intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if,
1008 4 + avi_if.len,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001009 SDVO_HBUF_TX_VSYNC);
1010}
1011
Eric Anholtc751ce42010-03-25 11:48:48 -07001012static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001013{
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001014
Zhao Yakuice6feab2009-08-24 13:50:26 +08001015 struct intel_sdvo_tv_format format;
Eric Anholtc751ce42010-03-25 11:48:48 -07001016 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001017 uint32_t format_map, i;
1018 uint8_t status;
1019
1020 for (i = 0; i < TV_FORMAT_NUM; i++)
1021 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1022 break;
1023
1024 format_map = 1 << i;
1025 memset(&format, 0, sizeof(format));
1026 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
1027 sizeof(format) : sizeof(format_map));
1028
Eric Anholtc751ce42010-03-25 11:48:48 -07001029 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format_map,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001030 sizeof(format));
1031
Eric Anholtc751ce42010-03-25 11:48:48 -07001032 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001033 if (status != SDVO_CMD_STATUS_SUCCESS)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001034 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
Zhao Yakuice6feab2009-08-24 13:50:26 +08001035 SDVO_NAME(sdvo_priv));
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001036}
1037
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001038static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1039 struct drm_display_mode *mode,
1040 struct drm_display_mode *adjusted_mode)
1041{
Eric Anholtc751ce42010-03-25 11:48:48 -07001042 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1043 struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001044
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001045 if (dev_priv->is_tv) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001046 struct intel_sdvo_dtd output_dtd;
1047 bool success;
1048
1049 /* We need to construct preferred input timings based on our
1050 * output timings. To do that, we have to set the output
1051 * timings, even though this isn't really the right place in
1052 * the sequence to do it. Oh well.
1053 */
1054
1055
1056 /* Set output timings */
1057 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
Eric Anholtc751ce42010-03-25 11:48:48 -07001058 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001059 dev_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001060 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001061
1062 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001063 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001064
1065
Eric Anholtc751ce42010-03-25 11:48:48 -07001066 success = intel_sdvo_create_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001067 mode->clock / 10,
1068 mode->hdisplay,
1069 mode->vdisplay);
1070 if (success) {
1071 struct intel_sdvo_dtd input_dtd;
1072
Eric Anholtc751ce42010-03-25 11:48:48 -07001073 intel_sdvo_get_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001074 &input_dtd);
1075 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001076 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001077
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001078 drm_mode_set_crtcinfo(adjusted_mode, 0);
1079
1080 mode->clock = adjusted_mode->clock;
1081
1082 adjusted_mode->clock *=
1083 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001084 } else {
1085 return false;
1086 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001087 } else if (dev_priv->is_lvds) {
1088 struct intel_sdvo_dtd output_dtd;
1089 bool success;
1090
1091 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1092 /* Set output timings */
1093 intel_sdvo_get_dtd_from_mode(&output_dtd,
1094 dev_priv->sdvo_lvds_fixed_mode);
1095
Eric Anholtc751ce42010-03-25 11:48:48 -07001096 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001097 dev_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001098 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001099
1100 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001101 intel_sdvo_set_target_input(intel_encoder, true, false);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001102
1103
1104 success = intel_sdvo_create_preferred_input_timing(
Eric Anholtc751ce42010-03-25 11:48:48 -07001105 intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001106 mode->clock / 10,
1107 mode->hdisplay,
1108 mode->vdisplay);
1109
1110 if (success) {
1111 struct intel_sdvo_dtd input_dtd;
1112
Eric Anholtc751ce42010-03-25 11:48:48 -07001113 intel_sdvo_get_preferred_input_timing(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001114 &input_dtd);
1115 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1116 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1117
1118 drm_mode_set_crtcinfo(adjusted_mode, 0);
1119
1120 mode->clock = adjusted_mode->clock;
1121
1122 adjusted_mode->clock *=
1123 intel_sdvo_get_pixel_multiplier(mode);
1124 } else {
1125 return false;
1126 }
1127
1128 } else {
1129 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1130 * SDVO device will be told of the multiplier during mode_set.
1131 */
1132 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001133 }
1134 return true;
1135}
1136
1137static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1138 struct drm_display_mode *mode,
1139 struct drm_display_mode *adjusted_mode)
1140{
1141 struct drm_device *dev = encoder->dev;
1142 struct drm_i915_private *dev_priv = dev->dev_private;
1143 struct drm_crtc *crtc = encoder->crtc;
1144 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Eric Anholtc751ce42010-03-25 11:48:48 -07001145 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1146 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001147 u32 sdvox = 0;
1148 int sdvo_pixel_multiply;
1149 struct intel_sdvo_in_out_map in_out;
1150 struct intel_sdvo_dtd input_dtd;
1151 u8 status;
1152
1153 if (!mode)
1154 return;
1155
1156 /* First, set the input mapping for the first input to our controlled
1157 * output. This is only correct if we're a single-input device, in
1158 * which case the first input is the output from the appropriate SDVO
1159 * channel on the motherboard. In a two-input device, the first input
1160 * will be SDVOB and the second SDVOC.
1161 */
Zhenyu Wang14571b42010-03-30 14:06:33 +08001162 in_out.in0 = sdvo_priv->attached_output;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001163 in_out.in1 = 0;
1164
Eric Anholtc751ce42010-03-25 11:48:48 -07001165 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001166 &in_out, sizeof(in_out));
Eric Anholtc751ce42010-03-25 11:48:48 -07001167 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001168
1169 if (sdvo_priv->is_hdmi) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001170 intel_sdvo_set_avi_infoframe(intel_encoder, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001171 sdvox |= SDVO_AUDIO_ENABLE;
1172 }
1173
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001174 /* We have tried to get input timing in mode_fixup, and filled into
1175 adjusted_mode */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001176 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001177 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001178 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
1179 } else
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001180 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001181
1182 /* If it's a TV, we already set the output timing in mode_fixup.
1183 * Otherwise, the output timing is equal to the input timing.
1184 */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001185 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001186 /* Set the output timing to the screen */
Eric Anholtc751ce42010-03-25 11:48:48 -07001187 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001188 sdvo_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001189 intel_sdvo_set_output_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001190 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001191
1192 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001193 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001194
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001195 if (sdvo_priv->is_tv)
Eric Anholtc751ce42010-03-25 11:48:48 -07001196 intel_sdvo_set_tv_format(intel_encoder);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001197
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001198 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001199 * provide the device with a timing it can support, if it supports that
1200 * feature. However, presumably we would need to adjust the CRTC to
1201 * output the preferred timing, and we don't support that currently.
1202 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001203#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -07001204 success = intel_sdvo_create_preferred_input_timing(encoder, clock,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001205 width, height);
1206 if (success) {
1207 struct intel_sdvo_dtd *input_dtd;
1208
Eric Anholtc751ce42010-03-25 11:48:48 -07001209 intel_sdvo_get_preferred_input_timing(encoder, &input_dtd);
1210 intel_sdvo_set_input_timing(encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001211 }
1212#else
Eric Anholtc751ce42010-03-25 11:48:48 -07001213 intel_sdvo_set_input_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001214#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001215
1216 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1217 case 1:
Eric Anholtc751ce42010-03-25 11:48:48 -07001218 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001219 SDVO_CLOCK_RATE_MULT_1X);
1220 break;
1221 case 2:
Eric Anholtc751ce42010-03-25 11:48:48 -07001222 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001223 SDVO_CLOCK_RATE_MULT_2X);
1224 break;
1225 case 4:
Eric Anholtc751ce42010-03-25 11:48:48 -07001226 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001227 SDVO_CLOCK_RATE_MULT_4X);
1228 break;
1229 }
1230
1231 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001232 if (IS_I965G(dev)) {
1233 sdvox |= SDVO_BORDER_ENABLE |
1234 SDVO_VSYNC_ACTIVE_HIGH |
1235 SDVO_HSYNC_ACTIVE_HIGH;
1236 } else {
Eric Anholtc751ce42010-03-25 11:48:48 -07001237 sdvox |= I915_READ(sdvo_priv->sdvo_reg);
1238 switch (sdvo_priv->sdvo_reg) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001239 case SDVOB:
1240 sdvox &= SDVOB_PRESERVE_MASK;
1241 break;
1242 case SDVOC:
1243 sdvox &= SDVOC_PRESERVE_MASK;
1244 break;
1245 }
1246 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1247 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001248 if (intel_crtc->pipe == 1)
1249 sdvox |= SDVO_PIPE_B_SELECT;
1250
1251 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1252 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001253 /* done in crtc_mode_set as the dpll_md reg must be written early */
1254 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1255 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001256 } else {
1257 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1258 }
1259
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001260 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
1261 sdvox |= SDVO_STALL_SELECT;
Eric Anholtc751ce42010-03-25 11:48:48 -07001262 intel_sdvo_write_sdvox(intel_encoder, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001263}
1264
1265static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1266{
1267 struct drm_device *dev = encoder->dev;
1268 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001269 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1270 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001271 u32 temp;
1272
1273 if (mode != DRM_MODE_DPMS_ON) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001274 intel_sdvo_set_active_outputs(intel_encoder, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -08001275 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001276 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -08001277
1278 if (mode == DRM_MODE_DPMS_OFF) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001279 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001280 if ((temp & SDVO_ENABLE) != 0) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001281 intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001282 }
1283 }
1284 } else {
1285 bool input1, input2;
1286 int i;
1287 u8 status;
1288
Eric Anholtc751ce42010-03-25 11:48:48 -07001289 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001290 if ((temp & SDVO_ENABLE) == 0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001291 intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001292 for (i = 0; i < 2; i++)
1293 intel_wait_for_vblank(dev);
1294
Eric Anholt21d40d32010-03-25 11:11:14 -07001295 status = intel_sdvo_get_trained_inputs(intel_encoder, &input1,
Jesse Barnes79e53942008-11-07 14:24:08 -08001296 &input2);
1297
1298
1299 /* Warn if the device reported failure to sync.
1300 * A lot of SDVO devices fail to notify of sync, but it's
1301 * a given it the status is a success, we succeeded.
1302 */
1303 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001304 DRM_DEBUG_KMS("First %s output reported failure to "
1305 "sync\n", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -08001306 }
1307
1308 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001309 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001310 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001311 }
1312 return;
1313}
1314
Jesse Barnes79e53942008-11-07 14:24:08 -08001315static int intel_sdvo_mode_valid(struct drm_connector *connector,
1316 struct drm_display_mode *mode)
1317{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001318 struct drm_encoder *encoder = intel_attached_encoder(connector);
1319 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001320 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001321
1322 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1323 return MODE_NO_DBLESCAN;
1324
1325 if (sdvo_priv->pixel_clock_min > mode->clock)
1326 return MODE_CLOCK_LOW;
1327
1328 if (sdvo_priv->pixel_clock_max < mode->clock)
1329 return MODE_CLOCK_HIGH;
1330
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001331 if (sdvo_priv->is_lvds == true) {
1332 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
1333 return MODE_PANEL;
1334
1335 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
1336 return MODE_PANEL;
1337
1338 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1339 return MODE_PANEL;
1340 }
1341
Jesse Barnes79e53942008-11-07 14:24:08 -08001342 return MODE_OK;
1343}
1344
Eric Anholt21d40d32010-03-25 11:11:14 -07001345static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps)
Jesse Barnes79e53942008-11-07 14:24:08 -08001346{
1347 u8 status;
1348
Eric Anholt21d40d32010-03-25 11:11:14 -07001349 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1350 status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps));
Jesse Barnes79e53942008-11-07 14:24:08 -08001351 if (status != SDVO_CMD_STATUS_SUCCESS)
1352 return false;
1353
1354 return true;
1355}
1356
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001357/* No use! */
1358#if 0
Jesse Barnes79e53942008-11-07 14:24:08 -08001359struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1360{
1361 struct drm_connector *connector = NULL;
Eric Anholt21d40d32010-03-25 11:11:14 -07001362 struct intel_encoder *iout = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001363 struct intel_sdvo_priv *sdvo;
1364
1365 /* find the sdvo connector */
1366 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001367 iout = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001368
1369 if (iout->type != INTEL_OUTPUT_SDVO)
1370 continue;
1371
1372 sdvo = iout->dev_priv;
1373
Eric Anholtc751ce42010-03-25 11:48:48 -07001374 if (sdvo->sdvo_reg == SDVOB && sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001375 return connector;
1376
Eric Anholtc751ce42010-03-25 11:48:48 -07001377 if (sdvo->sdvo_reg == SDVOC && !sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001378 return connector;
1379
1380 }
1381
1382 return NULL;
1383}
1384
1385int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1386{
1387 u8 response[2];
1388 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001389 struct intel_encoder *intel_encoder;
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001390 DRM_DEBUG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -08001391
1392 if (!connector)
1393 return 0;
1394
Eric Anholt21d40d32010-03-25 11:11:14 -07001395 intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001396
Eric Anholt21d40d32010-03-25 11:11:14 -07001397 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1398 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001399
1400 if (response[0] !=0)
1401 return 1;
1402
1403 return 0;
1404}
1405
1406void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1407{
1408 u8 response[2];
1409 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001410 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001411
Eric Anholt21d40d32010-03-25 11:11:14 -07001412 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1413 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001414
1415 if (on) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001416 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1417 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001418
Eric Anholt21d40d32010-03-25 11:11:14 -07001419 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001420 } else {
1421 response[0] = 0;
1422 response[1] = 0;
Eric Anholt21d40d32010-03-25 11:11:14 -07001423 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001424 }
1425
Eric Anholt21d40d32010-03-25 11:11:14 -07001426 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1427 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001428}
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001429#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001430
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001431static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07001432intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001433{
Eric Anholt21d40d32010-03-25 11:11:14 -07001434 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001435 int caps = 0;
1436
1437 if (sdvo_priv->caps.output_flags &
1438 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1439 caps++;
1440 if (sdvo_priv->caps.output_flags &
1441 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1442 caps++;
1443 if (sdvo_priv->caps.output_flags &
Roel Kluin19e1f882009-08-09 13:50:53 +02001444 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001445 caps++;
1446 if (sdvo_priv->caps.output_flags &
1447 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1448 caps++;
1449 if (sdvo_priv->caps.output_flags &
1450 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1451 caps++;
1452
1453 if (sdvo_priv->caps.output_flags &
1454 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1455 caps++;
1456
1457 if (sdvo_priv->caps.output_flags &
1458 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1459 caps++;
1460
1461 return (caps > 1);
1462}
1463
Keith Packard57cdaf92009-09-04 13:07:54 +08001464static struct drm_connector *
1465intel_find_analog_connector(struct drm_device *dev)
1466{
1467 struct drm_connector *connector;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001468 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07001469 struct intel_encoder *intel_encoder;
Keith Packard57cdaf92009-09-04 13:07:54 +08001470
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001471 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1472 intel_encoder = enc_to_intel_encoder(encoder);
1473 if (intel_encoder->type == INTEL_OUTPUT_ANALOG) {
1474 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1475 if (connector && encoder == intel_attached_encoder(connector))
1476 return connector;
1477 }
1478 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001479 }
1480 return NULL;
1481}
1482
1483static int
1484intel_analog_is_connected(struct drm_device *dev)
1485{
1486 struct drm_connector *analog_connector;
1487 analog_connector = intel_find_analog_connector(dev);
1488
1489 if (!analog_connector)
1490 return false;
1491
1492 if (analog_connector->funcs->detect(analog_connector) ==
1493 connector_status_disconnected)
1494 return false;
1495
1496 return true;
1497}
1498
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001499enum drm_connector_status
1500intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
Ma Ling9dff6af2009-04-02 13:13:26 +08001501{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001502 struct drm_encoder *encoder = intel_attached_encoder(connector);
1503 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001504 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001505 enum drm_connector_status status = connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001506 struct edid *edid = NULL;
1507
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001508 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001509 intel_encoder->ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001510
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001511 /* This is only applied to SDVO cards with multiple outputs */
Eric Anholt21d40d32010-03-25 11:11:14 -07001512 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) {
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001513 uint8_t saved_ddc, temp_ddc;
1514 saved_ddc = sdvo_priv->ddc_bus;
1515 temp_ddc = sdvo_priv->ddc_bus >> 1;
1516 /*
1517 * Don't use the 1 as the argument of DDC bus switch to get
1518 * the EDID. It is used for SDVO SPD ROM.
1519 */
1520 while(temp_ddc > 1) {
1521 sdvo_priv->ddc_bus = temp_ddc;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001522 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001523 intel_encoder->ddc_bus);
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001524 if (edid) {
1525 /*
1526 * When we can get the EDID, maybe it is the
1527 * correct DDC bus. Update it.
1528 */
1529 sdvo_priv->ddc_bus = temp_ddc;
1530 break;
1531 }
1532 temp_ddc >>= 1;
1533 }
1534 if (edid == NULL)
1535 sdvo_priv->ddc_bus = saved_ddc;
1536 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001537 /* when there is no edid and no monitor is connected with VGA
1538 * port, try to use the CRT ddc to read the EDID for DVI-connector
1539 */
1540 if (edid == NULL &&
1541 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001542 !intel_analog_is_connected(connector->dev))
1543 edid = drm_get_edid(connector,
Keith Packard57cdaf92009-09-04 13:07:54 +08001544 sdvo_priv->analog_ddc_bus);
Ma Ling9dff6af2009-04-02 13:13:26 +08001545 if (edid != NULL) {
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001546 /* Don't report the output as connected if it's a DVI-I
1547 * connector with a non-digital EDID coming out.
1548 */
1549 if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
1550 if (edid->input & DRM_EDID_INPUT_DIGITAL)
1551 sdvo_priv->is_hdmi =
1552 drm_detect_hdmi_monitor(edid);
1553 else
1554 status = connector_status_disconnected;
1555 }
1556
Ma Ling9dff6af2009-04-02 13:13:26 +08001557 kfree(edid);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001558 connector->display_info.raw_edid = NULL;
ling.ma@intel.com2b8d33f72009-07-29 11:31:18 +08001559
1560 } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1561 status = connector_status_disconnected;
1562
1563 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +08001564}
1565
Jesse Barnes79e53942008-11-07 14:24:08 -08001566static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1567{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001568 uint16_t response;
Jesse Barnes79e53942008-11-07 14:24:08 -08001569 u8 status;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001570 struct drm_encoder *encoder = intel_attached_encoder(connector);
1571 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1572 struct intel_connector *intel_connector = to_intel_connector(connector);
Eric Anholt21d40d32010-03-25 11:11:14 -07001573 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001574 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1575 enum drm_connector_status ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001576
Eric Anholt21d40d32010-03-25 11:11:14 -07001577 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001578 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
Zhao Yakuid09c23d2009-11-06 15:39:56 +08001579 if (sdvo_priv->is_tv) {
1580 /* add 30ms delay when the output type is SDVO-TV */
1581 mdelay(30);
1582 }
Eric Anholt21d40d32010-03-25 11:11:14 -07001583 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001584
Dave Airlie51c8b402009-08-20 13:38:04 +10001585 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001586
1587 if (status != SDVO_CMD_STATUS_SUCCESS)
1588 return connector_status_unknown;
1589
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001590 if (response == 0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001591 return connector_status_disconnected;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001592
Zhenyu Wang14571b42010-03-30 14:06:33 +08001593 sdvo_priv->attached_output = response;
1594
1595 if ((sdvo_connector->output_flag & response) == 0)
1596 ret = connector_status_disconnected;
1597 else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1598 ret = intel_sdvo_hdmi_sink_detect(connector, response);
1599 else
1600 ret = connector_status_connected;
1601
1602 /* May update encoder flag for like clock for SDVO TV, etc.*/
1603 if (ret == connector_status_connected) {
1604 sdvo_priv->is_tv = false;
1605 sdvo_priv->is_lvds = false;
1606 intel_encoder->needs_tv_clock = false;
1607
1608 if (response & SDVO_TV_MASK) {
1609 sdvo_priv->is_tv = true;
1610 intel_encoder->needs_tv_clock = true;
1611 }
1612 if (response & SDVO_LVDS_MASK)
1613 sdvo_priv->is_lvds = true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001614 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001615
1616 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001617}
1618
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001619static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001620{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001621 struct drm_encoder *encoder = intel_attached_encoder(connector);
1622 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001623 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Keith Packard57cdaf92009-09-04 13:07:54 +08001624 int num_modes;
Jesse Barnes79e53942008-11-07 14:24:08 -08001625
1626 /* set the bus switch and get the modes */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001627 num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001628
Keith Packard57cdaf92009-09-04 13:07:54 +08001629 /*
1630 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1631 * link between analog and digital outputs. So, if the regular SDVO
1632 * DDC fails, check to see if the analog output is disconnected, in
1633 * which case we'll look there for the digital DDC data.
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001634 */
Keith Packard57cdaf92009-09-04 13:07:54 +08001635 if (num_modes == 0 &&
1636 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001637 !intel_analog_is_connected(connector->dev)) {
Keith Packard57cdaf92009-09-04 13:07:54 +08001638 /* Switch to the analog ddc bus and try that
1639 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001640 (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001641 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001642}
1643
1644/*
1645 * Set of SDVO TV modes.
1646 * Note! This is in reply order (see loop in get_tv_modes).
1647 * XXX: all 60Hz refresh?
1648 */
1649struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001650 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1651 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001652 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001653 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1654 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001655 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001656 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1657 496, 0, 300, 301, 332, 333, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001658 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001659 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1660 736, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001661 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001662 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1663 736, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001664 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001665 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1666 736, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001667 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001668 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1669 800, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001670 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001671 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1672 800, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001673 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001674 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1675 816, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001676 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001677 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1678 816, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001679 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001680 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1681 816, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001682 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001683 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1684 816, 0, 540, 541, 572, 573, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001685 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001686 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1687 816, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001688 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001689 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1690 864, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001691 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001692 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1693 896, 0, 600, 601, 632, 633, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001694 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001695 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1696 928, 0, 624, 625, 656, 657, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001697 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001698 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1699 1016, 0, 766, 767, 798, 799, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001700 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001701 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1702 1120, 0, 768, 769, 800, 801, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001703 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001704 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1705 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001706 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1707};
1708
1709static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1710{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001711 struct drm_encoder *encoder = intel_attached_encoder(connector);
1712 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1713 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001714 struct intel_sdvo_sdtv_resolution_request tv_res;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001715 uint32_t reply = 0, format_map = 0;
1716 int i;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001717 uint8_t status;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001718
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001719
1720 /* Read the list of supported input resolutions for the selected TV
1721 * format.
1722 */
Zhao Yakuice6feab2009-08-24 13:50:26 +08001723 for (i = 0; i < TV_FORMAT_NUM; i++)
1724 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1725 break;
1726
1727 format_map = (1 << i);
1728 memcpy(&tv_res, &format_map,
1729 sizeof(struct intel_sdvo_sdtv_resolution_request) >
1730 sizeof(format_map) ? sizeof(format_map) :
1731 sizeof(struct intel_sdvo_sdtv_resolution_request));
1732
Zhenyu Wang14571b42010-03-30 14:06:33 +08001733 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001734
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001735 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001736 &tv_res, sizeof(tv_res));
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001737 status = intel_sdvo_read_response(intel_encoder, &reply, 3);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001738 if (status != SDVO_CMD_STATUS_SUCCESS)
1739 return;
1740
1741 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001742 if (reply & (1 << i)) {
1743 struct drm_display_mode *nmode;
1744 nmode = drm_mode_duplicate(connector->dev,
1745 &sdvo_tv_modes[i]);
1746 if (nmode)
1747 drm_mode_probed_add(connector, nmode);
1748 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001749
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001750}
1751
Ma Ling7086c872009-05-13 11:20:06 +08001752static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1753{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001754 struct drm_encoder *encoder = intel_attached_encoder(connector);
1755 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Ma Ling7086c872009-05-13 11:20:06 +08001756 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001757 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001758 struct drm_display_mode *newmode;
Ma Ling7086c872009-05-13 11:20:06 +08001759
1760 /*
1761 * Attempt to get the mode list from DDC.
1762 * Assume that the preferred modes are
1763 * arranged in priority order.
1764 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001765 intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Ma Ling7086c872009-05-13 11:20:06 +08001766 if (list_empty(&connector->probed_modes) == false)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001767 goto end;
Ma Ling7086c872009-05-13 11:20:06 +08001768
1769 /* Fetch modes from VBT */
1770 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
Ma Ling7086c872009-05-13 11:20:06 +08001771 newmode = drm_mode_duplicate(connector->dev,
1772 dev_priv->sdvo_lvds_vbt_mode);
1773 if (newmode != NULL) {
1774 /* Guarantee the mode is preferred */
1775 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1776 DRM_MODE_TYPE_DRIVER);
1777 drm_mode_probed_add(connector, newmode);
1778 }
1779 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001780
1781end:
1782 list_for_each_entry(newmode, &connector->probed_modes, head) {
1783 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1784 sdvo_priv->sdvo_lvds_fixed_mode =
1785 drm_mode_duplicate(connector->dev, newmode);
1786 break;
1787 }
1788 }
1789
Ma Ling7086c872009-05-13 11:20:06 +08001790}
1791
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001792static int intel_sdvo_get_modes(struct drm_connector *connector)
1793{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001794 struct intel_connector *intel_connector = to_intel_connector(connector);
1795 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001796
Zhenyu Wang14571b42010-03-30 14:06:33 +08001797 if (IS_TV(sdvo_connector))
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001798 intel_sdvo_get_tv_modes(connector);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001799 else if (IS_LVDS(sdvo_connector))
Ma Ling7086c872009-05-13 11:20:06 +08001800 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001801 else
1802 intel_sdvo_get_ddc_modes(connector);
1803
Jesse Barnes79e53942008-11-07 14:24:08 -08001804 if (list_empty(&connector->probed_modes))
1805 return 0;
1806 return 1;
1807}
1808
Zhao Yakuib9219c52009-09-10 15:45:46 +08001809static
1810void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1811{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001812 struct intel_connector *intel_connector = to_intel_connector(connector);
1813 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
1814 struct drm_device *dev = connector->dev;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001815
Zhenyu Wang14571b42010-03-30 14:06:33 +08001816 if (IS_TV(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001817 if (sdvo_priv->left_property)
1818 drm_property_destroy(dev, sdvo_priv->left_property);
1819 if (sdvo_priv->right_property)
1820 drm_property_destroy(dev, sdvo_priv->right_property);
1821 if (sdvo_priv->top_property)
1822 drm_property_destroy(dev, sdvo_priv->top_property);
1823 if (sdvo_priv->bottom_property)
1824 drm_property_destroy(dev, sdvo_priv->bottom_property);
1825 if (sdvo_priv->hpos_property)
1826 drm_property_destroy(dev, sdvo_priv->hpos_property);
1827 if (sdvo_priv->vpos_property)
1828 drm_property_destroy(dev, sdvo_priv->vpos_property);
Zhao Yakuib9219c52009-09-10 15:45:46 +08001829 if (sdvo_priv->saturation_property)
1830 drm_property_destroy(dev,
1831 sdvo_priv->saturation_property);
1832 if (sdvo_priv->contrast_property)
1833 drm_property_destroy(dev,
1834 sdvo_priv->contrast_property);
1835 if (sdvo_priv->hue_property)
1836 drm_property_destroy(dev, sdvo_priv->hue_property);
1837 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001838 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001839 if (sdvo_priv->brightness_property)
1840 drm_property_destroy(dev,
1841 sdvo_priv->brightness_property);
1842 }
1843 return;
1844}
1845
Jesse Barnes79e53942008-11-07 14:24:08 -08001846static void intel_sdvo_destroy(struct drm_connector *connector)
1847{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001848 struct intel_connector *intel_connector = to_intel_connector(connector);
1849 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1850
1851 if (sdvo_connector->tv_format_property)
1852 drm_property_destroy(connector->dev,
1853 sdvo_connector->tv_format_property);
1854
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001855 intel_sdvo_destroy_enhance_property(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001856 drm_sysfs_connector_remove(connector);
1857 drm_connector_cleanup(connector);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001858 kfree(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001859}
1860
Zhao Yakuice6feab2009-08-24 13:50:26 +08001861static int
1862intel_sdvo_set_property(struct drm_connector *connector,
1863 struct drm_property *property,
1864 uint64_t val)
1865{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001866 struct drm_encoder *encoder = intel_attached_encoder(connector);
1867 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001868 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001869 struct intel_connector *intel_connector = to_intel_connector(connector);
1870 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001871 struct drm_crtc *crtc = encoder->crtc;
1872 int ret = 0;
1873 bool changed = false;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001874 uint8_t cmd, status;
1875 uint16_t temp_value;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001876
1877 ret = drm_connector_property_set_value(connector, property, val);
1878 if (ret < 0)
1879 goto out;
1880
Zhenyu Wang14571b42010-03-30 14:06:33 +08001881 if (property == sdvo_connector->tv_format_property) {
Zhao Yakuice6feab2009-08-24 13:50:26 +08001882 if (val >= TV_FORMAT_NUM) {
1883 ret = -EINVAL;
1884 goto out;
1885 }
1886 if (sdvo_priv->tv_format_name ==
Zhenyu Wang14571b42010-03-30 14:06:33 +08001887 sdvo_connector->tv_format_supported[val])
Zhao Yakuice6feab2009-08-24 13:50:26 +08001888 goto out;
1889
Zhenyu Wang14571b42010-03-30 14:06:33 +08001890 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val];
Zhao Yakuice6feab2009-08-24 13:50:26 +08001891 changed = true;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001892 }
1893
Zhenyu Wang14571b42010-03-30 14:06:33 +08001894 if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001895 cmd = 0;
1896 temp_value = val;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001897 if (sdvo_connector->left_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001898 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001899 sdvo_connector->right_property, val);
1900 if (sdvo_connector->left_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001901 goto out;
1902
Zhenyu Wang14571b42010-03-30 14:06:33 +08001903 sdvo_connector->left_margin = temp_value;
1904 sdvo_connector->right_margin = temp_value;
1905 temp_value = sdvo_connector->max_hscan -
1906 sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001907 cmd = SDVO_CMD_SET_OVERSCAN_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001908 } else if (sdvo_connector->right_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001909 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001910 sdvo_connector->left_property, val);
1911 if (sdvo_connector->right_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001912 goto out;
1913
Zhenyu Wang14571b42010-03-30 14:06:33 +08001914 sdvo_connector->left_margin = temp_value;
1915 sdvo_connector->right_margin = temp_value;
1916 temp_value = sdvo_connector->max_hscan -
1917 sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001918 cmd = SDVO_CMD_SET_OVERSCAN_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001919 } else if (sdvo_connector->top_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001920 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001921 sdvo_connector->bottom_property, val);
1922 if (sdvo_connector->top_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001923 goto out;
1924
Zhenyu Wang14571b42010-03-30 14:06:33 +08001925 sdvo_connector->top_margin = temp_value;
1926 sdvo_connector->bottom_margin = temp_value;
1927 temp_value = sdvo_connector->max_vscan -
1928 sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001929 cmd = SDVO_CMD_SET_OVERSCAN_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001930 } else if (sdvo_connector->bottom_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001931 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001932 sdvo_connector->top_property, val);
1933 if (sdvo_connector->bottom_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001934 goto out;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001935 sdvo_connector->top_margin = temp_value;
1936 sdvo_connector->bottom_margin = temp_value;
1937 temp_value = sdvo_connector->max_vscan -
1938 sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001939 cmd = SDVO_CMD_SET_OVERSCAN_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001940 } else if (sdvo_connector->hpos_property == property) {
1941 if (sdvo_connector->cur_hpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001942 goto out;
1943
1944 cmd = SDVO_CMD_SET_POSITION_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001945 sdvo_connector->cur_hpos = temp_value;
1946 } else if (sdvo_connector->vpos_property == property) {
1947 if (sdvo_connector->cur_vpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001948 goto out;
1949
1950 cmd = SDVO_CMD_SET_POSITION_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001951 sdvo_connector->cur_vpos = temp_value;
1952 } else if (sdvo_connector->saturation_property == property) {
1953 if (sdvo_connector->cur_saturation == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001954 goto out;
1955
1956 cmd = SDVO_CMD_SET_SATURATION;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001957 sdvo_connector->cur_saturation = temp_value;
1958 } else if (sdvo_connector->contrast_property == property) {
1959 if (sdvo_connector->cur_contrast == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001960 goto out;
1961
1962 cmd = SDVO_CMD_SET_CONTRAST;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001963 sdvo_connector->cur_contrast = temp_value;
1964 } else if (sdvo_connector->hue_property == property) {
1965 if (sdvo_connector->cur_hue == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001966 goto out;
1967
1968 cmd = SDVO_CMD_SET_HUE;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001969 sdvo_connector->cur_hue = temp_value;
1970 } else if (sdvo_connector->brightness_property == property) {
1971 if (sdvo_connector->cur_brightness == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001972 goto out;
1973
1974 cmd = SDVO_CMD_SET_BRIGHTNESS;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001975 sdvo_connector->cur_brightness = temp_value;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001976 }
1977 if (cmd) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001978 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
1979 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08001980 NULL, 0);
1981 if (status != SDVO_CMD_STATUS_SUCCESS) {
1982 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1983 return -EINVAL;
1984 }
1985 changed = true;
1986 }
1987 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001988 if (changed && crtc)
1989 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1990 crtc->y, crtc->fb);
1991out:
1992 return ret;
1993}
1994
Jesse Barnes79e53942008-11-07 14:24:08 -08001995static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1996 .dpms = intel_sdvo_dpms,
1997 .mode_fixup = intel_sdvo_mode_fixup,
1998 .prepare = intel_encoder_prepare,
1999 .mode_set = intel_sdvo_mode_set,
2000 .commit = intel_encoder_commit,
2001};
2002
2003static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -07002004 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -08002005 .detect = intel_sdvo_detect,
2006 .fill_modes = drm_helper_probe_single_connector_modes,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002007 .set_property = intel_sdvo_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -08002008 .destroy = intel_sdvo_destroy,
2009};
2010
2011static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2012 .get_modes = intel_sdvo_get_modes,
2013 .mode_valid = intel_sdvo_mode_valid,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002014 .best_encoder = intel_attached_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002015};
2016
Hannes Ederb358d0a2008-12-18 21:18:47 +01002017static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08002018{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002019 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
2020 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2021
2022 if (intel_encoder->i2c_bus)
2023 intel_i2c_destroy(intel_encoder->i2c_bus);
2024 if (intel_encoder->ddc_bus)
2025 intel_i2c_destroy(intel_encoder->ddc_bus);
2026 if (sdvo_priv->analog_ddc_bus)
2027 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
2028
2029 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
2030 drm_mode_destroy(encoder->dev,
2031 sdvo_priv->sdvo_lvds_fixed_mode);
2032
Jesse Barnes79e53942008-11-07 14:24:08 -08002033 drm_encoder_cleanup(encoder);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002034 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002035}
2036
2037static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2038 .destroy = intel_sdvo_enc_destroy,
2039};
2040
2041
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002042/**
2043 * Choose the appropriate DDC bus for control bus switch command for this
2044 * SDVO output based on the controlled output.
2045 *
2046 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2047 * outputs, then LVDS outputs.
2048 */
2049static void
2050intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
2051{
2052 uint16_t mask = 0;
2053 unsigned int num_bits;
2054
2055 /* Make a mask of outputs less than or equal to our own priority in the
2056 * list.
2057 */
2058 switch (dev_priv->controlled_output) {
2059 case SDVO_OUTPUT_LVDS1:
2060 mask |= SDVO_OUTPUT_LVDS1;
2061 case SDVO_OUTPUT_LVDS0:
2062 mask |= SDVO_OUTPUT_LVDS0;
2063 case SDVO_OUTPUT_TMDS1:
2064 mask |= SDVO_OUTPUT_TMDS1;
2065 case SDVO_OUTPUT_TMDS0:
2066 mask |= SDVO_OUTPUT_TMDS0;
2067 case SDVO_OUTPUT_RGB1:
2068 mask |= SDVO_OUTPUT_RGB1;
2069 case SDVO_OUTPUT_RGB0:
2070 mask |= SDVO_OUTPUT_RGB0;
2071 break;
2072 }
2073
2074 /* Count bits to find what number we are in the priority list. */
2075 mask &= dev_priv->caps.output_flags;
2076 num_bits = hweight16(mask);
2077 if (num_bits > 3) {
2078 /* if more than 3 outputs, default to DDC bus 3 for now */
2079 num_bits = 3;
2080 }
2081
2082 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2083 dev_priv->ddc_bus = 1 << num_bits;
2084}
2085
2086static bool
Zhenyu Wang14571b42010-03-30 14:06:33 +08002087intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002088{
2089 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
2090 uint8_t status;
2091
Zhenyu Wang14571b42010-03-30 14:06:33 +08002092 if (device == 0)
2093 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0);
2094 else
2095 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002096
2097 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2098 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
2099 if (status != SDVO_CMD_STATUS_SUCCESS)
2100 return false;
2101 return true;
2102}
2103
Eric Anholt21d40d32010-03-25 11:11:14 -07002104static struct intel_encoder *
2105intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan)
Ma Ling619ac3b2009-05-18 16:12:46 +08002106{
2107 struct drm_device *dev = chan->drm_dev;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002108 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07002109 struct intel_encoder *intel_encoder = NULL;
Ma Ling619ac3b2009-05-18 16:12:46 +08002110
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002111 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2112 intel_encoder = enc_to_intel_encoder(encoder);
2113 if (intel_encoder->ddc_bus == &chan->adapter)
Ma Ling619ac3b2009-05-18 16:12:46 +08002114 break;
Ma Ling619ac3b2009-05-18 16:12:46 +08002115 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002116 return intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002117}
2118
2119static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2120 struct i2c_msg msgs[], int num)
2121{
Eric Anholt21d40d32010-03-25 11:11:14 -07002122 struct intel_encoder *intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002123 struct intel_sdvo_priv *sdvo_priv;
2124 struct i2c_algo_bit_data *algo_data;
Keith Packardf9c10a92009-05-30 12:16:25 -07002125 const struct i2c_algorithm *algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002126
2127 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
Eric Anholt21d40d32010-03-25 11:11:14 -07002128 intel_encoder =
2129 intel_sdvo_chan_to_intel_encoder(
Ma Ling619ac3b2009-05-18 16:12:46 +08002130 (struct intel_i2c_chan *)(algo_data->data));
Eric Anholt21d40d32010-03-25 11:11:14 -07002131 if (intel_encoder == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002132 return -EINVAL;
2133
Eric Anholt21d40d32010-03-25 11:11:14 -07002134 sdvo_priv = intel_encoder->dev_priv;
2135 algo = intel_encoder->i2c_bus->algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002136
Eric Anholt21d40d32010-03-25 11:11:14 -07002137 intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08002138 return algo->master_xfer(i2c_adap, msgs, num);
2139}
2140
2141static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
2142 .master_xfer = intel_sdvo_master_xfer,
2143};
2144
yakui_zhao714605e2009-05-31 17:18:07 +08002145static u8
Eric Anholtc751ce42010-03-25 11:48:48 -07002146intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
yakui_zhao714605e2009-05-31 17:18:07 +08002147{
2148 struct drm_i915_private *dev_priv = dev->dev_private;
2149 struct sdvo_device_mapping *my_mapping, *other_mapping;
2150
Eric Anholtc751ce42010-03-25 11:48:48 -07002151 if (sdvo_reg == SDVOB) {
yakui_zhao714605e2009-05-31 17:18:07 +08002152 my_mapping = &dev_priv->sdvo_mappings[0];
2153 other_mapping = &dev_priv->sdvo_mappings[1];
2154 } else {
2155 my_mapping = &dev_priv->sdvo_mappings[1];
2156 other_mapping = &dev_priv->sdvo_mappings[0];
2157 }
2158
2159 /* If the BIOS described our SDVO device, take advantage of it. */
2160 if (my_mapping->slave_addr)
2161 return my_mapping->slave_addr;
2162
2163 /* If the BIOS only described a different SDVO device, use the
2164 * address that it isn't using.
2165 */
2166 if (other_mapping->slave_addr) {
2167 if (other_mapping->slave_addr == 0x70)
2168 return 0x72;
2169 else
2170 return 0x70;
2171 }
2172
2173 /* No SDVO device info is found for another DVO port,
2174 * so use mapping assumption we had before BIOS parsing.
2175 */
Eric Anholtc751ce42010-03-25 11:48:48 -07002176 if (sdvo_reg == SDVOB)
yakui_zhao714605e2009-05-31 17:18:07 +08002177 return 0x70;
2178 else
2179 return 0x72;
2180}
2181
Zhao Yakui6070a4a2010-02-08 21:35:12 +08002182static int intel_sdvo_bad_tv_callback(const struct dmi_system_id *id)
2183{
2184 DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id->ident);
2185 return 1;
2186}
2187
2188static struct dmi_system_id intel_sdvo_bad_tv[] = {
2189 {
2190 .callback = intel_sdvo_bad_tv_callback,
2191 .ident = "IntelG45/ICH10R/DME1737",
2192 .matches = {
2193 DMI_MATCH(DMI_SYS_VENDOR, "IBM CORPORATION"),
2194 DMI_MATCH(DMI_PRODUCT_NAME, "4800784"),
2195 },
2196 },
2197
2198 { } /* terminating entry */
2199};
2200
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002201static bool
Zhenyu Wang14571b42010-03-30 14:06:33 +08002202intel_sdvo_connector_alloc (struct intel_connector **ret)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002203{
Zhenyu Wang14571b42010-03-30 14:06:33 +08002204 struct intel_connector *intel_connector;
2205 struct intel_sdvo_connector *sdvo_connector;
2206
2207 *ret = kzalloc(sizeof(*intel_connector) +
2208 sizeof(*sdvo_connector), GFP_KERNEL);
2209 if (!*ret)
2210 return false;
2211
2212 intel_connector = *ret;
2213 sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1);
2214 intel_connector->dev_priv = sdvo_connector;
2215
2216 return true;
2217}
2218
2219static void
2220intel_sdvo_connector_create (struct drm_encoder *encoder,
2221 struct drm_connector *connector)
2222{
2223 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs,
2224 connector->connector_type);
2225
2226 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2227
2228 connector->interlace_allowed = 0;
2229 connector->doublescan_allowed = 0;
2230 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2231
2232 drm_mode_connector_attach_encoder(connector, encoder);
2233 drm_sysfs_connector_add(connector);
2234}
2235
2236static bool
2237intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device)
2238{
Eric Anholt21d40d32010-03-25 11:11:14 -07002239 struct drm_encoder *encoder = &intel_encoder->enc;
2240 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002241 struct drm_connector *connector;
2242 struct intel_connector *intel_connector;
2243 struct intel_sdvo_connector *sdvo_connector;
2244
2245 if (!intel_sdvo_connector_alloc(&intel_connector))
2246 return false;
2247
2248 sdvo_connector = intel_connector->dev_priv;
2249
2250 if (device == 0) {
2251 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0;
2252 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2253 } else if (device == 1) {
2254 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1;
2255 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2256 }
2257
2258 connector = &intel_connector->base;
2259 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2260 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2261
2262 if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode)
2263 && intel_sdvo_get_digital_encoding_mode(intel_encoder, device)
2264 && sdvo_priv->is_hdmi) {
2265 /* enable hdmi encoding mode if supported */
2266 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI);
2267 intel_sdvo_set_colorimetry(intel_encoder,
2268 SDVO_COLORIMETRY_RGB256);
2269 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2270 }
2271 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2272 (1 << INTEL_ANALOG_CLONE_BIT);
2273
2274 intel_sdvo_connector_create(encoder, connector);
2275
2276 return true;
2277}
2278
2279static bool
2280intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type)
2281{
2282 struct drm_encoder *encoder = &intel_encoder->enc;
2283 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2284 struct drm_connector *connector;
2285 struct intel_connector *intel_connector;
2286 struct intel_sdvo_connector *sdvo_connector;
2287
2288 if (!intel_sdvo_connector_alloc(&intel_connector))
2289 return false;
2290
2291 connector = &intel_connector->base;
2292 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2293 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2294 sdvo_connector = intel_connector->dev_priv;
2295
2296 sdvo_priv->controlled_output |= type;
2297 sdvo_connector->output_flag = type;
2298
2299 sdvo_priv->is_tv = true;
2300 intel_encoder->needs_tv_clock = true;
2301 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
2302
2303 intel_sdvo_connector_create(encoder, connector);
2304
2305 intel_sdvo_tv_create_property(connector, type);
2306
2307 intel_sdvo_create_enhance_property(connector);
2308
2309 return true;
2310}
2311
2312static bool
2313intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device)
2314{
2315 struct drm_encoder *encoder = &intel_encoder->enc;
2316 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2317 struct drm_connector *connector;
2318 struct intel_connector *intel_connector;
2319 struct intel_sdvo_connector *sdvo_connector;
2320
2321 if (!intel_sdvo_connector_alloc(&intel_connector))
2322 return false;
2323
2324 connector = &intel_connector->base;
2325 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2326 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2327 sdvo_connector = intel_connector->dev_priv;
2328
2329 if (device == 0) {
2330 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0;
2331 sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2332 } else if (device == 1) {
2333 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1;
2334 sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2335 }
2336
2337 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2338 (1 << INTEL_ANALOG_CLONE_BIT);
2339
2340 intel_sdvo_connector_create(encoder, connector);
2341 return true;
2342}
2343
2344static bool
2345intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device)
2346{
2347 struct drm_encoder *encoder = &intel_encoder->enc;
2348 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2349 struct drm_connector *connector;
2350 struct intel_connector *intel_connector;
2351 struct intel_sdvo_connector *sdvo_connector;
2352
2353 if (!intel_sdvo_connector_alloc(&intel_connector))
2354 return false;
2355
2356 connector = &intel_connector->base;
2357 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2358 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2359 sdvo_connector = intel_connector->dev_priv;
2360
2361 sdvo_priv->is_lvds = true;
2362
2363 if (device == 0) {
2364 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0;
2365 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2366 } else if (device == 1) {
2367 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1;
2368 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2369 }
2370
2371 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
2372 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
2373
2374 intel_sdvo_connector_create(encoder, connector);
2375 intel_sdvo_create_enhance_property(connector);
2376 return true;
2377}
2378
2379static bool
2380intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags)
2381{
2382 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002383
2384 sdvo_priv->is_tv = false;
Eric Anholt21d40d32010-03-25 11:11:14 -07002385 intel_encoder->needs_tv_clock = false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002386 sdvo_priv->is_lvds = false;
2387
Zhenyu Wang14571b42010-03-30 14:06:33 +08002388 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002389
Zhenyu Wang14571b42010-03-30 14:06:33 +08002390 if (flags & SDVO_OUTPUT_TMDS0)
2391 if (!intel_sdvo_dvi_init(intel_encoder, 0))
2392 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002393
Zhenyu Wang14571b42010-03-30 14:06:33 +08002394 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2395 if (!intel_sdvo_dvi_init(intel_encoder, 1))
2396 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002397
Zhenyu Wang14571b42010-03-30 14:06:33 +08002398 /* TV has no XXX1 function block */
2399 if ((flags & SDVO_OUTPUT_SVID0) && !dmi_check_system(intel_sdvo_bad_tv))
2400 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0))
2401 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002402
Zhenyu Wang14571b42010-03-30 14:06:33 +08002403 if (flags & SDVO_OUTPUT_CVBS0)
2404 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0))
2405 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002406
Zhenyu Wang14571b42010-03-30 14:06:33 +08002407 if (flags & SDVO_OUTPUT_RGB0)
2408 if (!intel_sdvo_analog_init(intel_encoder, 0))
2409 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002410
Zhenyu Wang14571b42010-03-30 14:06:33 +08002411 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2412 if (!intel_sdvo_analog_init(intel_encoder, 1))
2413 return false;
Zhao Yakui2dd87382010-01-27 16:32:46 +08002414
Zhenyu Wang14571b42010-03-30 14:06:33 +08002415 if (flags & SDVO_OUTPUT_LVDS0)
2416 if (!intel_sdvo_lvds_init(intel_encoder, 0))
2417 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002418
Zhenyu Wang14571b42010-03-30 14:06:33 +08002419 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2420 if (!intel_sdvo_lvds_init(intel_encoder, 1))
2421 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002422
Zhenyu Wang14571b42010-03-30 14:06:33 +08002423 if ((flags & SDVO_OUTPUT_MASK) == 0) {
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002424 unsigned char bytes[2];
2425
2426 sdvo_priv->controlled_output = 0;
2427 memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
Dave Airlie51c8b402009-08-20 13:38:04 +10002428 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2429 SDVO_NAME(sdvo_priv),
2430 bytes[0], bytes[1]);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002431 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002432 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002433 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002434
Zhenyu Wang14571b42010-03-30 14:06:33 +08002435 return true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002436}
2437
Zhenyu Wang14571b42010-03-30 14:06:33 +08002438static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002439{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002440 struct drm_encoder *encoder = intel_attached_encoder(connector);
2441 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07002442 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002443 struct intel_connector *intel_connector = to_intel_connector(connector);
2444 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002445 struct intel_sdvo_tv_format format;
2446 uint32_t format_map, i;
2447 uint8_t status;
2448
Zhenyu Wang14571b42010-03-30 14:06:33 +08002449 intel_sdvo_set_target_output(intel_encoder, type);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002450
Eric Anholt21d40d32010-03-25 11:11:14 -07002451 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002452 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002453 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002454 &format, sizeof(format));
2455 if (status != SDVO_CMD_STATUS_SUCCESS)
2456 return;
2457
2458 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
2459 sizeof(format_map) : sizeof(format));
2460
2461 if (format_map == 0)
2462 return;
2463
Zhenyu Wang14571b42010-03-30 14:06:33 +08002464 sdvo_connector->format_supported_num = 0;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002465 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2466 if (format_map & (1 << i)) {
Zhenyu Wang14571b42010-03-30 14:06:33 +08002467 sdvo_connector->tv_format_supported
2468 [sdvo_connector->format_supported_num++] =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002469 tv_format_names[i];
2470 }
2471
2472
Zhenyu Wang14571b42010-03-30 14:06:33 +08002473 sdvo_connector->tv_format_property =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002474 drm_property_create(
2475 connector->dev, DRM_MODE_PROP_ENUM,
Zhenyu Wang14571b42010-03-30 14:06:33 +08002476 "mode", sdvo_connector->format_supported_num);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002477
Zhenyu Wang14571b42010-03-30 14:06:33 +08002478 for (i = 0; i < sdvo_connector->format_supported_num; i++)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002479 drm_property_add_enum(
Zhenyu Wang14571b42010-03-30 14:06:33 +08002480 sdvo_connector->tv_format_property, i,
2481 i, sdvo_connector->tv_format_supported[i]);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002482
Zhenyu Wang14571b42010-03-30 14:06:33 +08002483 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0];
Zhao Yakuice6feab2009-08-24 13:50:26 +08002484 drm_connector_attach_property(
Zhenyu Wang14571b42010-03-30 14:06:33 +08002485 connector, sdvo_connector->tv_format_property, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002486
2487}
2488
Zhao Yakuib9219c52009-09-10 15:45:46 +08002489static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2490{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002491 struct drm_encoder *encoder = intel_attached_encoder(connector);
2492 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002493 struct intel_connector *intel_connector = to_intel_connector(connector);
2494 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
Zhao Yakuib9219c52009-09-10 15:45:46 +08002495 struct intel_sdvo_enhancements_reply sdvo_data;
2496 struct drm_device *dev = connector->dev;
2497 uint8_t status;
2498 uint16_t response, data_value[2];
2499
Eric Anholt21d40d32010-03-25 11:11:14 -07002500 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002501 NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002502 status = intel_sdvo_read_response(intel_encoder, &sdvo_data,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002503 sizeof(sdvo_data));
2504 if (status != SDVO_CMD_STATUS_SUCCESS) {
2505 DRM_DEBUG_KMS(" incorrect response is returned\n");
2506 return;
2507 }
2508 response = *((uint16_t *)&sdvo_data);
2509 if (!response) {
2510 DRM_DEBUG_KMS("No enhancement is supported\n");
2511 return;
2512 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08002513 if (IS_TV(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002514 /* when horizontal overscan is supported, Add the left/right
2515 * property
2516 */
2517 if (sdvo_data.overscan_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002518 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002519 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002520 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002521 &data_value, 4);
2522 if (status != SDVO_CMD_STATUS_SUCCESS) {
2523 DRM_DEBUG_KMS("Incorrect SDVO max "
2524 "h_overscan\n");
2525 return;
2526 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002527 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002528 SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002529 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002530 &response, 2);
2531 if (status != SDVO_CMD_STATUS_SUCCESS) {
2532 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2533 return;
2534 }
2535 sdvo_priv->max_hscan = data_value[0];
2536 sdvo_priv->left_margin = data_value[0] - response;
2537 sdvo_priv->right_margin = sdvo_priv->left_margin;
2538 sdvo_priv->left_property =
2539 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2540 "left_margin", 2);
2541 sdvo_priv->left_property->values[0] = 0;
2542 sdvo_priv->left_property->values[1] = data_value[0];
2543 drm_connector_attach_property(connector,
2544 sdvo_priv->left_property,
2545 sdvo_priv->left_margin);
2546 sdvo_priv->right_property =
2547 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2548 "right_margin", 2);
2549 sdvo_priv->right_property->values[0] = 0;
2550 sdvo_priv->right_property->values[1] = data_value[0];
2551 drm_connector_attach_property(connector,
2552 sdvo_priv->right_property,
2553 sdvo_priv->right_margin);
2554 DRM_DEBUG_KMS("h_overscan: max %d, "
2555 "default %d, current %d\n",
2556 data_value[0], data_value[1], response);
2557 }
2558 if (sdvo_data.overscan_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002559 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002560 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002561 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002562 &data_value, 4);
2563 if (status != SDVO_CMD_STATUS_SUCCESS) {
2564 DRM_DEBUG_KMS("Incorrect SDVO max "
2565 "v_overscan\n");
2566 return;
2567 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002568 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002569 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002570 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002571 &response, 2);
2572 if (status != SDVO_CMD_STATUS_SUCCESS) {
2573 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2574 return;
2575 }
2576 sdvo_priv->max_vscan = data_value[0];
2577 sdvo_priv->top_margin = data_value[0] - response;
2578 sdvo_priv->bottom_margin = sdvo_priv->top_margin;
2579 sdvo_priv->top_property =
2580 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2581 "top_margin", 2);
2582 sdvo_priv->top_property->values[0] = 0;
2583 sdvo_priv->top_property->values[1] = data_value[0];
2584 drm_connector_attach_property(connector,
2585 sdvo_priv->top_property,
2586 sdvo_priv->top_margin);
2587 sdvo_priv->bottom_property =
2588 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2589 "bottom_margin", 2);
2590 sdvo_priv->bottom_property->values[0] = 0;
2591 sdvo_priv->bottom_property->values[1] = data_value[0];
2592 drm_connector_attach_property(connector,
2593 sdvo_priv->bottom_property,
2594 sdvo_priv->bottom_margin);
2595 DRM_DEBUG_KMS("v_overscan: max %d, "
2596 "default %d, current %d\n",
2597 data_value[0], data_value[1], response);
2598 }
2599 if (sdvo_data.position_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002600 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002601 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002602 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002603 &data_value, 4);
2604 if (status != SDVO_CMD_STATUS_SUCCESS) {
2605 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2606 return;
2607 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002608 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002609 SDVO_CMD_GET_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002610 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002611 &response, 2);
2612 if (status != SDVO_CMD_STATUS_SUCCESS) {
2613 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2614 return;
2615 }
2616 sdvo_priv->max_hpos = data_value[0];
2617 sdvo_priv->cur_hpos = response;
2618 sdvo_priv->hpos_property =
2619 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2620 "hpos", 2);
2621 sdvo_priv->hpos_property->values[0] = 0;
2622 sdvo_priv->hpos_property->values[1] = data_value[0];
2623 drm_connector_attach_property(connector,
2624 sdvo_priv->hpos_property,
2625 sdvo_priv->cur_hpos);
2626 DRM_DEBUG_KMS("h_position: max %d, "
2627 "default %d, current %d\n",
2628 data_value[0], data_value[1], response);
2629 }
2630 if (sdvo_data.position_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002631 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002632 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002633 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002634 &data_value, 4);
2635 if (status != SDVO_CMD_STATUS_SUCCESS) {
2636 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2637 return;
2638 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002639 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002640 SDVO_CMD_GET_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002641 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002642 &response, 2);
2643 if (status != SDVO_CMD_STATUS_SUCCESS) {
2644 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2645 return;
2646 }
2647 sdvo_priv->max_vpos = data_value[0];
2648 sdvo_priv->cur_vpos = response;
2649 sdvo_priv->vpos_property =
2650 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2651 "vpos", 2);
2652 sdvo_priv->vpos_property->values[0] = 0;
2653 sdvo_priv->vpos_property->values[1] = data_value[0];
2654 drm_connector_attach_property(connector,
2655 sdvo_priv->vpos_property,
2656 sdvo_priv->cur_vpos);
2657 DRM_DEBUG_KMS("v_position: max %d, "
2658 "default %d, current %d\n",
2659 data_value[0], data_value[1], response);
2660 }
Zhao Yakuib9219c52009-09-10 15:45:46 +08002661 if (sdvo_data.saturation) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002662 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002663 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002664 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002665 &data_value, 4);
2666 if (status != SDVO_CMD_STATUS_SUCCESS) {
2667 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2668 return;
2669 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002670 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002671 SDVO_CMD_GET_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002672 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002673 &response, 2);
2674 if (status != SDVO_CMD_STATUS_SUCCESS) {
2675 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2676 return;
2677 }
2678 sdvo_priv->max_saturation = data_value[0];
2679 sdvo_priv->cur_saturation = response;
2680 sdvo_priv->saturation_property =
2681 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2682 "saturation", 2);
2683 sdvo_priv->saturation_property->values[0] = 0;
2684 sdvo_priv->saturation_property->values[1] =
2685 data_value[0];
2686 drm_connector_attach_property(connector,
2687 sdvo_priv->saturation_property,
2688 sdvo_priv->cur_saturation);
2689 DRM_DEBUG_KMS("saturation: max %d, "
2690 "default %d, current %d\n",
2691 data_value[0], data_value[1], response);
2692 }
2693 if (sdvo_data.contrast) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002694 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002695 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002696 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002697 &data_value, 4);
2698 if (status != SDVO_CMD_STATUS_SUCCESS) {
2699 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2700 return;
2701 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002702 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002703 SDVO_CMD_GET_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002704 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002705 &response, 2);
2706 if (status != SDVO_CMD_STATUS_SUCCESS) {
2707 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2708 return;
2709 }
2710 sdvo_priv->max_contrast = data_value[0];
2711 sdvo_priv->cur_contrast = response;
2712 sdvo_priv->contrast_property =
2713 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2714 "contrast", 2);
2715 sdvo_priv->contrast_property->values[0] = 0;
2716 sdvo_priv->contrast_property->values[1] = data_value[0];
2717 drm_connector_attach_property(connector,
2718 sdvo_priv->contrast_property,
2719 sdvo_priv->cur_contrast);
2720 DRM_DEBUG_KMS("contrast: max %d, "
2721 "default %d, current %d\n",
2722 data_value[0], data_value[1], response);
2723 }
2724 if (sdvo_data.hue) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002725 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002726 SDVO_CMD_GET_MAX_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002727 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002728 &data_value, 4);
2729 if (status != SDVO_CMD_STATUS_SUCCESS) {
2730 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2731 return;
2732 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002733 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002734 SDVO_CMD_GET_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002735 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002736 &response, 2);
2737 if (status != SDVO_CMD_STATUS_SUCCESS) {
2738 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2739 return;
2740 }
2741 sdvo_priv->max_hue = data_value[0];
2742 sdvo_priv->cur_hue = response;
2743 sdvo_priv->hue_property =
2744 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2745 "hue", 2);
2746 sdvo_priv->hue_property->values[0] = 0;
2747 sdvo_priv->hue_property->values[1] =
2748 data_value[0];
2749 drm_connector_attach_property(connector,
2750 sdvo_priv->hue_property,
2751 sdvo_priv->cur_hue);
2752 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2753 data_value[0], data_value[1], response);
2754 }
2755 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08002756 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002757 if (sdvo_data.brightness) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002758 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002759 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002760 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002761 &data_value, 4);
2762 if (status != SDVO_CMD_STATUS_SUCCESS) {
2763 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2764 return;
2765 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002766 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002767 SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002768 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002769 &response, 2);
2770 if (status != SDVO_CMD_STATUS_SUCCESS) {
2771 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2772 return;
2773 }
2774 sdvo_priv->max_brightness = data_value[0];
2775 sdvo_priv->cur_brightness = response;
2776 sdvo_priv->brightness_property =
2777 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2778 "brightness", 2);
2779 sdvo_priv->brightness_property->values[0] = 0;
2780 sdvo_priv->brightness_property->values[1] =
2781 data_value[0];
2782 drm_connector_attach_property(connector,
2783 sdvo_priv->brightness_property,
2784 sdvo_priv->cur_brightness);
2785 DRM_DEBUG_KMS("brightness: max %d, "
2786 "default %d, current %d\n",
2787 data_value[0], data_value[1], response);
2788 }
2789 }
2790 return;
2791}
2792
Eric Anholtc751ce42010-03-25 11:48:48 -07002793bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
Jesse Barnes79e53942008-11-07 14:24:08 -08002794{
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002795 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07002796 struct intel_encoder *intel_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -08002797 struct intel_sdvo_priv *sdvo_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08002798 u8 ch[0x40];
2799 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -08002800
Eric Anholt21d40d32010-03-25 11:11:14 -07002801 intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
2802 if (!intel_encoder) {
Eric Anholt7d573822009-01-02 13:33:00 -08002803 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002804 }
2805
Eric Anholt21d40d32010-03-25 11:11:14 -07002806 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1);
Eric Anholtc751ce42010-03-25 11:48:48 -07002807 sdvo_priv->sdvo_reg = sdvo_reg;
Keith Packard308cd3a2009-06-14 11:56:18 -07002808
Eric Anholt21d40d32010-03-25 11:11:14 -07002809 intel_encoder->dev_priv = sdvo_priv;
2810 intel_encoder->type = INTEL_OUTPUT_SDVO;
Jesse Barnes79e53942008-11-07 14:24:08 -08002811
Jesse Barnes79e53942008-11-07 14:24:08 -08002812 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002813 if (sdvo_reg == SDVOB)
Eric Anholt21d40d32010-03-25 11:11:14 -07002814 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
Keith Packard308cd3a2009-06-14 11:56:18 -07002815 else
Eric Anholt21d40d32010-03-25 11:11:14 -07002816 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
Keith Packard308cd3a2009-06-14 11:56:18 -07002817
Eric Anholt21d40d32010-03-25 11:11:14 -07002818 if (!intel_encoder->i2c_bus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002819 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08002820
Eric Anholtc751ce42010-03-25 11:48:48 -07002821 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08002822
Keith Packard308cd3a2009-06-14 11:56:18 -07002823 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
Eric Anholt21d40d32010-03-25 11:11:14 -07002824 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
Jesse Barnes79e53942008-11-07 14:24:08 -08002825
Jesse Barnes79e53942008-11-07 14:24:08 -08002826 /* Read the regs to test if we can talk to the device */
2827 for (i = 0; i < 0x40; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002828 if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002829 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002830 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002831 goto err_i2c;
2832 }
2833 }
2834
Ma Ling619ac3b2009-05-18 16:12:46 +08002835 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002836 if (sdvo_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002837 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002838 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2839 "SDVOB/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002840 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002841 } else {
Eric Anholt21d40d32010-03-25 11:11:14 -07002842 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002843 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2844 "SDVOC/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002845 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002846 }
Ma Ling619ac3b2009-05-18 16:12:46 +08002847
Eric Anholt21d40d32010-03-25 11:11:14 -07002848 if (intel_encoder->ddc_bus == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002849 goto err_i2c;
2850
Keith Packard308cd3a2009-06-14 11:56:18 -07002851 /* Wrap with our custom algo which switches to DDC mode */
Eric Anholt21d40d32010-03-25 11:11:14 -07002852 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002853
Zhenyu Wang14571b42010-03-30 14:06:33 +08002854 /* encoder type will be decided later */
2855 drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0);
2856 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2857
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002858 /* In default case sdvo lvds is false */
Eric Anholt21d40d32010-03-25 11:11:14 -07002859 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps);
Jesse Barnes79e53942008-11-07 14:24:08 -08002860
Zhenyu Wang14571b42010-03-30 14:06:33 +08002861 if (intel_sdvo_output_setup(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002862 sdvo_priv->caps.output_flags) != true) {
Dave Airlie51c8b402009-08-20 13:38:04 +10002863 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002864 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002865 goto err_i2c;
2866 }
2867
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002868 intel_sdvo_select_ddc_bus(sdvo_priv);
2869
Jesse Barnes79e53942008-11-07 14:24:08 -08002870 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholt21d40d32010-03-25 11:11:14 -07002871 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08002872
Eric Anholt21d40d32010-03-25 11:11:14 -07002873 intel_sdvo_get_input_pixel_clock_range(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002874 &sdvo_priv->pixel_clock_min,
2875 &sdvo_priv->pixel_clock_max);
2876
2877
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002878 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
yakui_zhao342dc382009-06-02 14:12:00 +08002879 "clock range %dMHz - %dMHz, "
2880 "input 1: %c, input 2: %c, "
2881 "output 1: %c, output 2: %c\n",
2882 SDVO_NAME(sdvo_priv),
2883 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
2884 sdvo_priv->caps.device_rev_id,
2885 sdvo_priv->pixel_clock_min / 1000,
2886 sdvo_priv->pixel_clock_max / 1000,
2887 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2888 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
2889 /* check currently supported outputs */
2890 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002891 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
yakui_zhao342dc382009-06-02 14:12:00 +08002892 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002893 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2894
Eric Anholt7d573822009-01-02 13:33:00 -08002895 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08002896
2897err_i2c:
Keith Packard57cdaf92009-09-04 13:07:54 +08002898 if (sdvo_priv->analog_ddc_bus != NULL)
2899 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
Eric Anholt21d40d32010-03-25 11:11:14 -07002900 if (intel_encoder->ddc_bus != NULL)
2901 intel_i2c_destroy(intel_encoder->ddc_bus);
2902 if (intel_encoder->i2c_bus != NULL)
2903 intel_i2c_destroy(intel_encoder->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002904err_inteloutput:
Eric Anholt21d40d32010-03-25 11:11:14 -07002905 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002906
Eric Anholt7d573822009-01-02 13:33:00 -08002907 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002908}