blob: 1f4e9e9eac904a540f740993cc354765d973361b [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Eric Anholt <eric@anholt.net>
27 */
28#include <linux/i2c.h>
29#include <linux/delay.h>
30#include "drmP.h"
31#include "drm.h"
32#include "drm_crtc.h"
33#include "intel_drv.h"
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +080034#include "drm_edid.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "i915_drm.h"
36#include "i915_drv.h"
37#include "intel_sdvo_regs.h"
38
Zhenyu Wang14571b42010-03-30 14:06:33 +080039#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
40#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
41#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
42#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
43
44#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
45 SDVO_TV_MASK)
46
47#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
48#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
49
50
Zhao Yakuice6feab2009-08-24 13:50:26 +080051static char *tv_format_names[] = {
52 "NTSC_M" , "NTSC_J" , "NTSC_443",
53 "PAL_B" , "PAL_D" , "PAL_G" ,
54 "PAL_H" , "PAL_I" , "PAL_M" ,
55 "PAL_N" , "PAL_NC" , "PAL_60" ,
56 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
57 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
58 "SECAM_60"
59};
60
61#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
62
Jesse Barnes79e53942008-11-07 14:24:08 -080063struct intel_sdvo_priv {
Keith Packardf9c10a92009-05-30 12:16:25 -070064 u8 slave_addr;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080065
66 /* Register for the SDVO device: SDVOB or SDVOC */
Eric Anholtc751ce42010-03-25 11:48:48 -070067 int sdvo_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080068
Jesse Barnese2f0ba92009-02-02 15:11:52 -080069 /* Active outputs controlled by this SDVO output */
70 uint16_t controlled_output;
Jesse Barnes79e53942008-11-07 14:24:08 -080071
Jesse Barnese2f0ba92009-02-02 15:11:52 -080072 /*
73 * Capabilities of the SDVO device returned by
74 * i830_sdvo_get_capabilities()
75 */
Jesse Barnes79e53942008-11-07 14:24:08 -080076 struct intel_sdvo_caps caps;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080077
78 /* Pixel clock limitations reported by the SDVO device, in kHz */
Jesse Barnes79e53942008-11-07 14:24:08 -080079 int pixel_clock_min, pixel_clock_max;
80
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +080081 /*
82 * For multiple function SDVO device,
83 * this is for current attached outputs.
84 */
85 uint16_t attached_output;
86
Jesse Barnese2f0ba92009-02-02 15:11:52 -080087 /**
88 * This is set if we're going to treat the device as TV-out.
89 *
90 * While we have these nice friendly flags for output types that ought
91 * to decide this for us, the S-Video output on our HDMI+S-Video card
92 * shows up as RGB1 (VGA).
93 */
94 bool is_tv;
95
Zhao Yakuice6feab2009-08-24 13:50:26 +080096 /* This is for current tv format name */
97 char *tv_format_name;
98
Jesse Barnese2f0ba92009-02-02 15:11:52 -080099 /**
100 * This is set if we treat the device as HDMI, instead of DVI.
101 */
102 bool is_hdmi;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800103
Ma Ling7086c872009-05-13 11:20:06 +0800104 /**
105 * This is set if we detect output of sdvo device as LVDS.
106 */
107 bool is_lvds;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800108
109 /**
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800110 * This is sdvo flags for input timing.
111 */
112 uint8_t sdvo_flags;
113
114 /**
115 * This is sdvo fixed pannel mode pointer
116 */
117 struct drm_display_mode *sdvo_lvds_fixed_mode;
118
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800119 /*
120 * supported encoding mode, used to determine whether HDMI is
121 * supported
122 */
123 struct intel_sdvo_encode encode;
124
Eric Anholtc751ce42010-03-25 11:48:48 -0700125 /* DDC bus used by this SDVO encoder */
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800126 uint8_t ddc_bus;
127
Keith Packard57cdaf92009-09-04 13:07:54 +0800128 /* Mac mini hack -- use the same DDC as the analog connector */
129 struct i2c_adapter *analog_ddc_bus;
130
Zhenyu Wang14571b42010-03-30 14:06:33 +0800131};
132
133struct intel_sdvo_connector {
134 /* Mark the type of connector */
135 uint16_t output_flag;
136
137 /* This contains all current supported TV format */
138 char *tv_format_supported[TV_FORMAT_NUM];
139 int format_supported_num;
140 struct drm_property *tv_format_property;
141 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
142
143 /**
144 * Returned SDTV resolutions allowed for the current format, if the
145 * device reported it.
146 */
147 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
148
Zhao Yakuib9219c52009-09-10 15:45:46 +0800149 /* add the property for the SDVO-TV */
150 struct drm_property *left_property;
151 struct drm_property *right_property;
152 struct drm_property *top_property;
153 struct drm_property *bottom_property;
154 struct drm_property *hpos_property;
155 struct drm_property *vpos_property;
156
157 /* add the property for the SDVO-TV/LVDS */
158 struct drm_property *brightness_property;
159 struct drm_property *contrast_property;
160 struct drm_property *saturation_property;
161 struct drm_property *hue_property;
162
163 /* Add variable to record current setting for the above property */
164 u32 left_margin, right_margin, top_margin, bottom_margin;
165 /* this is to get the range of margin.*/
166 u32 max_hscan, max_vscan;
167 u32 max_hpos, cur_hpos;
168 u32 max_vpos, cur_vpos;
169 u32 cur_brightness, max_brightness;
170 u32 cur_contrast, max_contrast;
171 u32 cur_saturation, max_saturation;
172 u32 cur_hue, max_hue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800173};
174
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800175static bool
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800176intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800177 uint16_t flags);
Zhenyu Wang14571b42010-03-30 14:06:33 +0800178static void
179intel_sdvo_tv_create_property(struct drm_connector *connector, int type);
180static void
181intel_sdvo_create_enhance_property(struct drm_connector *connector);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800182
Jesse Barnes79e53942008-11-07 14:24:08 -0800183/**
184 * Writes the SDVOB or SDVOC with the given value, but always writes both
185 * SDVOB and SDVOC to work around apparent hardware issues (according to
186 * comments in the BIOS).
187 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700188static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800189{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800190 struct drm_device *dev = intel_encoder->enc.dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800191 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -0700192 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800193 u32 bval = val, cval = val;
194 int i;
195
Eric Anholtc751ce42010-03-25 11:48:48 -0700196 if (sdvo_priv->sdvo_reg == SDVOB) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800197 cval = I915_READ(SDVOC);
198 } else {
199 bval = I915_READ(SDVOB);
200 }
201 /*
202 * Write the registers twice for luck. Sometimes,
203 * writing them only once doesn't appear to 'stick'.
204 * The BIOS does this too. Yay, magic
205 */
206 for (i = 0; i < 2; i++)
207 {
208 I915_WRITE(SDVOB, bval);
209 I915_READ(SDVOB);
210 I915_WRITE(SDVOC, cval);
211 I915_READ(SDVOC);
212 }
213}
214
Eric Anholt21d40d32010-03-25 11:11:14 -0700215static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800216 u8 *ch)
217{
Eric Anholt21d40d32010-03-25 11:11:14 -0700218 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800219 u8 out_buf[2];
220 u8 buf[2];
221 int ret;
222
223 struct i2c_msg msgs[] = {
224 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700225 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800226 .flags = 0,
227 .len = 1,
228 .buf = out_buf,
229 },
230 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700231 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800232 .flags = I2C_M_RD,
233 .len = 1,
234 .buf = buf,
235 }
236 };
237
238 out_buf[0] = addr;
239 out_buf[1] = 0;
240
Eric Anholt21d40d32010-03-25 11:11:14 -0700241 if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800242 {
243 *ch = buf[0];
244 return true;
245 }
246
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800247 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
Jesse Barnes79e53942008-11-07 14:24:08 -0800248 return false;
249}
250
Eric Anholt21d40d32010-03-25 11:11:14 -0700251static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800252 u8 ch)
253{
Eric Anholt21d40d32010-03-25 11:11:14 -0700254 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800255 u8 out_buf[2];
256 struct i2c_msg msgs[] = {
257 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700258 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800259 .flags = 0,
260 .len = 2,
261 .buf = out_buf,
262 }
263 };
264
265 out_buf[0] = addr;
266 out_buf[1] = ch;
267
Eric Anholt21d40d32010-03-25 11:11:14 -0700268 if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800269 {
270 return true;
271 }
272 return false;
273}
274
275#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
276/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100277static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800278 u8 cmd;
279 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800280} sdvo_cmd_names[] = {
281 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
Zhao Yakuib9219c52009-09-10 15:45:46 +0800324 /* Add the op code for SDVO enhancements */
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800349 /* HDMI op code */
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
355 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
356 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
359 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
360 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
361 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
362 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
366 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
368 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
369 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800370};
371
Eric Anholtc751ce42010-03-25 11:48:48 -0700372#define SDVO_NAME(dev_priv) ((dev_priv)->sdvo_reg == SDVOB ? "SDVOB" : "SDVOC")
373#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -0800374
Eric Anholt21d40d32010-03-25 11:11:14 -0700375static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800376 void *args, int args_len)
377{
Eric Anholt21d40d32010-03-25 11:11:14 -0700378 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800379 int i;
380
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800381 DRM_DEBUG_KMS("%s: W: %02X ",
yakui_zhao342dc382009-06-02 14:12:00 +0800382 SDVO_NAME(sdvo_priv), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800383 for (i = 0; i < args_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800384 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800385 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800386 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800387 for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
388 if (cmd == sdvo_cmd_names[i].cmd) {
yakui_zhao342dc382009-06-02 14:12:00 +0800389 DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800390 break;
391 }
392 }
393 if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
yakui_zhao342dc382009-06-02 14:12:00 +0800394 DRM_LOG_KMS("(%02X)", cmd);
395 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800396}
Jesse Barnes79e53942008-11-07 14:24:08 -0800397
Eric Anholt21d40d32010-03-25 11:11:14 -0700398static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800399 void *args, int args_len)
400{
401 int i;
402
Eric Anholt21d40d32010-03-25 11:11:14 -0700403 intel_sdvo_debug_write(intel_encoder, cmd, args, args_len);
Jesse Barnes79e53942008-11-07 14:24:08 -0800404
405 for (i = 0; i < args_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700406 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i,
Jesse Barnes79e53942008-11-07 14:24:08 -0800407 ((u8*)args)[i]);
408 }
409
Eric Anholt21d40d32010-03-25 11:11:14 -0700410 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800411}
412
Jesse Barnes79e53942008-11-07 14:24:08 -0800413static const char *cmd_status_names[] = {
414 "Power on",
415 "Success",
416 "Not supported",
417 "Invalid arg",
418 "Pending",
419 "Target not specified",
420 "Scaling not supported"
421};
422
Eric Anholt21d40d32010-03-25 11:11:14 -0700423static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800424 void *response, int response_len,
425 u8 status)
426{
Eric Anholt21d40d32010-03-25 11:11:14 -0700427 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang33b52962009-03-24 14:02:40 +0800428 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800429
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800430 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -0800431 for (i = 0; i < response_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800432 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800433 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800434 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800435 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
yakui_zhao342dc382009-06-02 14:12:00 +0800436 DRM_LOG_KMS("(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800437 else
yakui_zhao342dc382009-06-02 14:12:00 +0800438 DRM_LOG_KMS("(??? %d)", status);
439 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800440}
Jesse Barnes79e53942008-11-07 14:24:08 -0800441
Eric Anholt21d40d32010-03-25 11:11:14 -0700442static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800443 void *response, int response_len)
444{
445 int i;
446 u8 status;
447 u8 retry = 50;
448
449 while (retry--) {
450 /* Read the command response */
451 for (i = 0; i < response_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700452 intel_sdvo_read_byte(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800453 SDVO_I2C_RETURN_0 + i,
454 &((u8 *)response)[i]);
455 }
456
457 /* read the return status */
Eric Anholt21d40d32010-03-25 11:11:14 -0700458 intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS,
Jesse Barnes79e53942008-11-07 14:24:08 -0800459 &status);
460
Eric Anholt21d40d32010-03-25 11:11:14 -0700461 intel_sdvo_debug_response(intel_encoder, response, response_len,
Jesse Barnes79e53942008-11-07 14:24:08 -0800462 status);
463 if (status != SDVO_CMD_STATUS_PENDING)
464 return status;
465
466 mdelay(50);
467 }
468
469 return status;
470}
471
Hannes Ederb358d0a2008-12-18 21:18:47 +0100472static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800473{
474 if (mode->clock >= 100000)
475 return 1;
476 else if (mode->clock >= 50000)
477 return 2;
478 else
479 return 4;
480}
481
482/**
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800483 * Try to read the response after issuie the DDC switch command. But it
484 * is noted that we must do the action of reading response and issuing DDC
485 * switch command in one I2C transaction. Otherwise when we try to start
486 * another I2C transaction after issuing the DDC bus switch, it will be
487 * switched to the internal SDVO register.
Jesse Barnes79e53942008-11-07 14:24:08 -0800488 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700489static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder,
Hannes Ederb358d0a2008-12-18 21:18:47 +0100490 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800491{
Eric Anholt21d40d32010-03-25 11:11:14 -0700492 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800493 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
494 struct i2c_msg msgs[] = {
495 {
496 .addr = sdvo_priv->slave_addr >> 1,
497 .flags = 0,
498 .len = 2,
499 .buf = out_buf,
500 },
501 /* the following two are to read the response */
502 {
503 .addr = sdvo_priv->slave_addr >> 1,
504 .flags = 0,
505 .len = 1,
506 .buf = cmd_buf,
507 },
508 {
509 .addr = sdvo_priv->slave_addr >> 1,
510 .flags = I2C_M_RD,
511 .len = 1,
512 .buf = ret_value,
513 },
514 };
515
Eric Anholt21d40d32010-03-25 11:11:14 -0700516 intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800517 &target, 1);
518 /* write the DDC switch command argument */
Eric Anholt21d40d32010-03-25 11:11:14 -0700519 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800520
521 out_buf[0] = SDVO_I2C_OPCODE;
522 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
523 cmd_buf[0] = SDVO_I2C_CMD_STATUS;
524 cmd_buf[1] = 0;
525 ret_value[0] = 0;
526 ret_value[1] = 0;
527
Eric Anholt21d40d32010-03-25 11:11:14 -0700528 ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800529 if (ret != 3) {
530 /* failure in I2C transfer */
531 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
532 return;
533 }
534 if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
535 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
536 ret_value[0]);
537 return;
538 }
539 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800540}
541
Eric Anholt21d40d32010-03-25 11:11:14 -0700542static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800543{
544 struct intel_sdvo_set_target_input_args targets = {0};
545 u8 status;
546
547 if (target_0 && target_1)
548 return SDVO_CMD_STATUS_NOTSUPP;
549
550 if (target_1)
551 targets.target_1 = 1;
552
Eric Anholt21d40d32010-03-25 11:11:14 -0700553 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets,
Jesse Barnes79e53942008-11-07 14:24:08 -0800554 sizeof(targets));
555
Eric Anholt21d40d32010-03-25 11:11:14 -0700556 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800557
558 return (status == SDVO_CMD_STATUS_SUCCESS);
559}
560
561/**
562 * Return whether each input is trained.
563 *
564 * This function is making an assumption about the layout of the response,
565 * which should be checked against the docs.
566 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700567static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800568{
569 struct intel_sdvo_get_trained_inputs_response response;
570 u8 status;
571
Eric Anholt21d40d32010-03-25 11:11:14 -0700572 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
573 status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response));
Jesse Barnes79e53942008-11-07 14:24:08 -0800574 if (status != SDVO_CMD_STATUS_SUCCESS)
575 return false;
576
577 *input_1 = response.input0_trained;
578 *input_2 = response.input1_trained;
579 return true;
580}
581
Eric Anholt21d40d32010-03-25 11:11:14 -0700582static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800583 u16 outputs)
584{
585 u8 status;
586
Eric Anholt21d40d32010-03-25 11:11:14 -0700587 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800588 sizeof(outputs));
Eric Anholt21d40d32010-03-25 11:11:14 -0700589 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800590 return (status == SDVO_CMD_STATUS_SUCCESS);
591}
592
Eric Anholt21d40d32010-03-25 11:11:14 -0700593static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800594 int mode)
595{
596 u8 status, state = SDVO_ENCODER_STATE_ON;
597
598 switch (mode) {
599 case DRM_MODE_DPMS_ON:
600 state = SDVO_ENCODER_STATE_ON;
601 break;
602 case DRM_MODE_DPMS_STANDBY:
603 state = SDVO_ENCODER_STATE_STANDBY;
604 break;
605 case DRM_MODE_DPMS_SUSPEND:
606 state = SDVO_ENCODER_STATE_SUSPEND;
607 break;
608 case DRM_MODE_DPMS_OFF:
609 state = SDVO_ENCODER_STATE_OFF;
610 break;
611 }
612
Eric Anholt21d40d32010-03-25 11:11:14 -0700613 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
Jesse Barnes79e53942008-11-07 14:24:08 -0800614 sizeof(state));
Eric Anholt21d40d32010-03-25 11:11:14 -0700615 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800616
617 return (status == SDVO_CMD_STATUS_SUCCESS);
618}
619
Eric Anholt21d40d32010-03-25 11:11:14 -0700620static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800621 int *clock_min,
622 int *clock_max)
623{
624 struct intel_sdvo_pixel_clock_range clocks;
625 u8 status;
626
Eric Anholt21d40d32010-03-25 11:11:14 -0700627 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
Jesse Barnes79e53942008-11-07 14:24:08 -0800628 NULL, 0);
629
Eric Anholt21d40d32010-03-25 11:11:14 -0700630 status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks));
Jesse Barnes79e53942008-11-07 14:24:08 -0800631
632 if (status != SDVO_CMD_STATUS_SUCCESS)
633 return false;
634
635 /* Convert the values from units of 10 kHz to kHz. */
636 *clock_min = clocks.min * 10;
637 *clock_max = clocks.max * 10;
638
639 return true;
640}
641
Eric Anholt21d40d32010-03-25 11:11:14 -0700642static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800643 u16 outputs)
644{
645 u8 status;
646
Eric Anholt21d40d32010-03-25 11:11:14 -0700647 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800648 sizeof(outputs));
649
Eric Anholt21d40d32010-03-25 11:11:14 -0700650 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800651 return (status == SDVO_CMD_STATUS_SUCCESS);
652}
653
Eric Anholt21d40d32010-03-25 11:11:14 -0700654static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800655 struct intel_sdvo_dtd *dtd)
656{
657 u8 status;
658
Eric Anholt21d40d32010-03-25 11:11:14 -0700659 intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1));
660 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800661 if (status != SDVO_CMD_STATUS_SUCCESS)
662 return false;
663
Eric Anholt21d40d32010-03-25 11:11:14 -0700664 intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2));
665 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800666 if (status != SDVO_CMD_STATUS_SUCCESS)
667 return false;
668
669 return true;
670}
671
Eric Anholt21d40d32010-03-25 11:11:14 -0700672static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800673 struct intel_sdvo_dtd *dtd)
674{
Eric Anholt21d40d32010-03-25 11:11:14 -0700675 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800676 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
677}
678
Eric Anholt21d40d32010-03-25 11:11:14 -0700679static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800680 struct intel_sdvo_dtd *dtd)
681{
Eric Anholt21d40d32010-03-25 11:11:14 -0700682 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800683 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
684}
685
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800686static bool
Eric Anholtc751ce42010-03-25 11:48:48 -0700687intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800688 uint16_t clock,
689 uint16_t width,
690 uint16_t height)
691{
692 struct intel_sdvo_preferred_input_timing_args args;
Eric Anholtc751ce42010-03-25 11:48:48 -0700693 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800694 uint8_t status;
695
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800696 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800697 args.clock = clock;
698 args.width = width;
699 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800700 args.interlace = 0;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800701
702 if (sdvo_priv->is_lvds &&
703 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
704 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
705 args.scaled = 1;
706
Eric Anholtc751ce42010-03-25 11:48:48 -0700707 intel_sdvo_write_cmd(intel_encoder,
708 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800709 &args, sizeof(args));
Eric Anholtc751ce42010-03-25 11:48:48 -0700710 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800711 if (status != SDVO_CMD_STATUS_SUCCESS)
712 return false;
713
714 return true;
715}
716
Eric Anholtc751ce42010-03-25 11:48:48 -0700717static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800718 struct intel_sdvo_dtd *dtd)
719{
720 bool status;
721
Eric Anholtc751ce42010-03-25 11:48:48 -0700722 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800723 NULL, 0);
724
Eric Anholtc751ce42010-03-25 11:48:48 -0700725 status = intel_sdvo_read_response(intel_encoder, &dtd->part1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800726 sizeof(dtd->part1));
727 if (status != SDVO_CMD_STATUS_SUCCESS)
728 return false;
729
Eric Anholtc751ce42010-03-25 11:48:48 -0700730 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800731 NULL, 0);
732
Eric Anholtc751ce42010-03-25 11:48:48 -0700733 status = intel_sdvo_read_response(intel_encoder, &dtd->part2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800734 sizeof(dtd->part2));
735 if (status != SDVO_CMD_STATUS_SUCCESS)
736 return false;
737
738 return false;
739}
Jesse Barnes79e53942008-11-07 14:24:08 -0800740
Eric Anholt21d40d32010-03-25 11:11:14 -0700741static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800742{
743 u8 status;
744
Eric Anholt21d40d32010-03-25 11:11:14 -0700745 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
746 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800747 if (status != SDVO_CMD_STATUS_SUCCESS)
748 return false;
749
750 return true;
751}
752
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800753static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
754 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800755{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800756 uint16_t width, height;
757 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
758 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800759
760 width = mode->crtc_hdisplay;
761 height = mode->crtc_vdisplay;
762
763 /* do some mode translations */
764 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
765 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
766
767 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
768 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
769
770 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
771 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
772
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800773 dtd->part1.clock = mode->clock / 10;
774 dtd->part1.h_active = width & 0xff;
775 dtd->part1.h_blank = h_blank_len & 0xff;
776 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800777 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800778 dtd->part1.v_active = height & 0xff;
779 dtd->part1.v_blank = v_blank_len & 0xff;
780 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800781 ((v_blank_len >> 8) & 0xf);
782
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800783 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800784 dtd->part2.h_sync_width = h_sync_len & 0xff;
785 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800786 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800787 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800788 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
789 ((v_sync_len & 0x30) >> 4);
790
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800791 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800792 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800793 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800794 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800795 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800796
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800797 dtd->part2.sdvo_flags = 0;
798 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
799 dtd->part2.reserved = 0;
800}
Jesse Barnes79e53942008-11-07 14:24:08 -0800801
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800802static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
803 struct intel_sdvo_dtd *dtd)
804{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800805 mode->hdisplay = dtd->part1.h_active;
806 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
807 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800808 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800809 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
810 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
811 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
812 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
813
814 mode->vdisplay = dtd->part1.v_active;
815 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
816 mode->vsync_start = mode->vdisplay;
817 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800818 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800819 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
820 mode->vsync_end = mode->vsync_start +
821 (dtd->part2.v_sync_off_width & 0xf);
822 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
823 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
824 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
825
826 mode->clock = dtd->part1.clock * 10;
827
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800828 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800829 if (dtd->part2.dtd_flags & 0x2)
830 mode->flags |= DRM_MODE_FLAG_PHSYNC;
831 if (dtd->part2.dtd_flags & 0x4)
832 mode->flags |= DRM_MODE_FLAG_PVSYNC;
833}
834
Eric Anholtc751ce42010-03-25 11:48:48 -0700835static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800836 struct intel_sdvo_encode *encode)
837{
838 uint8_t status;
839
Eric Anholtc751ce42010-03-25 11:48:48 -0700840 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
841 status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800842 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
843 memset(encode, 0, sizeof(*encode));
844 return false;
845 }
846
847 return true;
848}
849
Eric Anholtc751ce42010-03-25 11:48:48 -0700850static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder,
851 uint8_t mode)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800852{
853 uint8_t status;
854
Eric Anholtc751ce42010-03-25 11:48:48 -0700855 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1);
856 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800857
858 return (status == SDVO_CMD_STATUS_SUCCESS);
859}
860
Eric Anholtc751ce42010-03-25 11:48:48 -0700861static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800862 uint8_t mode)
863{
864 uint8_t status;
865
Eric Anholtc751ce42010-03-25 11:48:48 -0700866 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
867 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800868
869 return (status == SDVO_CMD_STATUS_SUCCESS);
870}
871
872#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -0700873static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800874{
875 int i, j;
876 uint8_t set_buf_index[2];
877 uint8_t av_split;
878 uint8_t buf_size;
879 uint8_t buf[48];
880 uint8_t *pos;
881
Eric Anholtc751ce42010-03-25 11:48:48 -0700882 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
883 intel_sdvo_read_response(encoder, &av_split, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800884
885 for (i = 0; i <= av_split; i++) {
886 set_buf_index[0] = i; set_buf_index[1] = 0;
Eric Anholtc751ce42010-03-25 11:48:48 -0700887 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800888 set_buf_index, 2);
Eric Anholtc751ce42010-03-25 11:48:48 -0700889 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
890 intel_sdvo_read_response(encoder, &buf_size, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800891
892 pos = buf;
893 for (j = 0; j <= buf_size; j += 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700894 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800895 NULL, 0);
Eric Anholtc751ce42010-03-25 11:48:48 -0700896 intel_sdvo_read_response(encoder, pos, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800897 pos += 8;
898 }
899 }
900}
901#endif
902
Eric Anholtc751ce42010-03-25 11:48:48 -0700903static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder,
904 int index,
905 uint8_t *data, int8_t size, uint8_t tx_rate)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800906{
907 uint8_t set_buf_index[2];
908
909 set_buf_index[0] = index;
910 set_buf_index[1] = 0;
911
Eric Anholtc751ce42010-03-25 11:48:48 -0700912 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX,
913 set_buf_index, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800914
915 for (; size > 0; size -= 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700916 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800917 data += 8;
918 }
919
Eric Anholtc751ce42010-03-25 11:48:48 -0700920 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800921}
922
923static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
924{
925 uint8_t csum = 0;
926 int i;
927
928 for (i = 0; i < size; i++)
929 csum += data[i];
930
931 return 0x100 - csum;
932}
933
934#define DIP_TYPE_AVI 0x82
935#define DIP_VERSION_AVI 0x2
936#define DIP_LEN_AVI 13
937
938struct dip_infoframe {
939 uint8_t type;
940 uint8_t version;
941 uint8_t len;
942 uint8_t checksum;
943 union {
944 struct {
945 /* Packet Byte #1 */
946 uint8_t S:2;
947 uint8_t B:2;
948 uint8_t A:1;
949 uint8_t Y:2;
950 uint8_t rsvd1:1;
951 /* Packet Byte #2 */
952 uint8_t R:4;
953 uint8_t M:2;
954 uint8_t C:2;
955 /* Packet Byte #3 */
956 uint8_t SC:2;
957 uint8_t Q:2;
958 uint8_t EC:3;
959 uint8_t ITC:1;
960 /* Packet Byte #4 */
961 uint8_t VIC:7;
962 uint8_t rsvd2:1;
963 /* Packet Byte #5 */
964 uint8_t PR:4;
965 uint8_t rsvd3:4;
966 /* Packet Byte #6~13 */
967 uint16_t top_bar_end;
968 uint16_t bottom_bar_start;
969 uint16_t left_bar_end;
970 uint16_t right_bar_start;
971 } avi;
972 struct {
973 /* Packet Byte #1 */
974 uint8_t channel_count:3;
975 uint8_t rsvd1:1;
976 uint8_t coding_type:4;
977 /* Packet Byte #2 */
978 uint8_t sample_size:2; /* SS0, SS1 */
979 uint8_t sample_frequency:3;
980 uint8_t rsvd2:3;
981 /* Packet Byte #3 */
982 uint8_t coding_type_private:5;
983 uint8_t rsvd3:3;
984 /* Packet Byte #4 */
985 uint8_t channel_allocation;
986 /* Packet Byte #5 */
987 uint8_t rsvd4:3;
988 uint8_t level_shift:4;
989 uint8_t downmix_inhibit:1;
990 } audio;
991 uint8_t payload[28];
992 } __attribute__ ((packed)) u;
993} __attribute__((packed));
994
Eric Anholtc751ce42010-03-25 11:48:48 -0700995static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800996 struct drm_display_mode * mode)
997{
998 struct dip_infoframe avi_if = {
999 .type = DIP_TYPE_AVI,
1000 .version = DIP_VERSION_AVI,
1001 .len = DIP_LEN_AVI,
1002 };
1003
1004 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
1005 4 + avi_if.len);
Eric Anholtc751ce42010-03-25 11:48:48 -07001006 intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if,
1007 4 + avi_if.len,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001008 SDVO_HBUF_TX_VSYNC);
1009}
1010
Eric Anholtc751ce42010-03-25 11:48:48 -07001011static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001012{
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001013
Zhao Yakuice6feab2009-08-24 13:50:26 +08001014 struct intel_sdvo_tv_format format;
Eric Anholtc751ce42010-03-25 11:48:48 -07001015 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001016 uint32_t format_map, i;
1017 uint8_t status;
1018
1019 for (i = 0; i < TV_FORMAT_NUM; i++)
1020 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1021 break;
1022
1023 format_map = 1 << i;
1024 memset(&format, 0, sizeof(format));
1025 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
1026 sizeof(format) : sizeof(format_map));
1027
Eric Anholtc751ce42010-03-25 11:48:48 -07001028 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format_map,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001029 sizeof(format));
1030
Eric Anholtc751ce42010-03-25 11:48:48 -07001031 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001032 if (status != SDVO_CMD_STATUS_SUCCESS)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001033 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
Zhao Yakuice6feab2009-08-24 13:50:26 +08001034 SDVO_NAME(sdvo_priv));
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001035}
1036
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001037static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1038 struct drm_display_mode *mode,
1039 struct drm_display_mode *adjusted_mode)
1040{
Eric Anholtc751ce42010-03-25 11:48:48 -07001041 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1042 struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001043
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001044 if (dev_priv->is_tv) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001045 struct intel_sdvo_dtd output_dtd;
1046 bool success;
1047
1048 /* We need to construct preferred input timings based on our
1049 * output timings. To do that, we have to set the output
1050 * timings, even though this isn't really the right place in
1051 * the sequence to do it. Oh well.
1052 */
1053
1054
1055 /* Set output timings */
1056 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
Eric Anholtc751ce42010-03-25 11:48:48 -07001057 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001058 dev_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001059 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001060
1061 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001062 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001063
1064
Eric Anholtc751ce42010-03-25 11:48:48 -07001065 success = intel_sdvo_create_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001066 mode->clock / 10,
1067 mode->hdisplay,
1068 mode->vdisplay);
1069 if (success) {
1070 struct intel_sdvo_dtd input_dtd;
1071
Eric Anholtc751ce42010-03-25 11:48:48 -07001072 intel_sdvo_get_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001073 &input_dtd);
1074 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001075 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001076
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001077 drm_mode_set_crtcinfo(adjusted_mode, 0);
1078
1079 mode->clock = adjusted_mode->clock;
1080
1081 adjusted_mode->clock *=
1082 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001083 } else {
1084 return false;
1085 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001086 } else if (dev_priv->is_lvds) {
1087 struct intel_sdvo_dtd output_dtd;
1088 bool success;
1089
1090 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1091 /* Set output timings */
1092 intel_sdvo_get_dtd_from_mode(&output_dtd,
1093 dev_priv->sdvo_lvds_fixed_mode);
1094
Eric Anholtc751ce42010-03-25 11:48:48 -07001095 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001096 dev_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001097 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001098
1099 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001100 intel_sdvo_set_target_input(intel_encoder, true, false);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001101
1102
1103 success = intel_sdvo_create_preferred_input_timing(
Eric Anholtc751ce42010-03-25 11:48:48 -07001104 intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001105 mode->clock / 10,
1106 mode->hdisplay,
1107 mode->vdisplay);
1108
1109 if (success) {
1110 struct intel_sdvo_dtd input_dtd;
1111
Eric Anholtc751ce42010-03-25 11:48:48 -07001112 intel_sdvo_get_preferred_input_timing(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001113 &input_dtd);
1114 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1115 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1116
1117 drm_mode_set_crtcinfo(adjusted_mode, 0);
1118
1119 mode->clock = adjusted_mode->clock;
1120
1121 adjusted_mode->clock *=
1122 intel_sdvo_get_pixel_multiplier(mode);
1123 } else {
1124 return false;
1125 }
1126
1127 } else {
1128 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1129 * SDVO device will be told of the multiplier during mode_set.
1130 */
1131 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001132 }
1133 return true;
1134}
1135
1136static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1137 struct drm_display_mode *mode,
1138 struct drm_display_mode *adjusted_mode)
1139{
1140 struct drm_device *dev = encoder->dev;
1141 struct drm_i915_private *dev_priv = dev->dev_private;
1142 struct drm_crtc *crtc = encoder->crtc;
1143 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Eric Anholtc751ce42010-03-25 11:48:48 -07001144 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1145 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001146 u32 sdvox = 0;
1147 int sdvo_pixel_multiply;
1148 struct intel_sdvo_in_out_map in_out;
1149 struct intel_sdvo_dtd input_dtd;
1150 u8 status;
1151
1152 if (!mode)
1153 return;
1154
1155 /* First, set the input mapping for the first input to our controlled
1156 * output. This is only correct if we're a single-input device, in
1157 * which case the first input is the output from the appropriate SDVO
1158 * channel on the motherboard. In a two-input device, the first input
1159 * will be SDVOB and the second SDVOC.
1160 */
Zhenyu Wang14571b42010-03-30 14:06:33 +08001161 in_out.in0 = sdvo_priv->attached_output;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001162 in_out.in1 = 0;
1163
Eric Anholtc751ce42010-03-25 11:48:48 -07001164 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001165 &in_out, sizeof(in_out));
Eric Anholtc751ce42010-03-25 11:48:48 -07001166 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001167
1168 if (sdvo_priv->is_hdmi) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001169 intel_sdvo_set_avi_infoframe(intel_encoder, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001170 sdvox |= SDVO_AUDIO_ENABLE;
1171 }
1172
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001173 /* We have tried to get input timing in mode_fixup, and filled into
1174 adjusted_mode */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001175 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001176 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001177 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
1178 } else
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001179 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001180
1181 /* If it's a TV, we already set the output timing in mode_fixup.
1182 * Otherwise, the output timing is equal to the input timing.
1183 */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001184 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001185 /* Set the output timing to the screen */
Eric Anholtc751ce42010-03-25 11:48:48 -07001186 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001187 sdvo_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001188 intel_sdvo_set_output_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001189 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001190
1191 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001192 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001193
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001194 if (sdvo_priv->is_tv)
Eric Anholtc751ce42010-03-25 11:48:48 -07001195 intel_sdvo_set_tv_format(intel_encoder);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001196
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001197 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001198 * provide the device with a timing it can support, if it supports that
1199 * feature. However, presumably we would need to adjust the CRTC to
1200 * output the preferred timing, and we don't support that currently.
1201 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001202#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -07001203 success = intel_sdvo_create_preferred_input_timing(encoder, clock,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001204 width, height);
1205 if (success) {
1206 struct intel_sdvo_dtd *input_dtd;
1207
Eric Anholtc751ce42010-03-25 11:48:48 -07001208 intel_sdvo_get_preferred_input_timing(encoder, &input_dtd);
1209 intel_sdvo_set_input_timing(encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001210 }
1211#else
Eric Anholtc751ce42010-03-25 11:48:48 -07001212 intel_sdvo_set_input_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001213#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001214
1215 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1216 case 1:
Eric Anholtc751ce42010-03-25 11:48:48 -07001217 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001218 SDVO_CLOCK_RATE_MULT_1X);
1219 break;
1220 case 2:
Eric Anholtc751ce42010-03-25 11:48:48 -07001221 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001222 SDVO_CLOCK_RATE_MULT_2X);
1223 break;
1224 case 4:
Eric Anholtc751ce42010-03-25 11:48:48 -07001225 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001226 SDVO_CLOCK_RATE_MULT_4X);
1227 break;
1228 }
1229
1230 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001231 if (IS_I965G(dev)) {
1232 sdvox |= SDVO_BORDER_ENABLE |
1233 SDVO_VSYNC_ACTIVE_HIGH |
1234 SDVO_HSYNC_ACTIVE_HIGH;
1235 } else {
Eric Anholtc751ce42010-03-25 11:48:48 -07001236 sdvox |= I915_READ(sdvo_priv->sdvo_reg);
1237 switch (sdvo_priv->sdvo_reg) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001238 case SDVOB:
1239 sdvox &= SDVOB_PRESERVE_MASK;
1240 break;
1241 case SDVOC:
1242 sdvox &= SDVOC_PRESERVE_MASK;
1243 break;
1244 }
1245 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1246 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001247 if (intel_crtc->pipe == 1)
1248 sdvox |= SDVO_PIPE_B_SELECT;
1249
1250 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1251 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001252 /* done in crtc_mode_set as the dpll_md reg must be written early */
1253 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1254 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001255 } else {
1256 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1257 }
1258
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001259 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
1260 sdvox |= SDVO_STALL_SELECT;
Eric Anholtc751ce42010-03-25 11:48:48 -07001261 intel_sdvo_write_sdvox(intel_encoder, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001262}
1263
1264static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1265{
1266 struct drm_device *dev = encoder->dev;
1267 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001268 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1269 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001270 u32 temp;
1271
1272 if (mode != DRM_MODE_DPMS_ON) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001273 intel_sdvo_set_active_outputs(intel_encoder, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -08001274 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001275 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -08001276
1277 if (mode == DRM_MODE_DPMS_OFF) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001278 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001279 if ((temp & SDVO_ENABLE) != 0) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001280 intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001281 }
1282 }
1283 } else {
1284 bool input1, input2;
1285 int i;
1286 u8 status;
1287
Eric Anholtc751ce42010-03-25 11:48:48 -07001288 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001289 if ((temp & SDVO_ENABLE) == 0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001290 intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001291 for (i = 0; i < 2; i++)
1292 intel_wait_for_vblank(dev);
1293
Eric Anholt21d40d32010-03-25 11:11:14 -07001294 status = intel_sdvo_get_trained_inputs(intel_encoder, &input1,
Jesse Barnes79e53942008-11-07 14:24:08 -08001295 &input2);
1296
1297
1298 /* Warn if the device reported failure to sync.
1299 * A lot of SDVO devices fail to notify of sync, but it's
1300 * a given it the status is a success, we succeeded.
1301 */
1302 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001303 DRM_DEBUG_KMS("First %s output reported failure to "
1304 "sync\n", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -08001305 }
1306
1307 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001308 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001309 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001310 }
1311 return;
1312}
1313
Jesse Barnes79e53942008-11-07 14:24:08 -08001314static int intel_sdvo_mode_valid(struct drm_connector *connector,
1315 struct drm_display_mode *mode)
1316{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001317 struct drm_encoder *encoder = intel_attached_encoder(connector);
1318 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001319 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001320
1321 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1322 return MODE_NO_DBLESCAN;
1323
1324 if (sdvo_priv->pixel_clock_min > mode->clock)
1325 return MODE_CLOCK_LOW;
1326
1327 if (sdvo_priv->pixel_clock_max < mode->clock)
1328 return MODE_CLOCK_HIGH;
1329
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001330 if (sdvo_priv->is_lvds == true) {
1331 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
1332 return MODE_PANEL;
1333
1334 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
1335 return MODE_PANEL;
1336
1337 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1338 return MODE_PANEL;
1339 }
1340
Jesse Barnes79e53942008-11-07 14:24:08 -08001341 return MODE_OK;
1342}
1343
Eric Anholt21d40d32010-03-25 11:11:14 -07001344static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps)
Jesse Barnes79e53942008-11-07 14:24:08 -08001345{
1346 u8 status;
1347
Eric Anholt21d40d32010-03-25 11:11:14 -07001348 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1349 status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps));
Jesse Barnes79e53942008-11-07 14:24:08 -08001350 if (status != SDVO_CMD_STATUS_SUCCESS)
1351 return false;
1352
1353 return true;
1354}
1355
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001356/* No use! */
1357#if 0
Jesse Barnes79e53942008-11-07 14:24:08 -08001358struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1359{
1360 struct drm_connector *connector = NULL;
Eric Anholt21d40d32010-03-25 11:11:14 -07001361 struct intel_encoder *iout = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001362 struct intel_sdvo_priv *sdvo;
1363
1364 /* find the sdvo connector */
1365 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001366 iout = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001367
1368 if (iout->type != INTEL_OUTPUT_SDVO)
1369 continue;
1370
1371 sdvo = iout->dev_priv;
1372
Eric Anholtc751ce42010-03-25 11:48:48 -07001373 if (sdvo->sdvo_reg == SDVOB && sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001374 return connector;
1375
Eric Anholtc751ce42010-03-25 11:48:48 -07001376 if (sdvo->sdvo_reg == SDVOC && !sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001377 return connector;
1378
1379 }
1380
1381 return NULL;
1382}
1383
1384int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1385{
1386 u8 response[2];
1387 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001388 struct intel_encoder *intel_encoder;
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001389 DRM_DEBUG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -08001390
1391 if (!connector)
1392 return 0;
1393
Eric Anholt21d40d32010-03-25 11:11:14 -07001394 intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001395
Eric Anholt21d40d32010-03-25 11:11:14 -07001396 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1397 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001398
1399 if (response[0] !=0)
1400 return 1;
1401
1402 return 0;
1403}
1404
1405void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1406{
1407 u8 response[2];
1408 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001409 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001410
Eric Anholt21d40d32010-03-25 11:11:14 -07001411 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1412 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001413
1414 if (on) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001415 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1416 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001417
Eric Anholt21d40d32010-03-25 11:11:14 -07001418 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001419 } else {
1420 response[0] = 0;
1421 response[1] = 0;
Eric Anholt21d40d32010-03-25 11:11:14 -07001422 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001423 }
1424
Eric Anholt21d40d32010-03-25 11:11:14 -07001425 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1426 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001427}
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001428#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001429
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001430static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07001431intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001432{
Eric Anholt21d40d32010-03-25 11:11:14 -07001433 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001434 int caps = 0;
1435
1436 if (sdvo_priv->caps.output_flags &
1437 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1438 caps++;
1439 if (sdvo_priv->caps.output_flags &
1440 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1441 caps++;
1442 if (sdvo_priv->caps.output_flags &
Roel Kluin19e1f882009-08-09 13:50:53 +02001443 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001444 caps++;
1445 if (sdvo_priv->caps.output_flags &
1446 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1447 caps++;
1448 if (sdvo_priv->caps.output_flags &
1449 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1450 caps++;
1451
1452 if (sdvo_priv->caps.output_flags &
1453 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1454 caps++;
1455
1456 if (sdvo_priv->caps.output_flags &
1457 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1458 caps++;
1459
1460 return (caps > 1);
1461}
1462
Keith Packard57cdaf92009-09-04 13:07:54 +08001463static struct drm_connector *
1464intel_find_analog_connector(struct drm_device *dev)
1465{
1466 struct drm_connector *connector;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001467 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07001468 struct intel_encoder *intel_encoder;
Keith Packard57cdaf92009-09-04 13:07:54 +08001469
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001470 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1471 intel_encoder = enc_to_intel_encoder(encoder);
1472 if (intel_encoder->type == INTEL_OUTPUT_ANALOG) {
1473 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1474 if (connector && encoder == intel_attached_encoder(connector))
1475 return connector;
1476 }
1477 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001478 }
1479 return NULL;
1480}
1481
1482static int
1483intel_analog_is_connected(struct drm_device *dev)
1484{
1485 struct drm_connector *analog_connector;
1486 analog_connector = intel_find_analog_connector(dev);
1487
1488 if (!analog_connector)
1489 return false;
1490
1491 if (analog_connector->funcs->detect(analog_connector) ==
1492 connector_status_disconnected)
1493 return false;
1494
1495 return true;
1496}
1497
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001498enum drm_connector_status
1499intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
Ma Ling9dff6af2009-04-02 13:13:26 +08001500{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001501 struct drm_encoder *encoder = intel_attached_encoder(connector);
1502 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001503 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001504 enum drm_connector_status status = connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001505 struct edid *edid = NULL;
1506
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001507 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001508 intel_encoder->ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001509
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001510 /* This is only applied to SDVO cards with multiple outputs */
Eric Anholt21d40d32010-03-25 11:11:14 -07001511 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) {
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001512 uint8_t saved_ddc, temp_ddc;
1513 saved_ddc = sdvo_priv->ddc_bus;
1514 temp_ddc = sdvo_priv->ddc_bus >> 1;
1515 /*
1516 * Don't use the 1 as the argument of DDC bus switch to get
1517 * the EDID. It is used for SDVO SPD ROM.
1518 */
1519 while(temp_ddc > 1) {
1520 sdvo_priv->ddc_bus = temp_ddc;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001521 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001522 intel_encoder->ddc_bus);
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001523 if (edid) {
1524 /*
1525 * When we can get the EDID, maybe it is the
1526 * correct DDC bus. Update it.
1527 */
1528 sdvo_priv->ddc_bus = temp_ddc;
1529 break;
1530 }
1531 temp_ddc >>= 1;
1532 }
1533 if (edid == NULL)
1534 sdvo_priv->ddc_bus = saved_ddc;
1535 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001536 /* when there is no edid and no monitor is connected with VGA
1537 * port, try to use the CRT ddc to read the EDID for DVI-connector
1538 */
1539 if (edid == NULL &&
1540 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001541 !intel_analog_is_connected(connector->dev))
1542 edid = drm_get_edid(connector,
Keith Packard57cdaf92009-09-04 13:07:54 +08001543 sdvo_priv->analog_ddc_bus);
Ma Ling9dff6af2009-04-02 13:13:26 +08001544 if (edid != NULL) {
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001545 /* Don't report the output as connected if it's a DVI-I
1546 * connector with a non-digital EDID coming out.
1547 */
1548 if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
1549 if (edid->input & DRM_EDID_INPUT_DIGITAL)
1550 sdvo_priv->is_hdmi =
1551 drm_detect_hdmi_monitor(edid);
1552 else
1553 status = connector_status_disconnected;
1554 }
1555
Ma Ling9dff6af2009-04-02 13:13:26 +08001556 kfree(edid);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001557 connector->display_info.raw_edid = NULL;
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001558
1559 } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1560 status = connector_status_disconnected;
1561
1562 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +08001563}
1564
Jesse Barnes79e53942008-11-07 14:24:08 -08001565static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1566{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001567 uint16_t response;
Jesse Barnes79e53942008-11-07 14:24:08 -08001568 u8 status;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001569 struct drm_encoder *encoder = intel_attached_encoder(connector);
1570 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1571 struct intel_connector *intel_connector = to_intel_connector(connector);
Eric Anholt21d40d32010-03-25 11:11:14 -07001572 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001573 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1574 enum drm_connector_status ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001575
Eric Anholt21d40d32010-03-25 11:11:14 -07001576 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001577 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
Zhao Yakuid09c23d2009-11-06 15:39:56 +08001578 if (sdvo_priv->is_tv) {
1579 /* add 30ms delay when the output type is SDVO-TV */
1580 mdelay(30);
1581 }
Eric Anholt21d40d32010-03-25 11:11:14 -07001582 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001583
Dave Airlie51c8b402009-08-20 13:38:04 +10001584 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001585
1586 if (status != SDVO_CMD_STATUS_SUCCESS)
1587 return connector_status_unknown;
1588
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001589 if (response == 0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001590 return connector_status_disconnected;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001591
Zhenyu Wang14571b42010-03-30 14:06:33 +08001592 sdvo_priv->attached_output = response;
1593
1594 if ((sdvo_connector->output_flag & response) == 0)
1595 ret = connector_status_disconnected;
1596 else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1597 ret = intel_sdvo_hdmi_sink_detect(connector, response);
1598 else
1599 ret = connector_status_connected;
1600
1601 /* May update encoder flag for like clock for SDVO TV, etc.*/
1602 if (ret == connector_status_connected) {
1603 sdvo_priv->is_tv = false;
1604 sdvo_priv->is_lvds = false;
1605 intel_encoder->needs_tv_clock = false;
1606
1607 if (response & SDVO_TV_MASK) {
1608 sdvo_priv->is_tv = true;
1609 intel_encoder->needs_tv_clock = true;
1610 }
1611 if (response & SDVO_LVDS_MASK)
1612 sdvo_priv->is_lvds = true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001613 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001614
1615 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001616}
1617
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001618static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001619{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001620 struct drm_encoder *encoder = intel_attached_encoder(connector);
1621 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001622 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Keith Packard57cdaf92009-09-04 13:07:54 +08001623 int num_modes;
Jesse Barnes79e53942008-11-07 14:24:08 -08001624
1625 /* set the bus switch and get the modes */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001626 num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001627
Keith Packard57cdaf92009-09-04 13:07:54 +08001628 /*
1629 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1630 * link between analog and digital outputs. So, if the regular SDVO
1631 * DDC fails, check to see if the analog output is disconnected, in
1632 * which case we'll look there for the digital DDC data.
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001633 */
Keith Packard57cdaf92009-09-04 13:07:54 +08001634 if (num_modes == 0 &&
1635 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001636 !intel_analog_is_connected(connector->dev)) {
Keith Packard57cdaf92009-09-04 13:07:54 +08001637 /* Switch to the analog ddc bus and try that
1638 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001639 (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001640 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001641}
1642
1643/*
1644 * Set of SDVO TV modes.
1645 * Note! This is in reply order (see loop in get_tv_modes).
1646 * XXX: all 60Hz refresh?
1647 */
1648struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001649 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1650 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001651 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001652 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1653 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001654 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001655 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1656 496, 0, 300, 301, 332, 333, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001657 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001658 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1659 736, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001660 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001661 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1662 736, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001663 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001664 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1665 736, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001666 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001667 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1668 800, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001669 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001670 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1671 800, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001672 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001673 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1674 816, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001675 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001676 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1677 816, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001678 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001679 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1680 816, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001681 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001682 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1683 816, 0, 540, 541, 572, 573, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001684 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001685 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1686 816, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001687 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001688 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1689 864, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001690 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001691 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1692 896, 0, 600, 601, 632, 633, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001693 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001694 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1695 928, 0, 624, 625, 656, 657, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001696 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001697 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1698 1016, 0, 766, 767, 798, 799, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001699 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001700 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1701 1120, 0, 768, 769, 800, 801, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001702 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001703 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1704 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001705 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1706};
1707
1708static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1709{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001710 struct drm_encoder *encoder = intel_attached_encoder(connector);
1711 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1712 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001713 struct intel_sdvo_sdtv_resolution_request tv_res;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001714 uint32_t reply = 0, format_map = 0;
1715 int i;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001716 uint8_t status;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001717
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001718
1719 /* Read the list of supported input resolutions for the selected TV
1720 * format.
1721 */
Zhao Yakuice6feab2009-08-24 13:50:26 +08001722 for (i = 0; i < TV_FORMAT_NUM; i++)
1723 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1724 break;
1725
1726 format_map = (1 << i);
1727 memcpy(&tv_res, &format_map,
1728 sizeof(struct intel_sdvo_sdtv_resolution_request) >
1729 sizeof(format_map) ? sizeof(format_map) :
1730 sizeof(struct intel_sdvo_sdtv_resolution_request));
1731
Zhenyu Wang14571b42010-03-30 14:06:33 +08001732 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001733
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001734 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001735 &tv_res, sizeof(tv_res));
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001736 status = intel_sdvo_read_response(intel_encoder, &reply, 3);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001737 if (status != SDVO_CMD_STATUS_SUCCESS)
1738 return;
1739
1740 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001741 if (reply & (1 << i)) {
1742 struct drm_display_mode *nmode;
1743 nmode = drm_mode_duplicate(connector->dev,
1744 &sdvo_tv_modes[i]);
1745 if (nmode)
1746 drm_mode_probed_add(connector, nmode);
1747 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001748
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001749}
1750
Ma Ling7086c872009-05-13 11:20:06 +08001751static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1752{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001753 struct drm_encoder *encoder = intel_attached_encoder(connector);
1754 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Ma Ling7086c872009-05-13 11:20:06 +08001755 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001756 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001757 struct drm_display_mode *newmode;
Ma Ling7086c872009-05-13 11:20:06 +08001758
1759 /*
1760 * Attempt to get the mode list from DDC.
1761 * Assume that the preferred modes are
1762 * arranged in priority order.
1763 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001764 intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Ma Ling7086c872009-05-13 11:20:06 +08001765 if (list_empty(&connector->probed_modes) == false)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001766 goto end;
Ma Ling7086c872009-05-13 11:20:06 +08001767
1768 /* Fetch modes from VBT */
1769 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
Ma Ling7086c872009-05-13 11:20:06 +08001770 newmode = drm_mode_duplicate(connector->dev,
1771 dev_priv->sdvo_lvds_vbt_mode);
1772 if (newmode != NULL) {
1773 /* Guarantee the mode is preferred */
1774 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1775 DRM_MODE_TYPE_DRIVER);
1776 drm_mode_probed_add(connector, newmode);
1777 }
1778 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001779
1780end:
1781 list_for_each_entry(newmode, &connector->probed_modes, head) {
1782 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1783 sdvo_priv->sdvo_lvds_fixed_mode =
1784 drm_mode_duplicate(connector->dev, newmode);
1785 break;
1786 }
1787 }
1788
Ma Ling7086c872009-05-13 11:20:06 +08001789}
1790
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001791static int intel_sdvo_get_modes(struct drm_connector *connector)
1792{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001793 struct intel_connector *intel_connector = to_intel_connector(connector);
1794 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001795
Zhenyu Wang14571b42010-03-30 14:06:33 +08001796 if (IS_TV(sdvo_connector))
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001797 intel_sdvo_get_tv_modes(connector);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001798 else if (IS_LVDS(sdvo_connector))
Ma Ling7086c872009-05-13 11:20:06 +08001799 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001800 else
1801 intel_sdvo_get_ddc_modes(connector);
1802
Jesse Barnes79e53942008-11-07 14:24:08 -08001803 if (list_empty(&connector->probed_modes))
1804 return 0;
1805 return 1;
1806}
1807
Zhao Yakuib9219c52009-09-10 15:45:46 +08001808static
1809void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1810{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001811 struct intel_connector *intel_connector = to_intel_connector(connector);
1812 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
1813 struct drm_device *dev = connector->dev;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001814
Zhenyu Wang14571b42010-03-30 14:06:33 +08001815 if (IS_TV(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001816 if (sdvo_priv->left_property)
1817 drm_property_destroy(dev, sdvo_priv->left_property);
1818 if (sdvo_priv->right_property)
1819 drm_property_destroy(dev, sdvo_priv->right_property);
1820 if (sdvo_priv->top_property)
1821 drm_property_destroy(dev, sdvo_priv->top_property);
1822 if (sdvo_priv->bottom_property)
1823 drm_property_destroy(dev, sdvo_priv->bottom_property);
1824 if (sdvo_priv->hpos_property)
1825 drm_property_destroy(dev, sdvo_priv->hpos_property);
1826 if (sdvo_priv->vpos_property)
1827 drm_property_destroy(dev, sdvo_priv->vpos_property);
Zhao Yakuib9219c52009-09-10 15:45:46 +08001828 if (sdvo_priv->saturation_property)
1829 drm_property_destroy(dev,
1830 sdvo_priv->saturation_property);
1831 if (sdvo_priv->contrast_property)
1832 drm_property_destroy(dev,
1833 sdvo_priv->contrast_property);
1834 if (sdvo_priv->hue_property)
1835 drm_property_destroy(dev, sdvo_priv->hue_property);
1836 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001837 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001838 if (sdvo_priv->brightness_property)
1839 drm_property_destroy(dev,
1840 sdvo_priv->brightness_property);
1841 }
1842 return;
1843}
1844
Jesse Barnes79e53942008-11-07 14:24:08 -08001845static void intel_sdvo_destroy(struct drm_connector *connector)
1846{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001847 struct intel_connector *intel_connector = to_intel_connector(connector);
1848 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1849
1850 if (sdvo_connector->tv_format_property)
1851 drm_property_destroy(connector->dev,
1852 sdvo_connector->tv_format_property);
1853
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001854 intel_sdvo_destroy_enhance_property(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001855 drm_sysfs_connector_remove(connector);
1856 drm_connector_cleanup(connector);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001857 kfree(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001858}
1859
Zhao Yakuice6feab2009-08-24 13:50:26 +08001860static int
1861intel_sdvo_set_property(struct drm_connector *connector,
1862 struct drm_property *property,
1863 uint64_t val)
1864{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001865 struct drm_encoder *encoder = intel_attached_encoder(connector);
1866 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001867 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001868 struct intel_connector *intel_connector = to_intel_connector(connector);
1869 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001870 struct drm_crtc *crtc = encoder->crtc;
1871 int ret = 0;
1872 bool changed = false;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001873 uint8_t cmd, status;
1874 uint16_t temp_value;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001875
1876 ret = drm_connector_property_set_value(connector, property, val);
1877 if (ret < 0)
1878 goto out;
1879
Zhenyu Wang14571b42010-03-30 14:06:33 +08001880 if (property == sdvo_connector->tv_format_property) {
Zhao Yakuice6feab2009-08-24 13:50:26 +08001881 if (val >= TV_FORMAT_NUM) {
1882 ret = -EINVAL;
1883 goto out;
1884 }
1885 if (sdvo_priv->tv_format_name ==
Zhenyu Wang14571b42010-03-30 14:06:33 +08001886 sdvo_connector->tv_format_supported[val])
Zhao Yakuice6feab2009-08-24 13:50:26 +08001887 goto out;
1888
Zhenyu Wang14571b42010-03-30 14:06:33 +08001889 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val];
Zhao Yakuice6feab2009-08-24 13:50:26 +08001890 changed = true;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001891 }
1892
Zhenyu Wang14571b42010-03-30 14:06:33 +08001893 if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001894 cmd = 0;
1895 temp_value = val;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001896 if (sdvo_connector->left_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001897 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001898 sdvo_connector->right_property, val);
1899 if (sdvo_connector->left_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001900 goto out;
1901
Zhenyu Wang14571b42010-03-30 14:06:33 +08001902 sdvo_connector->left_margin = temp_value;
1903 sdvo_connector->right_margin = temp_value;
1904 temp_value = sdvo_connector->max_hscan -
1905 sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001906 cmd = SDVO_CMD_SET_OVERSCAN_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001907 } else if (sdvo_connector->right_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001908 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001909 sdvo_connector->left_property, val);
1910 if (sdvo_connector->right_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001911 goto out;
1912
Zhenyu Wang14571b42010-03-30 14:06:33 +08001913 sdvo_connector->left_margin = temp_value;
1914 sdvo_connector->right_margin = temp_value;
1915 temp_value = sdvo_connector->max_hscan -
1916 sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001917 cmd = SDVO_CMD_SET_OVERSCAN_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001918 } else if (sdvo_connector->top_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001919 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001920 sdvo_connector->bottom_property, val);
1921 if (sdvo_connector->top_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001922 goto out;
1923
Zhenyu Wang14571b42010-03-30 14:06:33 +08001924 sdvo_connector->top_margin = temp_value;
1925 sdvo_connector->bottom_margin = temp_value;
1926 temp_value = sdvo_connector->max_vscan -
1927 sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001928 cmd = SDVO_CMD_SET_OVERSCAN_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001929 } else if (sdvo_connector->bottom_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001930 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001931 sdvo_connector->top_property, val);
1932 if (sdvo_connector->bottom_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001933 goto out;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001934 sdvo_connector->top_margin = temp_value;
1935 sdvo_connector->bottom_margin = temp_value;
1936 temp_value = sdvo_connector->max_vscan -
1937 sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001938 cmd = SDVO_CMD_SET_OVERSCAN_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001939 } else if (sdvo_connector->hpos_property == property) {
1940 if (sdvo_connector->cur_hpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001941 goto out;
1942
1943 cmd = SDVO_CMD_SET_POSITION_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001944 sdvo_connector->cur_hpos = temp_value;
1945 } else if (sdvo_connector->vpos_property == property) {
1946 if (sdvo_connector->cur_vpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001947 goto out;
1948
1949 cmd = SDVO_CMD_SET_POSITION_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001950 sdvo_connector->cur_vpos = temp_value;
1951 } else if (sdvo_connector->saturation_property == property) {
1952 if (sdvo_connector->cur_saturation == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001953 goto out;
1954
1955 cmd = SDVO_CMD_SET_SATURATION;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001956 sdvo_connector->cur_saturation = temp_value;
1957 } else if (sdvo_connector->contrast_property == property) {
1958 if (sdvo_connector->cur_contrast == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001959 goto out;
1960
1961 cmd = SDVO_CMD_SET_CONTRAST;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001962 sdvo_connector->cur_contrast = temp_value;
1963 } else if (sdvo_connector->hue_property == property) {
1964 if (sdvo_connector->cur_hue == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001965 goto out;
1966
1967 cmd = SDVO_CMD_SET_HUE;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001968 sdvo_connector->cur_hue = temp_value;
1969 } else if (sdvo_connector->brightness_property == property) {
1970 if (sdvo_connector->cur_brightness == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001971 goto out;
1972
1973 cmd = SDVO_CMD_SET_BRIGHTNESS;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001974 sdvo_connector->cur_brightness = temp_value;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001975 }
1976 if (cmd) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001977 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
1978 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08001979 NULL, 0);
1980 if (status != SDVO_CMD_STATUS_SUCCESS) {
1981 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1982 return -EINVAL;
1983 }
1984 changed = true;
1985 }
1986 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001987 if (changed && crtc)
1988 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1989 crtc->y, crtc->fb);
1990out:
1991 return ret;
1992}
1993
Jesse Barnes79e53942008-11-07 14:24:08 -08001994static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1995 .dpms = intel_sdvo_dpms,
1996 .mode_fixup = intel_sdvo_mode_fixup,
1997 .prepare = intel_encoder_prepare,
1998 .mode_set = intel_sdvo_mode_set,
1999 .commit = intel_encoder_commit,
2000};
2001
2002static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -07002003 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -08002004 .detect = intel_sdvo_detect,
2005 .fill_modes = drm_helper_probe_single_connector_modes,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002006 .set_property = intel_sdvo_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -08002007 .destroy = intel_sdvo_destroy,
2008};
2009
2010static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2011 .get_modes = intel_sdvo_get_modes,
2012 .mode_valid = intel_sdvo_mode_valid,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002013 .best_encoder = intel_attached_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002014};
2015
Hannes Ederb358d0a2008-12-18 21:18:47 +01002016static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08002017{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002018 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
2019 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2020
2021 if (intel_encoder->i2c_bus)
2022 intel_i2c_destroy(intel_encoder->i2c_bus);
2023 if (intel_encoder->ddc_bus)
2024 intel_i2c_destroy(intel_encoder->ddc_bus);
2025 if (sdvo_priv->analog_ddc_bus)
2026 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
2027
2028 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
2029 drm_mode_destroy(encoder->dev,
2030 sdvo_priv->sdvo_lvds_fixed_mode);
2031
Jesse Barnes79e53942008-11-07 14:24:08 -08002032 drm_encoder_cleanup(encoder);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002033 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002034}
2035
2036static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2037 .destroy = intel_sdvo_enc_destroy,
2038};
2039
2040
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002041/**
2042 * Choose the appropriate DDC bus for control bus switch command for this
2043 * SDVO output based on the controlled output.
2044 *
2045 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2046 * outputs, then LVDS outputs.
2047 */
2048static void
2049intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
2050{
2051 uint16_t mask = 0;
2052 unsigned int num_bits;
2053
2054 /* Make a mask of outputs less than or equal to our own priority in the
2055 * list.
2056 */
2057 switch (dev_priv->controlled_output) {
2058 case SDVO_OUTPUT_LVDS1:
2059 mask |= SDVO_OUTPUT_LVDS1;
2060 case SDVO_OUTPUT_LVDS0:
2061 mask |= SDVO_OUTPUT_LVDS0;
2062 case SDVO_OUTPUT_TMDS1:
2063 mask |= SDVO_OUTPUT_TMDS1;
2064 case SDVO_OUTPUT_TMDS0:
2065 mask |= SDVO_OUTPUT_TMDS0;
2066 case SDVO_OUTPUT_RGB1:
2067 mask |= SDVO_OUTPUT_RGB1;
2068 case SDVO_OUTPUT_RGB0:
2069 mask |= SDVO_OUTPUT_RGB0;
2070 break;
2071 }
2072
2073 /* Count bits to find what number we are in the priority list. */
2074 mask &= dev_priv->caps.output_flags;
2075 num_bits = hweight16(mask);
2076 if (num_bits > 3) {
2077 /* if more than 3 outputs, default to DDC bus 3 for now */
2078 num_bits = 3;
2079 }
2080
2081 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2082 dev_priv->ddc_bus = 1 << num_bits;
2083}
2084
2085static bool
Zhenyu Wang14571b42010-03-30 14:06:33 +08002086intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002087{
2088 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
2089 uint8_t status;
2090
Zhenyu Wang14571b42010-03-30 14:06:33 +08002091 if (device == 0)
2092 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0);
2093 else
2094 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002095
2096 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2097 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
2098 if (status != SDVO_CMD_STATUS_SUCCESS)
2099 return false;
2100 return true;
2101}
2102
Eric Anholt21d40d32010-03-25 11:11:14 -07002103static struct intel_encoder *
2104intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan)
Ma Ling619ac3b2009-05-18 16:12:46 +08002105{
2106 struct drm_device *dev = chan->drm_dev;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002107 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07002108 struct intel_encoder *intel_encoder = NULL;
Ma Ling619ac3b2009-05-18 16:12:46 +08002109
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002110 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2111 intel_encoder = enc_to_intel_encoder(encoder);
2112 if (intel_encoder->ddc_bus == &chan->adapter)
Ma Ling619ac3b2009-05-18 16:12:46 +08002113 break;
Ma Ling619ac3b2009-05-18 16:12:46 +08002114 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002115 return intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002116}
2117
2118static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2119 struct i2c_msg msgs[], int num)
2120{
Eric Anholt21d40d32010-03-25 11:11:14 -07002121 struct intel_encoder *intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002122 struct intel_sdvo_priv *sdvo_priv;
2123 struct i2c_algo_bit_data *algo_data;
Keith Packardf9c10a92009-05-30 12:16:25 -07002124 const struct i2c_algorithm *algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002125
2126 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
Eric Anholt21d40d32010-03-25 11:11:14 -07002127 intel_encoder =
2128 intel_sdvo_chan_to_intel_encoder(
Ma Ling619ac3b2009-05-18 16:12:46 +08002129 (struct intel_i2c_chan *)(algo_data->data));
Eric Anholt21d40d32010-03-25 11:11:14 -07002130 if (intel_encoder == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002131 return -EINVAL;
2132
Eric Anholt21d40d32010-03-25 11:11:14 -07002133 sdvo_priv = intel_encoder->dev_priv;
2134 algo = intel_encoder->i2c_bus->algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002135
Eric Anholt21d40d32010-03-25 11:11:14 -07002136 intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08002137 return algo->master_xfer(i2c_adap, msgs, num);
2138}
2139
2140static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
2141 .master_xfer = intel_sdvo_master_xfer,
2142};
2143
yakui_zhao714605e2009-05-31 17:18:07 +08002144static u8
Eric Anholtc751ce42010-03-25 11:48:48 -07002145intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
yakui_zhao714605e2009-05-31 17:18:07 +08002146{
2147 struct drm_i915_private *dev_priv = dev->dev_private;
2148 struct sdvo_device_mapping *my_mapping, *other_mapping;
2149
Eric Anholtc751ce42010-03-25 11:48:48 -07002150 if (sdvo_reg == SDVOB) {
yakui_zhao714605e2009-05-31 17:18:07 +08002151 my_mapping = &dev_priv->sdvo_mappings[0];
2152 other_mapping = &dev_priv->sdvo_mappings[1];
2153 } else {
2154 my_mapping = &dev_priv->sdvo_mappings[1];
2155 other_mapping = &dev_priv->sdvo_mappings[0];
2156 }
2157
2158 /* If the BIOS described our SDVO device, take advantage of it. */
2159 if (my_mapping->slave_addr)
2160 return my_mapping->slave_addr;
2161
2162 /* If the BIOS only described a different SDVO device, use the
2163 * address that it isn't using.
2164 */
2165 if (other_mapping->slave_addr) {
2166 if (other_mapping->slave_addr == 0x70)
2167 return 0x72;
2168 else
2169 return 0x70;
2170 }
2171
2172 /* No SDVO device info is found for another DVO port,
2173 * so use mapping assumption we had before BIOS parsing.
2174 */
Eric Anholtc751ce42010-03-25 11:48:48 -07002175 if (sdvo_reg == SDVOB)
yakui_zhao714605e2009-05-31 17:18:07 +08002176 return 0x70;
2177 else
2178 return 0x72;
2179}
2180
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002181static bool
Zhenyu Wang14571b42010-03-30 14:06:33 +08002182intel_sdvo_connector_alloc (struct intel_connector **ret)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002183{
Zhenyu Wang14571b42010-03-30 14:06:33 +08002184 struct intel_connector *intel_connector;
2185 struct intel_sdvo_connector *sdvo_connector;
2186
2187 *ret = kzalloc(sizeof(*intel_connector) +
2188 sizeof(*sdvo_connector), GFP_KERNEL);
2189 if (!*ret)
2190 return false;
2191
2192 intel_connector = *ret;
2193 sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1);
2194 intel_connector->dev_priv = sdvo_connector;
2195
2196 return true;
2197}
2198
2199static void
2200intel_sdvo_connector_create (struct drm_encoder *encoder,
2201 struct drm_connector *connector)
2202{
2203 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs,
2204 connector->connector_type);
2205
2206 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2207
2208 connector->interlace_allowed = 0;
2209 connector->doublescan_allowed = 0;
2210 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2211
2212 drm_mode_connector_attach_encoder(connector, encoder);
2213 drm_sysfs_connector_add(connector);
2214}
2215
2216static bool
2217intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device)
2218{
Eric Anholt21d40d32010-03-25 11:11:14 -07002219 struct drm_encoder *encoder = &intel_encoder->enc;
2220 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002221 struct drm_connector *connector;
2222 struct intel_connector *intel_connector;
2223 struct intel_sdvo_connector *sdvo_connector;
2224
2225 if (!intel_sdvo_connector_alloc(&intel_connector))
2226 return false;
2227
2228 sdvo_connector = intel_connector->dev_priv;
2229
2230 if (device == 0) {
2231 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0;
2232 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2233 } else if (device == 1) {
2234 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1;
2235 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2236 }
2237
2238 connector = &intel_connector->base;
2239 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2240 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2241
2242 if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode)
2243 && intel_sdvo_get_digital_encoding_mode(intel_encoder, device)
2244 && sdvo_priv->is_hdmi) {
2245 /* enable hdmi encoding mode if supported */
2246 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI);
2247 intel_sdvo_set_colorimetry(intel_encoder,
2248 SDVO_COLORIMETRY_RGB256);
2249 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2250 }
2251 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2252 (1 << INTEL_ANALOG_CLONE_BIT);
2253
2254 intel_sdvo_connector_create(encoder, connector);
2255
2256 return true;
2257}
2258
2259static bool
2260intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type)
2261{
2262 struct drm_encoder *encoder = &intel_encoder->enc;
2263 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2264 struct drm_connector *connector;
2265 struct intel_connector *intel_connector;
2266 struct intel_sdvo_connector *sdvo_connector;
2267
2268 if (!intel_sdvo_connector_alloc(&intel_connector))
2269 return false;
2270
2271 connector = &intel_connector->base;
2272 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2273 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2274 sdvo_connector = intel_connector->dev_priv;
2275
2276 sdvo_priv->controlled_output |= type;
2277 sdvo_connector->output_flag = type;
2278
2279 sdvo_priv->is_tv = true;
2280 intel_encoder->needs_tv_clock = true;
2281 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
2282
2283 intel_sdvo_connector_create(encoder, connector);
2284
2285 intel_sdvo_tv_create_property(connector, type);
2286
2287 intel_sdvo_create_enhance_property(connector);
2288
2289 return true;
2290}
2291
2292static bool
2293intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device)
2294{
2295 struct drm_encoder *encoder = &intel_encoder->enc;
2296 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2297 struct drm_connector *connector;
2298 struct intel_connector *intel_connector;
2299 struct intel_sdvo_connector *sdvo_connector;
2300
2301 if (!intel_sdvo_connector_alloc(&intel_connector))
2302 return false;
2303
2304 connector = &intel_connector->base;
2305 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2306 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2307 sdvo_connector = intel_connector->dev_priv;
2308
2309 if (device == 0) {
2310 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0;
2311 sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2312 } else if (device == 1) {
2313 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1;
2314 sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2315 }
2316
2317 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2318 (1 << INTEL_ANALOG_CLONE_BIT);
2319
2320 intel_sdvo_connector_create(encoder, connector);
2321 return true;
2322}
2323
2324static bool
2325intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device)
2326{
2327 struct drm_encoder *encoder = &intel_encoder->enc;
2328 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2329 struct drm_connector *connector;
2330 struct intel_connector *intel_connector;
2331 struct intel_sdvo_connector *sdvo_connector;
2332
2333 if (!intel_sdvo_connector_alloc(&intel_connector))
2334 return false;
2335
2336 connector = &intel_connector->base;
2337 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2338 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2339 sdvo_connector = intel_connector->dev_priv;
2340
2341 sdvo_priv->is_lvds = true;
2342
2343 if (device == 0) {
2344 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0;
2345 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2346 } else if (device == 1) {
2347 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1;
2348 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2349 }
2350
2351 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
2352 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
2353
2354 intel_sdvo_connector_create(encoder, connector);
2355 intel_sdvo_create_enhance_property(connector);
2356 return true;
2357}
2358
2359static bool
2360intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags)
2361{
2362 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002363
2364 sdvo_priv->is_tv = false;
Eric Anholt21d40d32010-03-25 11:11:14 -07002365 intel_encoder->needs_tv_clock = false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002366 sdvo_priv->is_lvds = false;
2367
Zhenyu Wang14571b42010-03-30 14:06:33 +08002368 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002369
Zhenyu Wang14571b42010-03-30 14:06:33 +08002370 if (flags & SDVO_OUTPUT_TMDS0)
2371 if (!intel_sdvo_dvi_init(intel_encoder, 0))
2372 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002373
Zhenyu Wang14571b42010-03-30 14:06:33 +08002374 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2375 if (!intel_sdvo_dvi_init(intel_encoder, 1))
2376 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002377
Zhenyu Wang14571b42010-03-30 14:06:33 +08002378 /* TV has no XXX1 function block */
Zhenyu Wanga1f4b7f2010-03-29 23:16:13 +08002379 if (flags & SDVO_OUTPUT_SVID0)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002380 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0))
2381 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002382
Zhenyu Wang14571b42010-03-30 14:06:33 +08002383 if (flags & SDVO_OUTPUT_CVBS0)
2384 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0))
2385 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002386
Zhenyu Wang14571b42010-03-30 14:06:33 +08002387 if (flags & SDVO_OUTPUT_RGB0)
2388 if (!intel_sdvo_analog_init(intel_encoder, 0))
2389 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002390
Zhenyu Wang14571b42010-03-30 14:06:33 +08002391 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2392 if (!intel_sdvo_analog_init(intel_encoder, 1))
2393 return false;
Zhao Yakui2dd87382010-01-27 16:32:46 +08002394
Zhenyu Wang14571b42010-03-30 14:06:33 +08002395 if (flags & SDVO_OUTPUT_LVDS0)
2396 if (!intel_sdvo_lvds_init(intel_encoder, 0))
2397 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002398
Zhenyu Wang14571b42010-03-30 14:06:33 +08002399 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2400 if (!intel_sdvo_lvds_init(intel_encoder, 1))
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_MASK) == 0) {
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002404 unsigned char bytes[2];
2405
2406 sdvo_priv->controlled_output = 0;
2407 memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
Dave Airlie51c8b402009-08-20 13:38:04 +10002408 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2409 SDVO_NAME(sdvo_priv),
2410 bytes[0], bytes[1]);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002411 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002412 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002413 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002414
Zhenyu Wang14571b42010-03-30 14:06:33 +08002415 return true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002416}
2417
Zhenyu Wang14571b42010-03-30 14:06:33 +08002418static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002419{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002420 struct drm_encoder *encoder = intel_attached_encoder(connector);
2421 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07002422 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002423 struct intel_connector *intel_connector = to_intel_connector(connector);
2424 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002425 struct intel_sdvo_tv_format format;
2426 uint32_t format_map, i;
2427 uint8_t status;
2428
Zhenyu Wang14571b42010-03-30 14:06:33 +08002429 intel_sdvo_set_target_output(intel_encoder, type);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002430
Eric Anholt21d40d32010-03-25 11:11:14 -07002431 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002432 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002433 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002434 &format, sizeof(format));
2435 if (status != SDVO_CMD_STATUS_SUCCESS)
2436 return;
2437
2438 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
2439 sizeof(format_map) : sizeof(format));
2440
2441 if (format_map == 0)
2442 return;
2443
Zhenyu Wang14571b42010-03-30 14:06:33 +08002444 sdvo_connector->format_supported_num = 0;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002445 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2446 if (format_map & (1 << i)) {
Zhenyu Wang14571b42010-03-30 14:06:33 +08002447 sdvo_connector->tv_format_supported
2448 [sdvo_connector->format_supported_num++] =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002449 tv_format_names[i];
2450 }
2451
2452
Zhenyu Wang14571b42010-03-30 14:06:33 +08002453 sdvo_connector->tv_format_property =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002454 drm_property_create(
2455 connector->dev, DRM_MODE_PROP_ENUM,
Zhenyu Wang14571b42010-03-30 14:06:33 +08002456 "mode", sdvo_connector->format_supported_num);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002457
Zhenyu Wang14571b42010-03-30 14:06:33 +08002458 for (i = 0; i < sdvo_connector->format_supported_num; i++)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002459 drm_property_add_enum(
Zhenyu Wang14571b42010-03-30 14:06:33 +08002460 sdvo_connector->tv_format_property, i,
2461 i, sdvo_connector->tv_format_supported[i]);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002462
Zhenyu Wang14571b42010-03-30 14:06:33 +08002463 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0];
Zhao Yakuice6feab2009-08-24 13:50:26 +08002464 drm_connector_attach_property(
Zhenyu Wang14571b42010-03-30 14:06:33 +08002465 connector, sdvo_connector->tv_format_property, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002466
2467}
2468
Zhao Yakuib9219c52009-09-10 15:45:46 +08002469static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2470{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002471 struct drm_encoder *encoder = intel_attached_encoder(connector);
2472 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002473 struct intel_connector *intel_connector = to_intel_connector(connector);
2474 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
Zhao Yakuib9219c52009-09-10 15:45:46 +08002475 struct intel_sdvo_enhancements_reply sdvo_data;
2476 struct drm_device *dev = connector->dev;
2477 uint8_t status;
2478 uint16_t response, data_value[2];
2479
Eric Anholt21d40d32010-03-25 11:11:14 -07002480 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002481 NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002482 status = intel_sdvo_read_response(intel_encoder, &sdvo_data,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002483 sizeof(sdvo_data));
2484 if (status != SDVO_CMD_STATUS_SUCCESS) {
2485 DRM_DEBUG_KMS(" incorrect response is returned\n");
2486 return;
2487 }
2488 response = *((uint16_t *)&sdvo_data);
2489 if (!response) {
2490 DRM_DEBUG_KMS("No enhancement is supported\n");
2491 return;
2492 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08002493 if (IS_TV(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002494 /* when horizontal overscan is supported, Add the left/right
2495 * property
2496 */
2497 if (sdvo_data.overscan_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002498 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002499 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002500 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002501 &data_value, 4);
2502 if (status != SDVO_CMD_STATUS_SUCCESS) {
2503 DRM_DEBUG_KMS("Incorrect SDVO max "
2504 "h_overscan\n");
2505 return;
2506 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002507 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002508 SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002509 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002510 &response, 2);
2511 if (status != SDVO_CMD_STATUS_SUCCESS) {
2512 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2513 return;
2514 }
2515 sdvo_priv->max_hscan = data_value[0];
2516 sdvo_priv->left_margin = data_value[0] - response;
2517 sdvo_priv->right_margin = sdvo_priv->left_margin;
2518 sdvo_priv->left_property =
2519 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2520 "left_margin", 2);
2521 sdvo_priv->left_property->values[0] = 0;
2522 sdvo_priv->left_property->values[1] = data_value[0];
2523 drm_connector_attach_property(connector,
2524 sdvo_priv->left_property,
2525 sdvo_priv->left_margin);
2526 sdvo_priv->right_property =
2527 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2528 "right_margin", 2);
2529 sdvo_priv->right_property->values[0] = 0;
2530 sdvo_priv->right_property->values[1] = data_value[0];
2531 drm_connector_attach_property(connector,
2532 sdvo_priv->right_property,
2533 sdvo_priv->right_margin);
2534 DRM_DEBUG_KMS("h_overscan: max %d, "
2535 "default %d, current %d\n",
2536 data_value[0], data_value[1], response);
2537 }
2538 if (sdvo_data.overscan_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002539 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002540 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002541 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002542 &data_value, 4);
2543 if (status != SDVO_CMD_STATUS_SUCCESS) {
2544 DRM_DEBUG_KMS("Incorrect SDVO max "
2545 "v_overscan\n");
2546 return;
2547 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002548 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002549 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002550 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002551 &response, 2);
2552 if (status != SDVO_CMD_STATUS_SUCCESS) {
2553 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2554 return;
2555 }
2556 sdvo_priv->max_vscan = data_value[0];
2557 sdvo_priv->top_margin = data_value[0] - response;
2558 sdvo_priv->bottom_margin = sdvo_priv->top_margin;
2559 sdvo_priv->top_property =
2560 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2561 "top_margin", 2);
2562 sdvo_priv->top_property->values[0] = 0;
2563 sdvo_priv->top_property->values[1] = data_value[0];
2564 drm_connector_attach_property(connector,
2565 sdvo_priv->top_property,
2566 sdvo_priv->top_margin);
2567 sdvo_priv->bottom_property =
2568 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2569 "bottom_margin", 2);
2570 sdvo_priv->bottom_property->values[0] = 0;
2571 sdvo_priv->bottom_property->values[1] = data_value[0];
2572 drm_connector_attach_property(connector,
2573 sdvo_priv->bottom_property,
2574 sdvo_priv->bottom_margin);
2575 DRM_DEBUG_KMS("v_overscan: max %d, "
2576 "default %d, current %d\n",
2577 data_value[0], data_value[1], response);
2578 }
2579 if (sdvo_data.position_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002580 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002581 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002582 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002583 &data_value, 4);
2584 if (status != SDVO_CMD_STATUS_SUCCESS) {
2585 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2586 return;
2587 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002588 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002589 SDVO_CMD_GET_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002590 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002591 &response, 2);
2592 if (status != SDVO_CMD_STATUS_SUCCESS) {
2593 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2594 return;
2595 }
2596 sdvo_priv->max_hpos = data_value[0];
2597 sdvo_priv->cur_hpos = response;
2598 sdvo_priv->hpos_property =
2599 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2600 "hpos", 2);
2601 sdvo_priv->hpos_property->values[0] = 0;
2602 sdvo_priv->hpos_property->values[1] = data_value[0];
2603 drm_connector_attach_property(connector,
2604 sdvo_priv->hpos_property,
2605 sdvo_priv->cur_hpos);
2606 DRM_DEBUG_KMS("h_position: max %d, "
2607 "default %d, current %d\n",
2608 data_value[0], data_value[1], response);
2609 }
2610 if (sdvo_data.position_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002611 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002612 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002613 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002614 &data_value, 4);
2615 if (status != SDVO_CMD_STATUS_SUCCESS) {
2616 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2617 return;
2618 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002619 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002620 SDVO_CMD_GET_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002621 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002622 &response, 2);
2623 if (status != SDVO_CMD_STATUS_SUCCESS) {
2624 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2625 return;
2626 }
2627 sdvo_priv->max_vpos = data_value[0];
2628 sdvo_priv->cur_vpos = response;
2629 sdvo_priv->vpos_property =
2630 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2631 "vpos", 2);
2632 sdvo_priv->vpos_property->values[0] = 0;
2633 sdvo_priv->vpos_property->values[1] = data_value[0];
2634 drm_connector_attach_property(connector,
2635 sdvo_priv->vpos_property,
2636 sdvo_priv->cur_vpos);
2637 DRM_DEBUG_KMS("v_position: max %d, "
2638 "default %d, current %d\n",
2639 data_value[0], data_value[1], response);
2640 }
Zhao Yakuib9219c52009-09-10 15:45:46 +08002641 if (sdvo_data.saturation) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002642 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002643 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002644 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002645 &data_value, 4);
2646 if (status != SDVO_CMD_STATUS_SUCCESS) {
2647 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2648 return;
2649 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002650 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002651 SDVO_CMD_GET_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002652 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002653 &response, 2);
2654 if (status != SDVO_CMD_STATUS_SUCCESS) {
2655 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2656 return;
2657 }
2658 sdvo_priv->max_saturation = data_value[0];
2659 sdvo_priv->cur_saturation = response;
2660 sdvo_priv->saturation_property =
2661 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2662 "saturation", 2);
2663 sdvo_priv->saturation_property->values[0] = 0;
2664 sdvo_priv->saturation_property->values[1] =
2665 data_value[0];
2666 drm_connector_attach_property(connector,
2667 sdvo_priv->saturation_property,
2668 sdvo_priv->cur_saturation);
2669 DRM_DEBUG_KMS("saturation: max %d, "
2670 "default %d, current %d\n",
2671 data_value[0], data_value[1], response);
2672 }
2673 if (sdvo_data.contrast) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002674 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002675 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002676 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002677 &data_value, 4);
2678 if (status != SDVO_CMD_STATUS_SUCCESS) {
2679 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2680 return;
2681 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002682 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002683 SDVO_CMD_GET_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002684 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002685 &response, 2);
2686 if (status != SDVO_CMD_STATUS_SUCCESS) {
2687 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2688 return;
2689 }
2690 sdvo_priv->max_contrast = data_value[0];
2691 sdvo_priv->cur_contrast = response;
2692 sdvo_priv->contrast_property =
2693 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2694 "contrast", 2);
2695 sdvo_priv->contrast_property->values[0] = 0;
2696 sdvo_priv->contrast_property->values[1] = data_value[0];
2697 drm_connector_attach_property(connector,
2698 sdvo_priv->contrast_property,
2699 sdvo_priv->cur_contrast);
2700 DRM_DEBUG_KMS("contrast: max %d, "
2701 "default %d, current %d\n",
2702 data_value[0], data_value[1], response);
2703 }
2704 if (sdvo_data.hue) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002705 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002706 SDVO_CMD_GET_MAX_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002707 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002708 &data_value, 4);
2709 if (status != SDVO_CMD_STATUS_SUCCESS) {
2710 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2711 return;
2712 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002713 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002714 SDVO_CMD_GET_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002715 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002716 &response, 2);
2717 if (status != SDVO_CMD_STATUS_SUCCESS) {
2718 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2719 return;
2720 }
2721 sdvo_priv->max_hue = data_value[0];
2722 sdvo_priv->cur_hue = response;
2723 sdvo_priv->hue_property =
2724 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2725 "hue", 2);
2726 sdvo_priv->hue_property->values[0] = 0;
2727 sdvo_priv->hue_property->values[1] =
2728 data_value[0];
2729 drm_connector_attach_property(connector,
2730 sdvo_priv->hue_property,
2731 sdvo_priv->cur_hue);
2732 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2733 data_value[0], data_value[1], response);
2734 }
2735 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08002736 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002737 if (sdvo_data.brightness) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002738 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002739 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002740 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002741 &data_value, 4);
2742 if (status != SDVO_CMD_STATUS_SUCCESS) {
2743 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2744 return;
2745 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002746 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002747 SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002748 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002749 &response, 2);
2750 if (status != SDVO_CMD_STATUS_SUCCESS) {
2751 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2752 return;
2753 }
2754 sdvo_priv->max_brightness = data_value[0];
2755 sdvo_priv->cur_brightness = response;
2756 sdvo_priv->brightness_property =
2757 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2758 "brightness", 2);
2759 sdvo_priv->brightness_property->values[0] = 0;
2760 sdvo_priv->brightness_property->values[1] =
2761 data_value[0];
2762 drm_connector_attach_property(connector,
2763 sdvo_priv->brightness_property,
2764 sdvo_priv->cur_brightness);
2765 DRM_DEBUG_KMS("brightness: max %d, "
2766 "default %d, current %d\n",
2767 data_value[0], data_value[1], response);
2768 }
2769 }
2770 return;
2771}
2772
Eric Anholtc751ce42010-03-25 11:48:48 -07002773bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
Jesse Barnes79e53942008-11-07 14:24:08 -08002774{
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002775 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07002776 struct intel_encoder *intel_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -08002777 struct intel_sdvo_priv *sdvo_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08002778 u8 ch[0x40];
2779 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -08002780
Eric Anholt21d40d32010-03-25 11:11:14 -07002781 intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
2782 if (!intel_encoder) {
Eric Anholt7d573822009-01-02 13:33:00 -08002783 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002784 }
2785
Eric Anholt21d40d32010-03-25 11:11:14 -07002786 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1);
Eric Anholtc751ce42010-03-25 11:48:48 -07002787 sdvo_priv->sdvo_reg = sdvo_reg;
Keith Packard308cd3a2009-06-14 11:56:18 -07002788
Eric Anholt21d40d32010-03-25 11:11:14 -07002789 intel_encoder->dev_priv = sdvo_priv;
2790 intel_encoder->type = INTEL_OUTPUT_SDVO;
Jesse Barnes79e53942008-11-07 14:24:08 -08002791
Jesse Barnes79e53942008-11-07 14:24:08 -08002792 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002793 if (sdvo_reg == SDVOB)
Eric Anholt21d40d32010-03-25 11:11:14 -07002794 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
Keith Packard308cd3a2009-06-14 11:56:18 -07002795 else
Eric Anholt21d40d32010-03-25 11:11:14 -07002796 intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
Keith Packard308cd3a2009-06-14 11:56:18 -07002797
Eric Anholt21d40d32010-03-25 11:11:14 -07002798 if (!intel_encoder->i2c_bus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002799 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08002800
Eric Anholtc751ce42010-03-25 11:48:48 -07002801 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08002802
Keith Packard308cd3a2009-06-14 11:56:18 -07002803 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
Eric Anholt21d40d32010-03-25 11:11:14 -07002804 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
Jesse Barnes79e53942008-11-07 14:24:08 -08002805
Jesse Barnes79e53942008-11-07 14:24:08 -08002806 /* Read the regs to test if we can talk to the device */
2807 for (i = 0; i < 0x40; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002808 if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002809 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002810 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002811 goto err_i2c;
2812 }
2813 }
2814
Ma Ling619ac3b2009-05-18 16:12:46 +08002815 /* setup the DDC bus. */
Eric Anholtc751ce42010-03-25 11:48:48 -07002816 if (sdvo_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002817 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002818 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2819 "SDVOB/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002820 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002821 } else {
Eric Anholt21d40d32010-03-25 11:11:14 -07002822 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
Keith Packard57cdaf92009-09-04 13:07:54 +08002823 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
2824 "SDVOC/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002825 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002826 }
Ma Ling619ac3b2009-05-18 16:12:46 +08002827
Eric Anholt21d40d32010-03-25 11:11:14 -07002828 if (intel_encoder->ddc_bus == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002829 goto err_i2c;
2830
Keith Packard308cd3a2009-06-14 11:56:18 -07002831 /* Wrap with our custom algo which switches to DDC mode */
Eric Anholt21d40d32010-03-25 11:11:14 -07002832 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002833
Zhenyu Wang14571b42010-03-30 14:06:33 +08002834 /* encoder type will be decided later */
2835 drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0);
2836 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2837
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002838 /* In default case sdvo lvds is false */
Eric Anholt21d40d32010-03-25 11:11:14 -07002839 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps);
Jesse Barnes79e53942008-11-07 14:24:08 -08002840
Zhenyu Wang14571b42010-03-30 14:06:33 +08002841 if (intel_sdvo_output_setup(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002842 sdvo_priv->caps.output_flags) != true) {
Dave Airlie51c8b402009-08-20 13:38:04 +10002843 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
Eric Anholtc751ce42010-03-25 11:48:48 -07002844 sdvo_reg == SDVOB ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002845 goto err_i2c;
2846 }
2847
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002848 intel_sdvo_select_ddc_bus(sdvo_priv);
2849
Jesse Barnes79e53942008-11-07 14:24:08 -08002850 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholt21d40d32010-03-25 11:11:14 -07002851 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08002852
Eric Anholt21d40d32010-03-25 11:11:14 -07002853 intel_sdvo_get_input_pixel_clock_range(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002854 &sdvo_priv->pixel_clock_min,
2855 &sdvo_priv->pixel_clock_max);
2856
2857
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002858 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
yakui_zhao342dc382009-06-02 14:12:00 +08002859 "clock range %dMHz - %dMHz, "
2860 "input 1: %c, input 2: %c, "
2861 "output 1: %c, output 2: %c\n",
2862 SDVO_NAME(sdvo_priv),
2863 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
2864 sdvo_priv->caps.device_rev_id,
2865 sdvo_priv->pixel_clock_min / 1000,
2866 sdvo_priv->pixel_clock_max / 1000,
2867 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2868 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
2869 /* check currently supported outputs */
2870 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002871 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
yakui_zhao342dc382009-06-02 14:12:00 +08002872 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002873 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2874
Eric Anholt7d573822009-01-02 13:33:00 -08002875 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08002876
2877err_i2c:
Keith Packard57cdaf92009-09-04 13:07:54 +08002878 if (sdvo_priv->analog_ddc_bus != NULL)
2879 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
Eric Anholt21d40d32010-03-25 11:11:14 -07002880 if (intel_encoder->ddc_bus != NULL)
2881 intel_i2c_destroy(intel_encoder->ddc_bus);
2882 if (intel_encoder->i2c_bus != NULL)
2883 intel_i2c_destroy(intel_encoder->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002884err_inteloutput:
Eric Anholt21d40d32010-03-25 11:11:14 -07002885 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002886
Eric Anholt7d573822009-01-02 13:33:00 -08002887 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002888}