aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_sdvo.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/i915/intel_sdvo.c')
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c2148
1 files changed, 966 insertions, 1182 deletions
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index d9d4d51aa89e..e3b7a7ee39cb 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -31,8 +31,8 @@
31#include "drmP.h" 31#include "drmP.h"
32#include "drm.h" 32#include "drm.h"
33#include "drm_crtc.h" 33#include "drm_crtc.h"
34#include "intel_drv.h"
35#include "drm_edid.h" 34#include "drm_edid.h"
35#include "intel_drv.h"
36#include "i915_drm.h" 36#include "i915_drm.h"
37#include "i915_drv.h" 37#include "i915_drv.h"
38#include "intel_sdvo_regs.h" 38#include "intel_sdvo_regs.h"
@@ -47,9 +47,10 @@
47 47
48#define IS_TV(c) (c->output_flag & SDVO_TV_MASK) 48#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
49#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK) 49#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
50#define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
50 51
51 52
52static char *tv_format_names[] = { 53static const char *tv_format_names[] = {
53 "NTSC_M" , "NTSC_J" , "NTSC_443", 54 "NTSC_M" , "NTSC_J" , "NTSC_443",
54 "PAL_B" , "PAL_D" , "PAL_G" , 55 "PAL_B" , "PAL_D" , "PAL_G" ,
55 "PAL_H" , "PAL_I" , "PAL_M" , 56 "PAL_H" , "PAL_I" , "PAL_M" ,
@@ -61,7 +62,9 @@ static char *tv_format_names[] = {
61 62
62#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names)) 63#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
63 64
64struct intel_sdvo_priv { 65struct intel_sdvo {
66 struct intel_encoder base;
67
65 u8 slave_addr; 68 u8 slave_addr;
66 69
67 /* Register for the SDVO device: SDVOB or SDVOC */ 70 /* Register for the SDVO device: SDVOB or SDVOC */
@@ -95,7 +98,7 @@ struct intel_sdvo_priv {
95 bool is_tv; 98 bool is_tv;
96 99
97 /* This is for current tv format name */ 100 /* This is for current tv format name */
98 char *tv_format_name; 101 int tv_format_index;
99 102
100 /** 103 /**
101 * This is set if we treat the device as HDMI, instead of DVI. 104 * This is set if we treat the device as HDMI, instead of DVI.
@@ -132,37 +135,40 @@ struct intel_sdvo_priv {
132}; 135};
133 136
134struct intel_sdvo_connector { 137struct intel_sdvo_connector {
138 struct intel_connector base;
139
135 /* Mark the type of connector */ 140 /* Mark the type of connector */
136 uint16_t output_flag; 141 uint16_t output_flag;
137 142
138 /* This contains all current supported TV format */ 143 /* This contains all current supported TV format */
139 char *tv_format_supported[TV_FORMAT_NUM]; 144 u8 tv_format_supported[TV_FORMAT_NUM];
140 int format_supported_num; 145 int format_supported_num;
141 struct drm_property *tv_format_property; 146 struct drm_property *tv_format;
142 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
143
144 /**
145 * Returned SDTV resolutions allowed for the current format, if the
146 * device reported it.
147 */
148 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
149 147
150 /* add the property for the SDVO-TV */ 148 /* add the property for the SDVO-TV */
151 struct drm_property *left_property; 149 struct drm_property *left;
152 struct drm_property *right_property; 150 struct drm_property *right;
153 struct drm_property *top_property; 151 struct drm_property *top;
154 struct drm_property *bottom_property; 152 struct drm_property *bottom;
155 struct drm_property *hpos_property; 153 struct drm_property *hpos;
156 struct drm_property *vpos_property; 154 struct drm_property *vpos;
155 struct drm_property *contrast;
156 struct drm_property *saturation;
157 struct drm_property *hue;
158 struct drm_property *sharpness;
159 struct drm_property *flicker_filter;
160 struct drm_property *flicker_filter_adaptive;
161 struct drm_property *flicker_filter_2d;
162 struct drm_property *tv_chroma_filter;
163 struct drm_property *tv_luma_filter;
164 struct drm_property *dot_crawl;
157 165
158 /* add the property for the SDVO-TV/LVDS */ 166 /* add the property for the SDVO-TV/LVDS */
159 struct drm_property *brightness_property; 167 struct drm_property *brightness;
160 struct drm_property *contrast_property;
161 struct drm_property *saturation_property;
162 struct drm_property *hue_property;
163 168
164 /* Add variable to record current setting for the above property */ 169 /* Add variable to record current setting for the above property */
165 u32 left_margin, right_margin, top_margin, bottom_margin; 170 u32 left_margin, right_margin, top_margin, bottom_margin;
171
166 /* this is to get the range of margin.*/ 172 /* this is to get the range of margin.*/
167 u32 max_hscan, max_vscan; 173 u32 max_hscan, max_vscan;
168 u32 max_hpos, cur_hpos; 174 u32 max_hpos, cur_hpos;
@@ -171,36 +177,54 @@ struct intel_sdvo_connector {
171 u32 cur_contrast, max_contrast; 177 u32 cur_contrast, max_contrast;
172 u32 cur_saturation, max_saturation; 178 u32 cur_saturation, max_saturation;
173 u32 cur_hue, max_hue; 179 u32 cur_hue, max_hue;
180 u32 cur_sharpness, max_sharpness;
181 u32 cur_flicker_filter, max_flicker_filter;
182 u32 cur_flicker_filter_adaptive, max_flicker_filter_adaptive;
183 u32 cur_flicker_filter_2d, max_flicker_filter_2d;
184 u32 cur_tv_chroma_filter, max_tv_chroma_filter;
185 u32 cur_tv_luma_filter, max_tv_luma_filter;
186 u32 cur_dot_crawl, max_dot_crawl;
174}; 187};
175 188
189static struct intel_sdvo *enc_to_intel_sdvo(struct drm_encoder *encoder)
190{
191 return container_of(enc_to_intel_encoder(encoder), struct intel_sdvo, base);
192}
193
194static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector)
195{
196 return container_of(to_intel_connector(connector), struct intel_sdvo_connector, base);
197}
198
176static bool 199static bool
177intel_sdvo_output_setup(struct intel_encoder *intel_encoder, 200intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags);
178 uint16_t flags); 201static bool
179static void 202intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
180intel_sdvo_tv_create_property(struct drm_connector *connector, int type); 203 struct intel_sdvo_connector *intel_sdvo_connector,
181static void 204 int type);
182intel_sdvo_create_enhance_property(struct drm_connector *connector); 205static bool
206intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
207 struct intel_sdvo_connector *intel_sdvo_connector);
183 208
184/** 209/**
185 * Writes the SDVOB or SDVOC with the given value, but always writes both 210 * Writes the SDVOB or SDVOC with the given value, but always writes both
186 * SDVOB and SDVOC to work around apparent hardware issues (according to 211 * SDVOB and SDVOC to work around apparent hardware issues (according to
187 * comments in the BIOS). 212 * comments in the BIOS).
188 */ 213 */
189static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val) 214static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
190{ 215{
191 struct drm_device *dev = intel_encoder->enc.dev; 216 struct drm_device *dev = intel_sdvo->base.enc.dev;
192 struct drm_i915_private *dev_priv = dev->dev_private; 217 struct drm_i915_private *dev_priv = dev->dev_private;
193 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
194 u32 bval = val, cval = val; 218 u32 bval = val, cval = val;
195 int i; 219 int i;
196 220
197 if (sdvo_priv->sdvo_reg == PCH_SDVOB) { 221 if (intel_sdvo->sdvo_reg == PCH_SDVOB) {
198 I915_WRITE(sdvo_priv->sdvo_reg, val); 222 I915_WRITE(intel_sdvo->sdvo_reg, val);
199 I915_READ(sdvo_priv->sdvo_reg); 223 I915_READ(intel_sdvo->sdvo_reg);
200 return; 224 return;
201 } 225 }
202 226
203 if (sdvo_priv->sdvo_reg == SDVOB) { 227 if (intel_sdvo->sdvo_reg == SDVOB) {
204 cval = I915_READ(SDVOC); 228 cval = I915_READ(SDVOC);
205 } else { 229 } else {
206 bval = I915_READ(SDVOB); 230 bval = I915_READ(SDVOB);
@@ -219,33 +243,27 @@ static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val)
219 } 243 }
220} 244}
221 245
222static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr, 246static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
223 u8 *ch)
224{ 247{
225 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 248 u8 out_buf[2] = { addr, 0 };
226 u8 out_buf[2];
227 u8 buf[2]; 249 u8 buf[2];
228 int ret;
229
230 struct i2c_msg msgs[] = { 250 struct i2c_msg msgs[] = {
231 { 251 {
232 .addr = sdvo_priv->slave_addr >> 1, 252 .addr = intel_sdvo->slave_addr >> 1,
233 .flags = 0, 253 .flags = 0,
234 .len = 1, 254 .len = 1,
235 .buf = out_buf, 255 .buf = out_buf,
236 }, 256 },
237 { 257 {
238 .addr = sdvo_priv->slave_addr >> 1, 258 .addr = intel_sdvo->slave_addr >> 1,
239 .flags = I2C_M_RD, 259 .flags = I2C_M_RD,
240 .len = 1, 260 .len = 1,
241 .buf = buf, 261 .buf = buf,
242 } 262 }
243 }; 263 };
264 int ret;
244 265
245 out_buf[0] = addr; 266 if ((ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 2)) == 2)
246 out_buf[1] = 0;
247
248 if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2)
249 { 267 {
250 *ch = buf[0]; 268 *ch = buf[0];
251 return true; 269 return true;
@@ -255,35 +273,26 @@ static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr,
255 return false; 273 return false;
256} 274}
257 275
258static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr, 276static bool intel_sdvo_write_byte(struct intel_sdvo *intel_sdvo, int addr, u8 ch)
259 u8 ch)
260{ 277{
261 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 278 u8 out_buf[2] = { addr, ch };
262 u8 out_buf[2];
263 struct i2c_msg msgs[] = { 279 struct i2c_msg msgs[] = {
264 { 280 {
265 .addr = sdvo_priv->slave_addr >> 1, 281 .addr = intel_sdvo->slave_addr >> 1,
266 .flags = 0, 282 .flags = 0,
267 .len = 2, 283 .len = 2,
268 .buf = out_buf, 284 .buf = out_buf,
269 } 285 }
270 }; 286 };
271 287
272 out_buf[0] = addr; 288 return i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 1) == 1;
273 out_buf[1] = ch;
274
275 if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1)
276 {
277 return true;
278 }
279 return false;
280} 289}
281 290
282#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} 291#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
283/** Mapping of command numbers to names, for debug output */ 292/** Mapping of command numbers to names, for debug output */
284static const struct _sdvo_cmd_name { 293static const struct _sdvo_cmd_name {
285 u8 cmd; 294 u8 cmd;
286 char *name; 295 const char *name;
287} sdvo_cmd_names[] = { 296} sdvo_cmd_names[] = {
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET), 297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS), 298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
@@ -328,13 +337,14 @@ static const struct _sdvo_cmd_name {
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT), 337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT), 338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS), 339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
340
331 /* Add the op code for SDVO enhancements */ 341 /* Add the op code for SDVO enhancements */
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H), 342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H), 343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H), 344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V), 345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V), 346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V), 347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION), 348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION), 349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION), 350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
@@ -353,6 +363,27 @@ static const struct _sdvo_cmd_name {
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V), 363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V), 364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
355 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V), 365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
366 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER),
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER),
368 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER),
369 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE),
370 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE),
371 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE),
372 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D),
373 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D),
374 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D),
375 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS),
376 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS),
377 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS),
378 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL),
379 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL),
380 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER),
381 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER),
382 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER),
383 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER),
384 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER),
385 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER),
386
356 /* HDMI op code */ 387 /* HDMI op code */
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE), 388 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE), 389 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
@@ -377,17 +408,15 @@ static const struct _sdvo_cmd_name {
377}; 408};
378 409
379#define IS_SDVOB(reg) (reg == SDVOB || reg == PCH_SDVOB) 410#define IS_SDVOB(reg) (reg == SDVOB || reg == PCH_SDVOB)
380#define SDVO_NAME(dev_priv) (IS_SDVOB((dev_priv)->sdvo_reg) ? "SDVOB" : "SDVOC") 411#define SDVO_NAME(svdo) (IS_SDVOB((svdo)->sdvo_reg) ? "SDVOB" : "SDVOC")
381#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv)
382 412
383static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd, 413static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
384 void *args, int args_len) 414 const void *args, int args_len)
385{ 415{
386 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
387 int i; 416 int i;
388 417
389 DRM_DEBUG_KMS("%s: W: %02X ", 418 DRM_DEBUG_KMS("%s: W: %02X ",
390 SDVO_NAME(sdvo_priv), cmd); 419 SDVO_NAME(intel_sdvo), cmd);
391 for (i = 0; i < args_len; i++) 420 for (i = 0; i < args_len; i++)
392 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]); 421 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
393 for (; i < 8; i++) 422 for (; i < 8; i++)
@@ -403,19 +432,20 @@ static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd,
403 DRM_LOG_KMS("\n"); 432 DRM_LOG_KMS("\n");
404} 433}
405 434
406static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd, 435static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
407 void *args, int args_len) 436 const void *args, int args_len)
408{ 437{
409 int i; 438 int i;
410 439
411 intel_sdvo_debug_write(intel_encoder, cmd, args, args_len); 440 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
412 441
413 for (i = 0; i < args_len; i++) { 442 for (i = 0; i < args_len; i++) {
414 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i, 443 if (!intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_ARG_0 - i,
415 ((u8*)args)[i]); 444 ((u8*)args)[i]))
445 return false;
416 } 446 }
417 447
418 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd); 448 return intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_OPCODE, cmd);
419} 449}
420 450
421static const char *cmd_status_names[] = { 451static const char *cmd_status_names[] = {
@@ -428,14 +458,13 @@ static const char *cmd_status_names[] = {
428 "Scaling not supported" 458 "Scaling not supported"
429}; 459};
430 460
431static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder, 461static void intel_sdvo_debug_response(struct intel_sdvo *intel_sdvo,
432 void *response, int response_len, 462 void *response, int response_len,
433 u8 status) 463 u8 status)
434{ 464{
435 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
436 int i; 465 int i;
437 466
438 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv)); 467 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo));
439 for (i = 0; i < response_len; i++) 468 for (i = 0; i < response_len; i++)
440 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]); 469 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
441 for (; i < 8; i++) 470 for (; i < 8; i++)
@@ -447,8 +476,8 @@ static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder,
447 DRM_LOG_KMS("\n"); 476 DRM_LOG_KMS("\n");
448} 477}
449 478
450static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder, 479static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
451 void *response, int response_len) 480 void *response, int response_len)
452{ 481{
453 int i; 482 int i;
454 u8 status; 483 u8 status;
@@ -457,24 +486,26 @@ static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder,
457 while (retry--) { 486 while (retry--) {
458 /* Read the command response */ 487 /* Read the command response */
459 for (i = 0; i < response_len; i++) { 488 for (i = 0; i < response_len; i++) {
460 intel_sdvo_read_byte(intel_encoder, 489 if (!intel_sdvo_read_byte(intel_sdvo,
461 SDVO_I2C_RETURN_0 + i, 490 SDVO_I2C_RETURN_0 + i,
462 &((u8 *)response)[i]); 491 &((u8 *)response)[i]))
492 return false;
463 } 493 }
464 494
465 /* read the return status */ 495 /* read the return status */
466 intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS, 496 if (!intel_sdvo_read_byte(intel_sdvo, SDVO_I2C_CMD_STATUS,
467 &status); 497 &status))
498 return false;
468 499
469 intel_sdvo_debug_response(intel_encoder, response, response_len, 500 intel_sdvo_debug_response(intel_sdvo, response, response_len,
470 status); 501 status);
471 if (status != SDVO_CMD_STATUS_PENDING) 502 if (status != SDVO_CMD_STATUS_PENDING)
472 return status; 503 break;
473 504
474 mdelay(50); 505 mdelay(50);
475 } 506 }
476 507
477 return status; 508 return status == SDVO_CMD_STATUS_SUCCESS;
478} 509}
479 510
480static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) 511static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
@@ -494,37 +525,36 @@ static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
494 * another I2C transaction after issuing the DDC bus switch, it will be 525 * another I2C transaction after issuing the DDC bus switch, it will be
495 * switched to the internal SDVO register. 526 * switched to the internal SDVO register.
496 */ 527 */
497static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder, 528static void intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
498 u8 target) 529 u8 target)
499{ 530{
500 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
501 u8 out_buf[2], cmd_buf[2], ret_value[2], ret; 531 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
502 struct i2c_msg msgs[] = { 532 struct i2c_msg msgs[] = {
503 { 533 {
504 .addr = sdvo_priv->slave_addr >> 1, 534 .addr = intel_sdvo->slave_addr >> 1,
505 .flags = 0, 535 .flags = 0,
506 .len = 2, 536 .len = 2,
507 .buf = out_buf, 537 .buf = out_buf,
508 }, 538 },
509 /* the following two are to read the response */ 539 /* the following two are to read the response */
510 { 540 {
511 .addr = sdvo_priv->slave_addr >> 1, 541 .addr = intel_sdvo->slave_addr >> 1,
512 .flags = 0, 542 .flags = 0,
513 .len = 1, 543 .len = 1,
514 .buf = cmd_buf, 544 .buf = cmd_buf,
515 }, 545 },
516 { 546 {
517 .addr = sdvo_priv->slave_addr >> 1, 547 .addr = intel_sdvo->slave_addr >> 1,
518 .flags = I2C_M_RD, 548 .flags = I2C_M_RD,
519 .len = 1, 549 .len = 1,
520 .buf = ret_value, 550 .buf = ret_value,
521 }, 551 },
522 }; 552 };
523 553
524 intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH, 554 intel_sdvo_debug_write(intel_sdvo, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
525 &target, 1); 555 &target, 1);
526 /* write the DDC switch command argument */ 556 /* write the DDC switch command argument */
527 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target); 557 intel_sdvo_write_byte(intel_sdvo, SDVO_I2C_ARG_0, target);
528 558
529 out_buf[0] = SDVO_I2C_OPCODE; 559 out_buf[0] = SDVO_I2C_OPCODE;
530 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH; 560 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
@@ -533,7 +563,7 @@ static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encode
533 ret_value[0] = 0; 563 ret_value[0] = 0;
534 ret_value[1] = 0; 564 ret_value[1] = 0;
535 565
536 ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3); 566 ret = i2c_transfer(intel_sdvo->base.i2c_bus, msgs, 3);
537 if (ret != 3) { 567 if (ret != 3) {
538 /* failure in I2C transfer */ 568 /* failure in I2C transfer */
539 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); 569 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
@@ -547,23 +577,29 @@ static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encode
547 return; 577 return;
548} 578}
549 579
550static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1) 580static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
551{ 581{
552 struct intel_sdvo_set_target_input_args targets = {0}; 582 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
553 u8 status; 583 return false;
554
555 if (target_0 && target_1)
556 return SDVO_CMD_STATUS_NOTSUPP;
557 584
558 if (target_1) 585 return intel_sdvo_read_response(intel_sdvo, NULL, 0);
559 targets.target_1 = 1; 586}
560 587
561 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets, 588static bool
562 sizeof(targets)); 589intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
590{
591 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
592 return false;
563 593
564 status = intel_sdvo_read_response(intel_encoder, NULL, 0); 594 return intel_sdvo_read_response(intel_sdvo, value, len);
595}
565 596
566 return (status == SDVO_CMD_STATUS_SUCCESS); 597static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
598{
599 struct intel_sdvo_set_target_input_args targets = {0};
600 return intel_sdvo_set_value(intel_sdvo,
601 SDVO_CMD_SET_TARGET_INPUT,
602 &targets, sizeof(targets));
567} 603}
568 604
569/** 605/**
@@ -572,14 +608,12 @@ static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, boo
572 * This function is making an assumption about the layout of the response, 608 * This function is making an assumption about the layout of the response,
573 * which should be checked against the docs. 609 * which should be checked against the docs.
574 */ 610 */
575static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2) 611static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
576{ 612{
577 struct intel_sdvo_get_trained_inputs_response response; 613 struct intel_sdvo_get_trained_inputs_response response;
578 u8 status;
579 614
580 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0); 615 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
581 status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response)); 616 &response, sizeof(response)))
582 if (status != SDVO_CMD_STATUS_SUCCESS)
583 return false; 617 return false;
584 618
585 *input_1 = response.input0_trained; 619 *input_1 = response.input0_trained;
@@ -587,21 +621,18 @@ static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, b
587 return true; 621 return true;
588} 622}
589 623
590static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder, 624static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
591 u16 outputs) 625 u16 outputs)
592{ 626{
593 u8 status; 627 return intel_sdvo_set_value(intel_sdvo,
594 628 SDVO_CMD_SET_ACTIVE_OUTPUTS,
595 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs, 629 &outputs, sizeof(outputs));
596 sizeof(outputs));
597 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
598 return (status == SDVO_CMD_STATUS_SUCCESS);
599} 630}
600 631
601static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder, 632static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
602 int mode) 633 int mode)
603{ 634{
604 u8 status, state = SDVO_ENCODER_STATE_ON; 635 u8 state = SDVO_ENCODER_STATE_ON;
605 636
606 switch (mode) { 637 switch (mode) {
607 case DRM_MODE_DPMS_ON: 638 case DRM_MODE_DPMS_ON:
@@ -618,88 +649,63 @@ static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encod
618 break; 649 break;
619 } 650 }
620 651
621 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state, 652 return intel_sdvo_set_value(intel_sdvo,
622 sizeof(state)); 653 SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
623 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
624
625 return (status == SDVO_CMD_STATUS_SUCCESS);
626} 654}
627 655
628static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder, 656static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
629 int *clock_min, 657 int *clock_min,
630 int *clock_max) 658 int *clock_max)
631{ 659{
632 struct intel_sdvo_pixel_clock_range clocks; 660 struct intel_sdvo_pixel_clock_range clocks;
633 u8 status;
634
635 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
636 NULL, 0);
637
638 status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks));
639 661
640 if (status != SDVO_CMD_STATUS_SUCCESS) 662 if (!intel_sdvo_get_value(intel_sdvo,
663 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
664 &clocks, sizeof(clocks)))
641 return false; 665 return false;
642 666
643 /* Convert the values from units of 10 kHz to kHz. */ 667 /* Convert the values from units of 10 kHz to kHz. */
644 *clock_min = clocks.min * 10; 668 *clock_min = clocks.min * 10;
645 *clock_max = clocks.max * 10; 669 *clock_max = clocks.max * 10;
646
647 return true; 670 return true;
648} 671}
649 672
650static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder, 673static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
651 u16 outputs) 674 u16 outputs)
652{ 675{
653 u8 status; 676 return intel_sdvo_set_value(intel_sdvo,
654 677 SDVO_CMD_SET_TARGET_OUTPUT,
655 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs, 678 &outputs, sizeof(outputs));
656 sizeof(outputs));
657
658 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
659 return (status == SDVO_CMD_STATUS_SUCCESS);
660} 679}
661 680
662static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd, 681static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
663 struct intel_sdvo_dtd *dtd) 682 struct intel_sdvo_dtd *dtd)
664{ 683{
665 u8 status; 684 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
666 685 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
667 intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1));
668 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
669 if (status != SDVO_CMD_STATUS_SUCCESS)
670 return false;
671
672 intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2));
673 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
674 if (status != SDVO_CMD_STATUS_SUCCESS)
675 return false;
676
677 return true;
678} 686}
679 687
680static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder, 688static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
681 struct intel_sdvo_dtd *dtd) 689 struct intel_sdvo_dtd *dtd)
682{ 690{
683 return intel_sdvo_set_timing(intel_encoder, 691 return intel_sdvo_set_timing(intel_sdvo,
684 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd); 692 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
685} 693}
686 694
687static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder, 695static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
688 struct intel_sdvo_dtd *dtd) 696 struct intel_sdvo_dtd *dtd)
689{ 697{
690 return intel_sdvo_set_timing(intel_encoder, 698 return intel_sdvo_set_timing(intel_sdvo,
691 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd); 699 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
692} 700}
693 701
694static bool 702static bool
695intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder, 703intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
696 uint16_t clock, 704 uint16_t clock,
697 uint16_t width, 705 uint16_t width,
698 uint16_t height) 706 uint16_t height)
699{ 707{
700 struct intel_sdvo_preferred_input_timing_args args; 708 struct intel_sdvo_preferred_input_timing_args args;
701 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
702 uint8_t status;
703 709
704 memset(&args, 0, sizeof(args)); 710 memset(&args, 0, sizeof(args));
705 args.clock = clock; 711 args.clock = clock;
@@ -707,59 +713,32 @@ intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder,
707 args.height = height; 713 args.height = height;
708 args.interlace = 0; 714 args.interlace = 0;
709 715
710 if (sdvo_priv->is_lvds && 716 if (intel_sdvo->is_lvds &&
711 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width || 717 (intel_sdvo->sdvo_lvds_fixed_mode->hdisplay != width ||
712 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height)) 718 intel_sdvo->sdvo_lvds_fixed_mode->vdisplay != height))
713 args.scaled = 1; 719 args.scaled = 1;
714 720
715 intel_sdvo_write_cmd(intel_encoder, 721 return intel_sdvo_set_value(intel_sdvo,
716 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, 722 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
717 &args, sizeof(args)); 723 &args, sizeof(args));
718 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
719 if (status != SDVO_CMD_STATUS_SUCCESS)
720 return false;
721
722 return true;
723} 724}
724 725
725static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder, 726static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
726 struct intel_sdvo_dtd *dtd) 727 struct intel_sdvo_dtd *dtd)
727{ 728{
728 bool status; 729 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
729 730 &dtd->part1, sizeof(dtd->part1)) &&
730 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, 731 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
731 NULL, 0); 732 &dtd->part2, sizeof(dtd->part2));
732
733 status = intel_sdvo_read_response(intel_encoder, &dtd->part1,
734 sizeof(dtd->part1));
735 if (status != SDVO_CMD_STATUS_SUCCESS)
736 return false;
737
738 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
739 NULL, 0);
740
741 status = intel_sdvo_read_response(intel_encoder, &dtd->part2,
742 sizeof(dtd->part2));
743 if (status != SDVO_CMD_STATUS_SUCCESS)
744 return false;
745
746 return false;
747} 733}
748 734
749static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val) 735static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
750{ 736{
751 u8 status; 737 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
752
753 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
754 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
755 if (status != SDVO_CMD_STATUS_SUCCESS)
756 return false;
757
758 return true;
759} 738}
760 739
761static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd, 740static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
762 struct drm_display_mode *mode) 741 const struct drm_display_mode *mode)
763{ 742{
764 uint16_t width, height; 743 uint16_t width, height;
765 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len; 744 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
@@ -808,7 +787,7 @@ static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
808} 787}
809 788
810static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode, 789static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
811 struct intel_sdvo_dtd *dtd) 790 const struct intel_sdvo_dtd *dtd)
812{ 791{
813 mode->hdisplay = dtd->part1.h_active; 792 mode->hdisplay = dtd->part1.h_active;
814 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8; 793 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
@@ -840,45 +819,33 @@ static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
840 mode->flags |= DRM_MODE_FLAG_PVSYNC; 819 mode->flags |= DRM_MODE_FLAG_PVSYNC;
841} 820}
842 821
843static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder, 822static bool intel_sdvo_get_supp_encode(struct intel_sdvo *intel_sdvo,
844 struct intel_sdvo_encode *encode) 823 struct intel_sdvo_encode *encode)
845{ 824{
846 uint8_t status; 825 if (intel_sdvo_get_value(intel_sdvo,
847 826 SDVO_CMD_GET_SUPP_ENCODE,
848 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0); 827 encode, sizeof(*encode)))
849 status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode)); 828 return true;
850 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
851 memset(encode, 0, sizeof(*encode));
852 return false;
853 }
854 829
855 return true; 830 /* non-support means DVI */
831 memset(encode, 0, sizeof(*encode));
832 return false;
856} 833}
857 834
858static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder, 835static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
859 uint8_t mode) 836 uint8_t mode)
860{ 837{
861 uint8_t status; 838 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
862
863 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1);
864 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
865
866 return (status == SDVO_CMD_STATUS_SUCCESS);
867} 839}
868 840
869static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder, 841static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
870 uint8_t mode) 842 uint8_t mode)
871{ 843{
872 uint8_t status; 844 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
873
874 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
875 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
876
877 return (status == SDVO_CMD_STATUS_SUCCESS);
878} 845}
879 846
880#if 0 847#if 0
881static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder) 848static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
882{ 849{
883 int i, j; 850 int i, j;
884 uint8_t set_buf_index[2]; 851 uint8_t set_buf_index[2];
@@ -887,8 +854,7 @@ static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
887 uint8_t buf[48]; 854 uint8_t buf[48];
888 uint8_t *pos; 855 uint8_t *pos;
889 856
890 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0); 857 intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
891 intel_sdvo_read_response(encoder, &av_split, 1);
892 858
893 for (i = 0; i <= av_split; i++) { 859 for (i = 0; i <= av_split; i++) {
894 set_buf_index[0] = i; set_buf_index[1] = 0; 860 set_buf_index[0] = i; set_buf_index[1] = 0;
@@ -908,7 +874,7 @@ static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
908} 874}
909#endif 875#endif
910 876
911static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder, 877static bool intel_sdvo_set_hdmi_buf(struct intel_sdvo *intel_sdvo,
912 int index, 878 int index,
913 uint8_t *data, int8_t size, uint8_t tx_rate) 879 uint8_t *data, int8_t size, uint8_t tx_rate)
914{ 880{
@@ -917,15 +883,18 @@ static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder,
917 set_buf_index[0] = index; 883 set_buf_index[0] = index;
918 set_buf_index[1] = 0; 884 set_buf_index[1] = 0;
919 885
920 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX, 886 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_INDEX,
921 set_buf_index, 2); 887 set_buf_index, 2))
888 return false;
922 889
923 for (; size > 0; size -= 8) { 890 for (; size > 0; size -= 8) {
924 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8); 891 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_DATA, data, 8))
892 return false;
893
925 data += 8; 894 data += 8;
926 } 895 }
927 896
928 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1); 897 return intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
929} 898}
930 899
931static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size) 900static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
@@ -1000,7 +969,7 @@ struct dip_infoframe {
1000 } __attribute__ ((packed)) u; 969 } __attribute__ ((packed)) u;
1001} __attribute__((packed)); 970} __attribute__((packed));
1002 971
1003static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder, 972static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1004 struct drm_display_mode * mode) 973 struct drm_display_mode * mode)
1005{ 974{
1006 struct dip_infoframe avi_if = { 975 struct dip_infoframe avi_if = {
@@ -1011,133 +980,107 @@ static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder,
1011 980
1012 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if, 981 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
1013 4 + avi_if.len); 982 4 + avi_if.len);
1014 intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if, 983 return intel_sdvo_set_hdmi_buf(intel_sdvo, 1, (uint8_t *)&avi_if,
1015 4 + avi_if.len, 984 4 + avi_if.len,
1016 SDVO_HBUF_TX_VSYNC); 985 SDVO_HBUF_TX_VSYNC);
1017} 986}
1018 987
1019static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder) 988static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo)
1020{ 989{
1021
1022 struct intel_sdvo_tv_format format; 990 struct intel_sdvo_tv_format format;
1023 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 991 uint32_t format_map;
1024 uint32_t format_map, i;
1025 uint8_t status;
1026
1027 for (i = 0; i < TV_FORMAT_NUM; i++)
1028 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1029 break;
1030 992
1031 format_map = 1 << i; 993 format_map = 1 << intel_sdvo->tv_format_index;
1032 memset(&format, 0, sizeof(format)); 994 memset(&format, 0, sizeof(format));
1033 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ? 995 memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1034 sizeof(format) : sizeof(format_map));
1035 996
1036 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format, 997 BUILD_BUG_ON(sizeof(format) != 6);
1037 sizeof(format)); 998 return intel_sdvo_set_value(intel_sdvo,
1038 999 SDVO_CMD_SET_TV_FORMAT,
1039 status = intel_sdvo_read_response(intel_encoder, NULL, 0); 1000 &format, sizeof(format));
1040 if (status != SDVO_CMD_STATUS_SUCCESS)
1041 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
1042 SDVO_NAME(sdvo_priv));
1043} 1001}
1044 1002
1045static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, 1003static bool
1046 struct drm_display_mode *mode, 1004intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1047 struct drm_display_mode *adjusted_mode) 1005 struct drm_display_mode *mode)
1048{ 1006{
1049 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1007 struct intel_sdvo_dtd output_dtd;
1050 struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv;
1051 1008
1052 if (dev_priv->is_tv) { 1009 if (!intel_sdvo_set_target_output(intel_sdvo,
1053 struct intel_sdvo_dtd output_dtd; 1010 intel_sdvo->attached_output))
1054 bool success; 1011 return false;
1055 1012
1056 /* We need to construct preferred input timings based on our 1013 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1057 * output timings. To do that, we have to set the output 1014 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1058 * timings, even though this isn't really the right place in 1015 return false;
1059 * the sequence to do it. Oh well.
1060 */
1061 1016
1017 return true;
1018}
1062 1019
1063 /* Set output timings */ 1020static bool
1064 intel_sdvo_get_dtd_from_mode(&output_dtd, mode); 1021intel_sdvo_set_input_timings_for_mode(struct intel_sdvo *intel_sdvo,
1065 intel_sdvo_set_target_output(intel_encoder, 1022 struct drm_display_mode *mode,
1066 dev_priv->attached_output); 1023 struct drm_display_mode *adjusted_mode)
1067 intel_sdvo_set_output_timing(intel_encoder, &output_dtd); 1024{
1025 struct intel_sdvo_dtd input_dtd;
1068 1026
1069 /* Set the input timing to the screen. Assume always input 0. */ 1027 /* Reset the input timing to the screen. Assume always input 0. */
1070 intel_sdvo_set_target_input(intel_encoder, true, false); 1028 if (!intel_sdvo_set_target_input(intel_sdvo))
1029 return false;
1071 1030
1031 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1032 mode->clock / 10,
1033 mode->hdisplay,
1034 mode->vdisplay))
1035 return false;
1072 1036
1073 success = intel_sdvo_create_preferred_input_timing(intel_encoder, 1037 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1074 mode->clock / 10, 1038 &input_dtd))
1075 mode->hdisplay, 1039 return false;
1076 mode->vdisplay);
1077 if (success) {
1078 struct intel_sdvo_dtd input_dtd;
1079 1040
1080 intel_sdvo_get_preferred_input_timing(intel_encoder, 1041 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1081 &input_dtd); 1042 intel_sdvo->sdvo_flags = input_dtd.part2.sdvo_flags;
1082 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1083 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1084 1043
1085 drm_mode_set_crtcinfo(adjusted_mode, 0); 1044 drm_mode_set_crtcinfo(adjusted_mode, 0);
1045 mode->clock = adjusted_mode->clock;
1046 return true;
1047}
1086 1048
1087 mode->clock = adjusted_mode->clock; 1049static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1050 struct drm_display_mode *mode,
1051 struct drm_display_mode *adjusted_mode)
1052{
1053 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1088 1054
1089 adjusted_mode->clock *= 1055 /* We need to construct preferred input timings based on our
1090 intel_sdvo_get_pixel_multiplier(mode); 1056 * output timings. To do that, we have to set the output
1091 } else { 1057 * timings, even though this isn't really the right place in
1058 * the sequence to do it. Oh well.
1059 */
1060 if (intel_sdvo->is_tv) {
1061 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1092 return false; 1062 return false;
1093 }
1094 } else if (dev_priv->is_lvds) {
1095 struct intel_sdvo_dtd output_dtd;
1096 bool success;
1097
1098 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1099 /* Set output timings */
1100 intel_sdvo_get_dtd_from_mode(&output_dtd,
1101 dev_priv->sdvo_lvds_fixed_mode);
1102
1103 intel_sdvo_set_target_output(intel_encoder,
1104 dev_priv->attached_output);
1105 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
1106
1107 /* Set the input timing to the screen. Assume always input 0. */
1108 intel_sdvo_set_target_input(intel_encoder, true, false);
1109
1110
1111 success = intel_sdvo_create_preferred_input_timing(
1112 intel_encoder,
1113 mode->clock / 10,
1114 mode->hdisplay,
1115 mode->vdisplay);
1116
1117 if (success) {
1118 struct intel_sdvo_dtd input_dtd;
1119
1120 intel_sdvo_get_preferred_input_timing(intel_encoder,
1121 &input_dtd);
1122 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1123 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1124 1063
1125 drm_mode_set_crtcinfo(adjusted_mode, 0); 1064 (void) intel_sdvo_set_input_timings_for_mode(intel_sdvo,
1065 mode,
1066 adjusted_mode);
1067 } else if (intel_sdvo->is_lvds) {
1068 drm_mode_set_crtcinfo(intel_sdvo->sdvo_lvds_fixed_mode, 0);
1126 1069
1127 mode->clock = adjusted_mode->clock; 1070 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1128 1071 intel_sdvo->sdvo_lvds_fixed_mode))
1129 adjusted_mode->clock *=
1130 intel_sdvo_get_pixel_multiplier(mode);
1131 } else {
1132 return false; 1072 return false;
1133 }
1134 1073
1135 } else { 1074 (void) intel_sdvo_set_input_timings_for_mode(intel_sdvo,
1136 /* Make the CRTC code factor in the SDVO pixel multiplier. The 1075 mode,
1137 * SDVO device will be told of the multiplier during mode_set. 1076 adjusted_mode);
1138 */
1139 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
1140 } 1077 }
1078
1079 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1080 * SDVO device will be told of the multiplier during mode_set.
1081 */
1082 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
1083
1141 return true; 1084 return true;
1142} 1085}
1143 1086
@@ -1149,13 +1092,11 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1149 struct drm_i915_private *dev_priv = dev->dev_private; 1092 struct drm_i915_private *dev_priv = dev->dev_private;
1150 struct drm_crtc *crtc = encoder->crtc; 1093 struct drm_crtc *crtc = encoder->crtc;
1151 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 1094 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1152 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1095 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1153 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1154 u32 sdvox = 0; 1096 u32 sdvox = 0;
1155 int sdvo_pixel_multiply; 1097 int sdvo_pixel_multiply, rate;
1156 struct intel_sdvo_in_out_map in_out; 1098 struct intel_sdvo_in_out_map in_out;
1157 struct intel_sdvo_dtd input_dtd; 1099 struct intel_sdvo_dtd input_dtd;
1158 u8 status;
1159 1100
1160 if (!mode) 1101 if (!mode)
1161 return; 1102 return;
@@ -1166,41 +1107,46 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1166 * channel on the motherboard. In a two-input device, the first input 1107 * channel on the motherboard. In a two-input device, the first input
1167 * will be SDVOB and the second SDVOC. 1108 * will be SDVOB and the second SDVOC.
1168 */ 1109 */
1169 in_out.in0 = sdvo_priv->attached_output; 1110 in_out.in0 = intel_sdvo->attached_output;
1170 in_out.in1 = 0; 1111 in_out.in1 = 0;
1171 1112
1172 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP, 1113 intel_sdvo_set_value(intel_sdvo,
1114 SDVO_CMD_SET_IN_OUT_MAP,
1173 &in_out, sizeof(in_out)); 1115 &in_out, sizeof(in_out));
1174 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
1175 1116
1176 if (sdvo_priv->is_hdmi) { 1117 if (intel_sdvo->is_hdmi) {
1177 intel_sdvo_set_avi_infoframe(intel_encoder, mode); 1118 if (!intel_sdvo_set_avi_infoframe(intel_sdvo, mode))
1119 return;
1120
1178 sdvox |= SDVO_AUDIO_ENABLE; 1121 sdvox |= SDVO_AUDIO_ENABLE;
1179 } 1122 }
1180 1123
1181 /* We have tried to get input timing in mode_fixup, and filled into 1124 /* We have tried to get input timing in mode_fixup, and filled into
1182 adjusted_mode */ 1125 adjusted_mode */
1183 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { 1126 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1184 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); 1127 if (intel_sdvo->is_tv || intel_sdvo->is_lvds)
1185 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags; 1128 input_dtd.part2.sdvo_flags = intel_sdvo->sdvo_flags;
1186 } else
1187 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
1188 1129
1189 /* If it's a TV, we already set the output timing in mode_fixup. 1130 /* If it's a TV, we already set the output timing in mode_fixup.
1190 * Otherwise, the output timing is equal to the input timing. 1131 * Otherwise, the output timing is equal to the input timing.
1191 */ 1132 */
1192 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) { 1133 if (!intel_sdvo->is_tv && !intel_sdvo->is_lvds) {
1193 /* Set the output timing to the screen */ 1134 /* Set the output timing to the screen */
1194 intel_sdvo_set_target_output(intel_encoder, 1135 if (!intel_sdvo_set_target_output(intel_sdvo,
1195 sdvo_priv->attached_output); 1136 intel_sdvo->attached_output))
1196 intel_sdvo_set_output_timing(intel_encoder, &input_dtd); 1137 return;
1138
1139 (void) intel_sdvo_set_output_timing(intel_sdvo, &input_dtd);
1197 } 1140 }
1198 1141
1199 /* Set the input timing to the screen. Assume always input 0. */ 1142 /* Set the input timing to the screen. Assume always input 0. */
1200 intel_sdvo_set_target_input(intel_encoder, true, false); 1143 if (!intel_sdvo_set_target_input(intel_sdvo))
1144 return;
1201 1145
1202 if (sdvo_priv->is_tv) 1146 if (intel_sdvo->is_tv) {
1203 intel_sdvo_set_tv_format(intel_encoder); 1147 if (!intel_sdvo_set_tv_format(intel_sdvo))
1148 return;
1149 }
1204 1150
1205 /* We would like to use intel_sdvo_create_preferred_input_timing() to 1151 /* We would like to use intel_sdvo_create_preferred_input_timing() to
1206 * provide the device with a timing it can support, if it supports that 1152 * provide the device with a timing it can support, if it supports that
@@ -1217,23 +1163,17 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1217 intel_sdvo_set_input_timing(encoder, &input_dtd); 1163 intel_sdvo_set_input_timing(encoder, &input_dtd);
1218 } 1164 }
1219#else 1165#else
1220 intel_sdvo_set_input_timing(intel_encoder, &input_dtd); 1166 (void) intel_sdvo_set_input_timing(intel_sdvo, &input_dtd);
1221#endif 1167#endif
1222 1168
1223 switch (intel_sdvo_get_pixel_multiplier(mode)) { 1169 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1224 case 1: 1170 switch (sdvo_pixel_multiply) {
1225 intel_sdvo_set_clock_rate_mult(intel_encoder, 1171 case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1226 SDVO_CLOCK_RATE_MULT_1X); 1172 case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1227 break; 1173 case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1228 case 2:
1229 intel_sdvo_set_clock_rate_mult(intel_encoder,
1230 SDVO_CLOCK_RATE_MULT_2X);
1231 break;
1232 case 4:
1233 intel_sdvo_set_clock_rate_mult(intel_encoder,
1234 SDVO_CLOCK_RATE_MULT_4X);
1235 break;
1236 } 1174 }
1175 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1176 return;
1237 1177
1238 /* Set the SDVO control regs. */ 1178 /* Set the SDVO control regs. */
1239 if (IS_I965G(dev)) { 1179 if (IS_I965G(dev)) {
@@ -1243,8 +1183,8 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1243 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 1183 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1244 sdvox |= SDVO_HSYNC_ACTIVE_HIGH; 1184 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
1245 } else { 1185 } else {
1246 sdvox |= I915_READ(sdvo_priv->sdvo_reg); 1186 sdvox |= I915_READ(intel_sdvo->sdvo_reg);
1247 switch (sdvo_priv->sdvo_reg) { 1187 switch (intel_sdvo->sdvo_reg) {
1248 case SDVOB: 1188 case SDVOB:
1249 sdvox &= SDVOB_PRESERVE_MASK; 1189 sdvox &= SDVOB_PRESERVE_MASK;
1250 break; 1190 break;
@@ -1257,7 +1197,6 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1257 if (intel_crtc->pipe == 1) 1197 if (intel_crtc->pipe == 1)
1258 sdvox |= SDVO_PIPE_B_SELECT; 1198 sdvox |= SDVO_PIPE_B_SELECT;
1259 1199
1260 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1261 if (IS_I965G(dev)) { 1200 if (IS_I965G(dev)) {
1262 /* done in crtc_mode_set as the dpll_md reg must be written early */ 1201 /* done in crtc_mode_set as the dpll_md reg must be written early */
1263 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { 1202 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
@@ -1266,28 +1205,28 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1266 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT; 1205 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1267 } 1206 }
1268 1207
1269 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL) 1208 if (intel_sdvo->sdvo_flags & SDVO_NEED_TO_STALL)
1270 sdvox |= SDVO_STALL_SELECT; 1209 sdvox |= SDVO_STALL_SELECT;
1271 intel_sdvo_write_sdvox(intel_encoder, sdvox); 1210 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1272} 1211}
1273 1212
1274static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) 1213static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1275{ 1214{
1276 struct drm_device *dev = encoder->dev; 1215 struct drm_device *dev = encoder->dev;
1277 struct drm_i915_private *dev_priv = dev->dev_private; 1216 struct drm_i915_private *dev_priv = dev->dev_private;
1278 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1217 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1279 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 1218 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1280 u32 temp; 1219 u32 temp;
1281 1220
1282 if (mode != DRM_MODE_DPMS_ON) { 1221 if (mode != DRM_MODE_DPMS_ON) {
1283 intel_sdvo_set_active_outputs(intel_encoder, 0); 1222 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1284 if (0) 1223 if (0)
1285 intel_sdvo_set_encoder_power_state(intel_encoder, mode); 1224 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1286 1225
1287 if (mode == DRM_MODE_DPMS_OFF) { 1226 if (mode == DRM_MODE_DPMS_OFF) {
1288 temp = I915_READ(sdvo_priv->sdvo_reg); 1227 temp = I915_READ(intel_sdvo->sdvo_reg);
1289 if ((temp & SDVO_ENABLE) != 0) { 1228 if ((temp & SDVO_ENABLE) != 0) {
1290 intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE); 1229 intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
1291 } 1230 }
1292 } 1231 }
1293 } else { 1232 } else {
@@ -1295,28 +1234,25 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1295 int i; 1234 int i;
1296 u8 status; 1235 u8 status;
1297 1236
1298 temp = I915_READ(sdvo_priv->sdvo_reg); 1237 temp = I915_READ(intel_sdvo->sdvo_reg);
1299 if ((temp & SDVO_ENABLE) == 0) 1238 if ((temp & SDVO_ENABLE) == 0)
1300 intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE); 1239 intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
1301 for (i = 0; i < 2; i++) 1240 for (i = 0; i < 2; i++)
1302 intel_wait_for_vblank(dev); 1241 intel_wait_for_vblank(dev, intel_crtc->pipe);
1303
1304 status = intel_sdvo_get_trained_inputs(intel_encoder, &input1,
1305 &input2);
1306
1307 1242
1243 status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1308 /* Warn if the device reported failure to sync. 1244 /* Warn if the device reported failure to sync.
1309 * A lot of SDVO devices fail to notify of sync, but it's 1245 * A lot of SDVO devices fail to notify of sync, but it's
1310 * a given it the status is a success, we succeeded. 1246 * a given it the status is a success, we succeeded.
1311 */ 1247 */
1312 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) { 1248 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
1313 DRM_DEBUG_KMS("First %s output reported failure to " 1249 DRM_DEBUG_KMS("First %s output reported failure to "
1314 "sync\n", SDVO_NAME(sdvo_priv)); 1250 "sync\n", SDVO_NAME(intel_sdvo));
1315 } 1251 }
1316 1252
1317 if (0) 1253 if (0)
1318 intel_sdvo_set_encoder_power_state(intel_encoder, mode); 1254 intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1319 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output); 1255 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1320 } 1256 }
1321 return; 1257 return;
1322} 1258}
@@ -1325,42 +1261,31 @@ static int intel_sdvo_mode_valid(struct drm_connector *connector,
1325 struct drm_display_mode *mode) 1261 struct drm_display_mode *mode)
1326{ 1262{
1327 struct drm_encoder *encoder = intel_attached_encoder(connector); 1263 struct drm_encoder *encoder = intel_attached_encoder(connector);
1328 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1264 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1329 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1330 1265
1331 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 1266 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1332 return MODE_NO_DBLESCAN; 1267 return MODE_NO_DBLESCAN;
1333 1268
1334 if (sdvo_priv->pixel_clock_min > mode->clock) 1269 if (intel_sdvo->pixel_clock_min > mode->clock)
1335 return MODE_CLOCK_LOW; 1270 return MODE_CLOCK_LOW;
1336 1271
1337 if (sdvo_priv->pixel_clock_max < mode->clock) 1272 if (intel_sdvo->pixel_clock_max < mode->clock)
1338 return MODE_CLOCK_HIGH; 1273 return MODE_CLOCK_HIGH;
1339 1274
1340 if (sdvo_priv->is_lvds == true) { 1275 if (intel_sdvo->is_lvds) {
1341 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL) 1276 if (mode->hdisplay > intel_sdvo->sdvo_lvds_fixed_mode->hdisplay)
1342 return MODE_PANEL; 1277 return MODE_PANEL;
1343 1278
1344 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay) 1279 if (mode->vdisplay > intel_sdvo->sdvo_lvds_fixed_mode->vdisplay)
1345 return MODE_PANEL;
1346
1347 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1348 return MODE_PANEL; 1280 return MODE_PANEL;
1349 } 1281 }
1350 1282
1351 return MODE_OK; 1283 return MODE_OK;
1352} 1284}
1353 1285
1354static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps) 1286static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1355{ 1287{
1356 u8 status; 1288 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DEVICE_CAPS, caps, sizeof(*caps));
1357
1358 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1359 status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps));
1360 if (status != SDVO_CMD_STATUS_SUCCESS)
1361 return false;
1362
1363 return true;
1364} 1289}
1365 1290
1366/* No use! */ 1291/* No use! */
@@ -1368,12 +1293,12 @@ static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, str
1368struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB) 1293struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1369{ 1294{
1370 struct drm_connector *connector = NULL; 1295 struct drm_connector *connector = NULL;
1371 struct intel_encoder *iout = NULL; 1296 struct intel_sdvo *iout = NULL;
1372 struct intel_sdvo_priv *sdvo; 1297 struct intel_sdvo *sdvo;
1373 1298
1374 /* find the sdvo connector */ 1299 /* find the sdvo connector */
1375 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 1300 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1376 iout = to_intel_encoder(connector); 1301 iout = to_intel_sdvo(connector);
1377 1302
1378 if (iout->type != INTEL_OUTPUT_SDVO) 1303 if (iout->type != INTEL_OUTPUT_SDVO)
1379 continue; 1304 continue;
@@ -1395,75 +1320,69 @@ int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1395{ 1320{
1396 u8 response[2]; 1321 u8 response[2];
1397 u8 status; 1322 u8 status;
1398 struct intel_encoder *intel_encoder; 1323 struct intel_sdvo *intel_sdvo;
1399 DRM_DEBUG_KMS("\n"); 1324 DRM_DEBUG_KMS("\n");
1400 1325
1401 if (!connector) 1326 if (!connector)
1402 return 0; 1327 return 0;
1403 1328
1404 intel_encoder = to_intel_encoder(connector); 1329 intel_sdvo = to_intel_sdvo(connector);
1405
1406 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1407 status = intel_sdvo_read_response(intel_encoder, &response, 2);
1408
1409 if (response[0] !=0)
1410 return 1;
1411 1330
1412 return 0; 1331 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1332 &response, 2) && response[0];
1413} 1333}
1414 1334
1415void intel_sdvo_set_hotplug(struct drm_connector *connector, int on) 1335void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1416{ 1336{
1417 u8 response[2]; 1337 u8 response[2];
1418 u8 status; 1338 u8 status;
1419 struct intel_encoder *intel_encoder = to_intel_encoder(connector); 1339 struct intel_sdvo *intel_sdvo = to_intel_sdvo(connector);
1420 1340
1421 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); 1341 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1422 intel_sdvo_read_response(intel_encoder, &response, 2); 1342 intel_sdvo_read_response(intel_sdvo, &response, 2);
1423 1343
1424 if (on) { 1344 if (on) {
1425 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); 1345 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1426 status = intel_sdvo_read_response(intel_encoder, &response, 2); 1346 status = intel_sdvo_read_response(intel_sdvo, &response, 2);
1427 1347
1428 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); 1348 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
1429 } else { 1349 } else {
1430 response[0] = 0; 1350 response[0] = 0;
1431 response[1] = 0; 1351 response[1] = 0;
1432 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); 1352 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
1433 } 1353 }
1434 1354
1435 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); 1355 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1436 intel_sdvo_read_response(intel_encoder, &response, 2); 1356 intel_sdvo_read_response(intel_sdvo, &response, 2);
1437} 1357}
1438#endif 1358#endif
1439 1359
1440static bool 1360static bool
1441intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder) 1361intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
1442{ 1362{
1443 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1444 int caps = 0; 1363 int caps = 0;
1445 1364
1446 if (sdvo_priv->caps.output_flags & 1365 if (intel_sdvo->caps.output_flags &
1447 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) 1366 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1448 caps++; 1367 caps++;
1449 if (sdvo_priv->caps.output_flags & 1368 if (intel_sdvo->caps.output_flags &
1450 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)) 1369 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1451 caps++; 1370 caps++;
1452 if (sdvo_priv->caps.output_flags & 1371 if (intel_sdvo->caps.output_flags &
1453 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1)) 1372 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
1454 caps++; 1373 caps++;
1455 if (sdvo_priv->caps.output_flags & 1374 if (intel_sdvo->caps.output_flags &
1456 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1)) 1375 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1457 caps++; 1376 caps++;
1458 if (sdvo_priv->caps.output_flags & 1377 if (intel_sdvo->caps.output_flags &
1459 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1)) 1378 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1460 caps++; 1379 caps++;
1461 1380
1462 if (sdvo_priv->caps.output_flags & 1381 if (intel_sdvo->caps.output_flags &
1463 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1)) 1382 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1464 caps++; 1383 caps++;
1465 1384
1466 if (sdvo_priv->caps.output_flags & 1385 if (intel_sdvo->caps.output_flags &
1467 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)) 1386 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1468 caps++; 1387 caps++;
1469 1388
@@ -1475,11 +1394,11 @@ intel_find_analog_connector(struct drm_device *dev)
1475{ 1394{
1476 struct drm_connector *connector; 1395 struct drm_connector *connector;
1477 struct drm_encoder *encoder; 1396 struct drm_encoder *encoder;
1478 struct intel_encoder *intel_encoder; 1397 struct intel_sdvo *intel_sdvo;
1479 1398
1480 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 1399 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1481 intel_encoder = enc_to_intel_encoder(encoder); 1400 intel_sdvo = enc_to_intel_sdvo(encoder);
1482 if (intel_encoder->type == INTEL_OUTPUT_ANALOG) { 1401 if (intel_sdvo->base.type == INTEL_OUTPUT_ANALOG) {
1483 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 1402 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1484 if (encoder == intel_attached_encoder(connector)) 1403 if (encoder == intel_attached_encoder(connector))
1485 return connector; 1404 return connector;
@@ -1493,8 +1412,8 @@ static int
1493intel_analog_is_connected(struct drm_device *dev) 1412intel_analog_is_connected(struct drm_device *dev)
1494{ 1413{
1495 struct drm_connector *analog_connector; 1414 struct drm_connector *analog_connector;
1496 analog_connector = intel_find_analog_connector(dev);
1497 1415
1416 analog_connector = intel_find_analog_connector(dev);
1498 if (!analog_connector) 1417 if (!analog_connector)
1499 return false; 1418 return false;
1500 1419
@@ -1509,54 +1428,52 @@ enum drm_connector_status
1509intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) 1428intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1510{ 1429{
1511 struct drm_encoder *encoder = intel_attached_encoder(connector); 1430 struct drm_encoder *encoder = intel_attached_encoder(connector);
1512 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1431 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1513 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 1432 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1514 struct intel_connector *intel_connector = to_intel_connector(connector);
1515 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1516 enum drm_connector_status status = connector_status_connected; 1433 enum drm_connector_status status = connector_status_connected;
1517 struct edid *edid = NULL; 1434 struct edid *edid = NULL;
1518 1435
1519 edid = drm_get_edid(connector, intel_encoder->ddc_bus); 1436 edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus);
1520 1437
1521 /* This is only applied to SDVO cards with multiple outputs */ 1438 /* This is only applied to SDVO cards with multiple outputs */
1522 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) { 1439 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
1523 uint8_t saved_ddc, temp_ddc; 1440 uint8_t saved_ddc, temp_ddc;
1524 saved_ddc = sdvo_priv->ddc_bus; 1441 saved_ddc = intel_sdvo->ddc_bus;
1525 temp_ddc = sdvo_priv->ddc_bus >> 1; 1442 temp_ddc = intel_sdvo->ddc_bus >> 1;
1526 /* 1443 /*
1527 * Don't use the 1 as the argument of DDC bus switch to get 1444 * Don't use the 1 as the argument of DDC bus switch to get
1528 * the EDID. It is used for SDVO SPD ROM. 1445 * the EDID. It is used for SDVO SPD ROM.
1529 */ 1446 */
1530 while(temp_ddc > 1) { 1447 while(temp_ddc > 1) {
1531 sdvo_priv->ddc_bus = temp_ddc; 1448 intel_sdvo->ddc_bus = temp_ddc;
1532 edid = drm_get_edid(connector, intel_encoder->ddc_bus); 1449 edid = drm_get_edid(connector, intel_sdvo->base.ddc_bus);
1533 if (edid) { 1450 if (edid) {
1534 /* 1451 /*
1535 * When we can get the EDID, maybe it is the 1452 * When we can get the EDID, maybe it is the
1536 * correct DDC bus. Update it. 1453 * correct DDC bus. Update it.
1537 */ 1454 */
1538 sdvo_priv->ddc_bus = temp_ddc; 1455 intel_sdvo->ddc_bus = temp_ddc;
1539 break; 1456 break;
1540 } 1457 }
1541 temp_ddc >>= 1; 1458 temp_ddc >>= 1;
1542 } 1459 }
1543 if (edid == NULL) 1460 if (edid == NULL)
1544 sdvo_priv->ddc_bus = saved_ddc; 1461 intel_sdvo->ddc_bus = saved_ddc;
1545 } 1462 }
1546 /* when there is no edid and no monitor is connected with VGA 1463 /* when there is no edid and no monitor is connected with VGA
1547 * port, try to use the CRT ddc to read the EDID for DVI-connector 1464 * port, try to use the CRT ddc to read the EDID for DVI-connector
1548 */ 1465 */
1549 if (edid == NULL && sdvo_priv->analog_ddc_bus && 1466 if (edid == NULL && intel_sdvo->analog_ddc_bus &&
1550 !intel_analog_is_connected(connector->dev)) 1467 !intel_analog_is_connected(connector->dev))
1551 edid = drm_get_edid(connector, sdvo_priv->analog_ddc_bus); 1468 edid = drm_get_edid(connector, intel_sdvo->analog_ddc_bus);
1552 1469
1553 if (edid != NULL) { 1470 if (edid != NULL) {
1554 bool is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL); 1471 bool is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
1555 bool need_digital = !!(sdvo_connector->output_flag & SDVO_TMDS_MASK); 1472 bool need_digital = !!(intel_sdvo_connector->output_flag & SDVO_TMDS_MASK);
1556 1473
1557 /* DDC bus is shared, match EDID to connector type */ 1474 /* DDC bus is shared, match EDID to connector type */
1558 if (is_digital && need_digital) 1475 if (is_digital && need_digital)
1559 sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid); 1476 intel_sdvo->is_hdmi = drm_detect_hdmi_monitor(edid);
1560 else if (is_digital != need_digital) 1477 else if (is_digital != need_digital)
1561 status = connector_status_disconnected; 1478 status = connector_status_disconnected;
1562 1479
@@ -1572,33 +1489,29 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1572static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector) 1489static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1573{ 1490{
1574 uint16_t response; 1491 uint16_t response;
1575 u8 status;
1576 struct drm_encoder *encoder = intel_attached_encoder(connector); 1492 struct drm_encoder *encoder = intel_attached_encoder(connector);
1577 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1493 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1578 struct intel_connector *intel_connector = to_intel_connector(connector); 1494 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1579 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1580 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1581 enum drm_connector_status ret; 1495 enum drm_connector_status ret;
1582 1496
1583 intel_sdvo_write_cmd(intel_encoder, 1497 if (!intel_sdvo_write_cmd(intel_sdvo,
1584 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0); 1498 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0))
1585 if (sdvo_priv->is_tv) { 1499 return connector_status_unknown;
1500 if (intel_sdvo->is_tv) {
1586 /* add 30ms delay when the output type is SDVO-TV */ 1501 /* add 30ms delay when the output type is SDVO-TV */
1587 mdelay(30); 1502 mdelay(30);
1588 } 1503 }
1589 status = intel_sdvo_read_response(intel_encoder, &response, 2); 1504 if (!intel_sdvo_read_response(intel_sdvo, &response, 2))
1505 return connector_status_unknown;
1590 1506
1591 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8); 1507 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
1592 1508
1593 if (status != SDVO_CMD_STATUS_SUCCESS)
1594 return connector_status_unknown;
1595
1596 if (response == 0) 1509 if (response == 0)
1597 return connector_status_disconnected; 1510 return connector_status_disconnected;
1598 1511
1599 sdvo_priv->attached_output = response; 1512 intel_sdvo->attached_output = response;
1600 1513
1601 if ((sdvo_connector->output_flag & response) == 0) 1514 if ((intel_sdvo_connector->output_flag & response) == 0)
1602 ret = connector_status_disconnected; 1515 ret = connector_status_disconnected;
1603 else if (response & SDVO_TMDS_MASK) 1516 else if (response & SDVO_TMDS_MASK)
1604 ret = intel_sdvo_hdmi_sink_detect(connector); 1517 ret = intel_sdvo_hdmi_sink_detect(connector);
@@ -1607,16 +1520,16 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect
1607 1520
1608 /* May update encoder flag for like clock for SDVO TV, etc.*/ 1521 /* May update encoder flag for like clock for SDVO TV, etc.*/
1609 if (ret == connector_status_connected) { 1522 if (ret == connector_status_connected) {
1610 sdvo_priv->is_tv = false; 1523 intel_sdvo->is_tv = false;
1611 sdvo_priv->is_lvds = false; 1524 intel_sdvo->is_lvds = false;
1612 intel_encoder->needs_tv_clock = false; 1525 intel_sdvo->base.needs_tv_clock = false;
1613 1526
1614 if (response & SDVO_TV_MASK) { 1527 if (response & SDVO_TV_MASK) {
1615 sdvo_priv->is_tv = true; 1528 intel_sdvo->is_tv = true;
1616 intel_encoder->needs_tv_clock = true; 1529 intel_sdvo->base.needs_tv_clock = true;
1617 } 1530 }
1618 if (response & SDVO_LVDS_MASK) 1531 if (response & SDVO_LVDS_MASK)
1619 sdvo_priv->is_lvds = true; 1532 intel_sdvo->is_lvds = intel_sdvo->sdvo_lvds_fixed_mode != NULL;
1620 } 1533 }
1621 1534
1622 return ret; 1535 return ret;
@@ -1625,12 +1538,11 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect
1625static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) 1538static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
1626{ 1539{
1627 struct drm_encoder *encoder = intel_attached_encoder(connector); 1540 struct drm_encoder *encoder = intel_attached_encoder(connector);
1628 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1541 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1629 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1630 int num_modes; 1542 int num_modes;
1631 1543
1632 /* set the bus switch and get the modes */ 1544 /* set the bus switch and get the modes */
1633 num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); 1545 num_modes = intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus);
1634 1546
1635 /* 1547 /*
1636 * Mac mini hack. On this device, the DVI-I connector shares one DDC 1548 * Mac mini hack. On this device, the DVI-I connector shares one DDC
@@ -1639,11 +1551,11 @@ static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
1639 * which case we'll look there for the digital DDC data. 1551 * which case we'll look there for the digital DDC data.
1640 */ 1552 */
1641 if (num_modes == 0 && 1553 if (num_modes == 0 &&
1642 sdvo_priv->analog_ddc_bus && 1554 intel_sdvo->analog_ddc_bus &&
1643 !intel_analog_is_connected(connector->dev)) { 1555 !intel_analog_is_connected(connector->dev)) {
1644 /* Switch to the analog ddc bus and try that 1556 /* Switch to the analog ddc bus and try that
1645 */ 1557 */
1646 (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus); 1558 (void) intel_ddc_get_modes(connector, intel_sdvo->analog_ddc_bus);
1647 } 1559 }
1648} 1560}
1649 1561
@@ -1715,52 +1627,43 @@ struct drm_display_mode sdvo_tv_modes[] = {
1715static void intel_sdvo_get_tv_modes(struct drm_connector *connector) 1627static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1716{ 1628{
1717 struct drm_encoder *encoder = intel_attached_encoder(connector); 1629 struct drm_encoder *encoder = intel_attached_encoder(connector);
1718 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1630 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1719 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1720 struct intel_sdvo_sdtv_resolution_request tv_res; 1631 struct intel_sdvo_sdtv_resolution_request tv_res;
1721 uint32_t reply = 0, format_map = 0; 1632 uint32_t reply = 0, format_map = 0;
1722 int i; 1633 int i;
1723 uint8_t status;
1724
1725 1634
1726 /* Read the list of supported input resolutions for the selected TV 1635 /* Read the list of supported input resolutions for the selected TV
1727 * format. 1636 * format.
1728 */ 1637 */
1729 for (i = 0; i < TV_FORMAT_NUM; i++) 1638 format_map = 1 << intel_sdvo->tv_format_index;
1730 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1731 break;
1732
1733 format_map = (1 << i);
1734 memcpy(&tv_res, &format_map, 1639 memcpy(&tv_res, &format_map,
1735 sizeof(struct intel_sdvo_sdtv_resolution_request) > 1640 min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
1736 sizeof(format_map) ? sizeof(format_map) :
1737 sizeof(struct intel_sdvo_sdtv_resolution_request));
1738 1641
1739 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output); 1642 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
1643 return;
1740 1644
1741 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, 1645 BUILD_BUG_ON(sizeof(tv_res) != 3);
1742 &tv_res, sizeof(tv_res)); 1646 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
1743 status = intel_sdvo_read_response(intel_encoder, &reply, 3); 1647 &tv_res, sizeof(tv_res)))
1744 if (status != SDVO_CMD_STATUS_SUCCESS) 1648 return;
1649 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
1745 return; 1650 return;
1746 1651
1747 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++) 1652 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
1748 if (reply & (1 << i)) { 1653 if (reply & (1 << i)) {
1749 struct drm_display_mode *nmode; 1654 struct drm_display_mode *nmode;
1750 nmode = drm_mode_duplicate(connector->dev, 1655 nmode = drm_mode_duplicate(connector->dev,
1751 &sdvo_tv_modes[i]); 1656 &sdvo_tv_modes[i]);
1752 if (nmode) 1657 if (nmode)
1753 drm_mode_probed_add(connector, nmode); 1658 drm_mode_probed_add(connector, nmode);
1754 } 1659 }
1755
1756} 1660}
1757 1661
1758static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) 1662static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1759{ 1663{
1760 struct drm_encoder *encoder = intel_attached_encoder(connector); 1664 struct drm_encoder *encoder = intel_attached_encoder(connector);
1761 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1665 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1762 struct drm_i915_private *dev_priv = connector->dev->dev_private; 1666 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1763 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
1764 struct drm_display_mode *newmode; 1667 struct drm_display_mode *newmode;
1765 1668
1766 /* 1669 /*
@@ -1768,7 +1671,7 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1768 * Assume that the preferred modes are 1671 * Assume that the preferred modes are
1769 * arranged in priority order. 1672 * arranged in priority order.
1770 */ 1673 */
1771 intel_ddc_get_modes(connector, intel_encoder->ddc_bus); 1674 intel_ddc_get_modes(connector, intel_sdvo->base.ddc_bus);
1772 if (list_empty(&connector->probed_modes) == false) 1675 if (list_empty(&connector->probed_modes) == false)
1773 goto end; 1676 goto end;
1774 1677
@@ -1787,8 +1690,9 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1787end: 1690end:
1788 list_for_each_entry(newmode, &connector->probed_modes, head) { 1691 list_for_each_entry(newmode, &connector->probed_modes, head) {
1789 if (newmode->type & DRM_MODE_TYPE_PREFERRED) { 1692 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1790 sdvo_priv->sdvo_lvds_fixed_mode = 1693 intel_sdvo->sdvo_lvds_fixed_mode =
1791 drm_mode_duplicate(connector->dev, newmode); 1694 drm_mode_duplicate(connector->dev, newmode);
1695 intel_sdvo->is_lvds = true;
1792 break; 1696 break;
1793 } 1697 }
1794 } 1698 }
@@ -1797,66 +1701,67 @@ end:
1797 1701
1798static int intel_sdvo_get_modes(struct drm_connector *connector) 1702static int intel_sdvo_get_modes(struct drm_connector *connector)
1799{ 1703{
1800 struct intel_connector *intel_connector = to_intel_connector(connector); 1704 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1801 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1802 1705
1803 if (IS_TV(sdvo_connector)) 1706 if (IS_TV(intel_sdvo_connector))
1804 intel_sdvo_get_tv_modes(connector); 1707 intel_sdvo_get_tv_modes(connector);
1805 else if (IS_LVDS(sdvo_connector)) 1708 else if (IS_LVDS(intel_sdvo_connector))
1806 intel_sdvo_get_lvds_modes(connector); 1709 intel_sdvo_get_lvds_modes(connector);
1807 else 1710 else
1808 intel_sdvo_get_ddc_modes(connector); 1711 intel_sdvo_get_ddc_modes(connector);
1809 1712
1810 if (list_empty(&connector->probed_modes)) 1713 return !list_empty(&connector->probed_modes);
1811 return 0;
1812 return 1;
1813} 1714}
1814 1715
1815static 1716static void
1816void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) 1717intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1817{ 1718{
1818 struct intel_connector *intel_connector = to_intel_connector(connector); 1719 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1819 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
1820 struct drm_device *dev = connector->dev; 1720 struct drm_device *dev = connector->dev;
1821 1721
1822 if (IS_TV(sdvo_priv)) { 1722 if (intel_sdvo_connector->left)
1823 if (sdvo_priv->left_property) 1723 drm_property_destroy(dev, intel_sdvo_connector->left);
1824 drm_property_destroy(dev, sdvo_priv->left_property); 1724 if (intel_sdvo_connector->right)
1825 if (sdvo_priv->right_property) 1725 drm_property_destroy(dev, intel_sdvo_connector->right);
1826 drm_property_destroy(dev, sdvo_priv->right_property); 1726 if (intel_sdvo_connector->top)
1827 if (sdvo_priv->top_property) 1727 drm_property_destroy(dev, intel_sdvo_connector->top);
1828 drm_property_destroy(dev, sdvo_priv->top_property); 1728 if (intel_sdvo_connector->bottom)
1829 if (sdvo_priv->bottom_property) 1729 drm_property_destroy(dev, intel_sdvo_connector->bottom);
1830 drm_property_destroy(dev, sdvo_priv->bottom_property); 1730 if (intel_sdvo_connector->hpos)
1831 if (sdvo_priv->hpos_property) 1731 drm_property_destroy(dev, intel_sdvo_connector->hpos);
1832 drm_property_destroy(dev, sdvo_priv->hpos_property); 1732 if (intel_sdvo_connector->vpos)
1833 if (sdvo_priv->vpos_property) 1733 drm_property_destroy(dev, intel_sdvo_connector->vpos);
1834 drm_property_destroy(dev, sdvo_priv->vpos_property); 1734 if (intel_sdvo_connector->saturation)
1835 if (sdvo_priv->saturation_property) 1735 drm_property_destroy(dev, intel_sdvo_connector->saturation);
1836 drm_property_destroy(dev, 1736 if (intel_sdvo_connector->contrast)
1837 sdvo_priv->saturation_property); 1737 drm_property_destroy(dev, intel_sdvo_connector->contrast);
1838 if (sdvo_priv->contrast_property) 1738 if (intel_sdvo_connector->hue)
1839 drm_property_destroy(dev, 1739 drm_property_destroy(dev, intel_sdvo_connector->hue);
1840 sdvo_priv->contrast_property); 1740 if (intel_sdvo_connector->sharpness)
1841 if (sdvo_priv->hue_property) 1741 drm_property_destroy(dev, intel_sdvo_connector->sharpness);
1842 drm_property_destroy(dev, sdvo_priv->hue_property); 1742 if (intel_sdvo_connector->flicker_filter)
1843 } 1743 drm_property_destroy(dev, intel_sdvo_connector->flicker_filter);
1844 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) { 1744 if (intel_sdvo_connector->flicker_filter_2d)
1845 if (sdvo_priv->brightness_property) 1745 drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_2d);
1846 drm_property_destroy(dev, 1746 if (intel_sdvo_connector->flicker_filter_adaptive)
1847 sdvo_priv->brightness_property); 1747 drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_adaptive);
1848 } 1748 if (intel_sdvo_connector->tv_luma_filter)
1849 return; 1749 drm_property_destroy(dev, intel_sdvo_connector->tv_luma_filter);
1750 if (intel_sdvo_connector->tv_chroma_filter)
1751 drm_property_destroy(dev, intel_sdvo_connector->tv_chroma_filter);
1752 if (intel_sdvo_connector->dot_crawl)
1753 drm_property_destroy(dev, intel_sdvo_connector->dot_crawl);
1754 if (intel_sdvo_connector->brightness)
1755 drm_property_destroy(dev, intel_sdvo_connector->brightness);
1850} 1756}
1851 1757
1852static void intel_sdvo_destroy(struct drm_connector *connector) 1758static void intel_sdvo_destroy(struct drm_connector *connector)
1853{ 1759{
1854 struct intel_connector *intel_connector = to_intel_connector(connector); 1760 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1855 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1856 1761
1857 if (sdvo_connector->tv_format_property) 1762 if (intel_sdvo_connector->tv_format)
1858 drm_property_destroy(connector->dev, 1763 drm_property_destroy(connector->dev,
1859 sdvo_connector->tv_format_property); 1764 intel_sdvo_connector->tv_format);
1860 1765
1861 intel_sdvo_destroy_enhance_property(connector); 1766 intel_sdvo_destroy_enhance_property(connector);
1862 drm_sysfs_connector_remove(connector); 1767 drm_sysfs_connector_remove(connector);
@@ -1870,132 +1775,118 @@ intel_sdvo_set_property(struct drm_connector *connector,
1870 uint64_t val) 1775 uint64_t val)
1871{ 1776{
1872 struct drm_encoder *encoder = intel_attached_encoder(connector); 1777 struct drm_encoder *encoder = intel_attached_encoder(connector);
1873 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1778 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
1874 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 1779 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1875 struct intel_connector *intel_connector = to_intel_connector(connector);
1876 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1877 struct drm_crtc *crtc = encoder->crtc;
1878 int ret = 0;
1879 bool changed = false;
1880 uint8_t cmd, status;
1881 uint16_t temp_value; 1780 uint16_t temp_value;
1781 uint8_t cmd;
1782 int ret;
1882 1783
1883 ret = drm_connector_property_set_value(connector, property, val); 1784 ret = drm_connector_property_set_value(connector, property, val);
1884 if (ret < 0) 1785 if (ret)
1885 goto out; 1786 return ret;
1787
1788#define CHECK_PROPERTY(name, NAME) \
1789 if (intel_sdvo_connector->name == property) { \
1790 if (intel_sdvo_connector->cur_##name == temp_value) return 0; \
1791 if (intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
1792 cmd = SDVO_CMD_SET_##NAME; \
1793 intel_sdvo_connector->cur_##name = temp_value; \
1794 goto set_value; \
1795 }
1886 1796
1887 if (property == sdvo_connector->tv_format_property) { 1797 if (property == intel_sdvo_connector->tv_format) {
1888 if (val >= TV_FORMAT_NUM) { 1798 if (val >= TV_FORMAT_NUM)
1889 ret = -EINVAL; 1799 return -EINVAL;
1890 goto out;
1891 }
1892 if (sdvo_priv->tv_format_name ==
1893 sdvo_connector->tv_format_supported[val])
1894 goto out;
1895 1800
1896 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val]; 1801 if (intel_sdvo->tv_format_index ==
1897 changed = true; 1802 intel_sdvo_connector->tv_format_supported[val])
1898 } 1803 return 0;
1899 1804
1900 if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) { 1805 intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[val];
1901 cmd = 0; 1806 goto done;
1807 } else if (IS_TV_OR_LVDS(intel_sdvo_connector)) {
1902 temp_value = val; 1808 temp_value = val;
1903 if (sdvo_connector->left_property == property) { 1809 if (intel_sdvo_connector->left == property) {
1904 drm_connector_property_set_value(connector, 1810 drm_connector_property_set_value(connector,
1905 sdvo_connector->right_property, val); 1811 intel_sdvo_connector->right, val);
1906 if (sdvo_connector->left_margin == temp_value) 1812 if (intel_sdvo_connector->left_margin == temp_value)
1907 goto out; 1813 return 0;
1908 1814
1909 sdvo_connector->left_margin = temp_value; 1815 intel_sdvo_connector->left_margin = temp_value;
1910 sdvo_connector->right_margin = temp_value; 1816 intel_sdvo_connector->right_margin = temp_value;
1911 temp_value = sdvo_connector->max_hscan - 1817 temp_value = intel_sdvo_connector->max_hscan -
1912 sdvo_connector->left_margin; 1818 intel_sdvo_connector->left_margin;
1913 cmd = SDVO_CMD_SET_OVERSCAN_H; 1819 cmd = SDVO_CMD_SET_OVERSCAN_H;
1914 } else if (sdvo_connector->right_property == property) { 1820 goto set_value;
1821 } else if (intel_sdvo_connector->right == property) {
1915 drm_connector_property_set_value(connector, 1822 drm_connector_property_set_value(connector,
1916 sdvo_connector->left_property, val); 1823 intel_sdvo_connector->left, val);
1917 if (sdvo_connector->right_margin == temp_value) 1824 if (intel_sdvo_connector->right_margin == temp_value)
1918 goto out; 1825 return 0;
1919 1826
1920 sdvo_connector->left_margin = temp_value; 1827 intel_sdvo_connector->left_margin = temp_value;
1921 sdvo_connector->right_margin = temp_value; 1828 intel_sdvo_connector->right_margin = temp_value;
1922 temp_value = sdvo_connector->max_hscan - 1829 temp_value = intel_sdvo_connector->max_hscan -
1923 sdvo_connector->left_margin; 1830 intel_sdvo_connector->left_margin;
1924 cmd = SDVO_CMD_SET_OVERSCAN_H; 1831 cmd = SDVO_CMD_SET_OVERSCAN_H;
1925 } else if (sdvo_connector->top_property == property) { 1832 goto set_value;
1833 } else if (intel_sdvo_connector->top == property) {
1926 drm_connector_property_set_value(connector, 1834 drm_connector_property_set_value(connector,
1927 sdvo_connector->bottom_property, val); 1835 intel_sdvo_connector->bottom, val);
1928 if (sdvo_connector->top_margin == temp_value) 1836 if (intel_sdvo_connector->top_margin == temp_value)
1929 goto out; 1837 return 0;
1930 1838
1931 sdvo_connector->top_margin = temp_value; 1839 intel_sdvo_connector->top_margin = temp_value;
1932 sdvo_connector->bottom_margin = temp_value; 1840 intel_sdvo_connector->bottom_margin = temp_value;
1933 temp_value = sdvo_connector->max_vscan - 1841 temp_value = intel_sdvo_connector->max_vscan -
1934 sdvo_connector->top_margin; 1842 intel_sdvo_connector->top_margin;
1935 cmd = SDVO_CMD_SET_OVERSCAN_V; 1843 cmd = SDVO_CMD_SET_OVERSCAN_V;
1936 } else if (sdvo_connector->bottom_property == property) { 1844 goto set_value;
1845 } else if (intel_sdvo_connector->bottom == property) {
1937 drm_connector_property_set_value(connector, 1846 drm_connector_property_set_value(connector,
1938 sdvo_connector->top_property, val); 1847 intel_sdvo_connector->top, val);
1939 if (sdvo_connector->bottom_margin == temp_value) 1848 if (intel_sdvo_connector->bottom_margin == temp_value)
1940 goto out; 1849 return 0;
1941 sdvo_connector->top_margin = temp_value; 1850
1942 sdvo_connector->bottom_margin = temp_value; 1851 intel_sdvo_connector->top_margin = temp_value;
1943 temp_value = sdvo_connector->max_vscan - 1852 intel_sdvo_connector->bottom_margin = temp_value;
1944 sdvo_connector->top_margin; 1853 temp_value = intel_sdvo_connector->max_vscan -
1854 intel_sdvo_connector->top_margin;
1945 cmd = SDVO_CMD_SET_OVERSCAN_V; 1855 cmd = SDVO_CMD_SET_OVERSCAN_V;
1946 } else if (sdvo_connector->hpos_property == property) { 1856 goto set_value;
1947 if (sdvo_connector->cur_hpos == temp_value)
1948 goto out;
1949
1950 cmd = SDVO_CMD_SET_POSITION_H;
1951 sdvo_connector->cur_hpos = temp_value;
1952 } else if (sdvo_connector->vpos_property == property) {
1953 if (sdvo_connector->cur_vpos == temp_value)
1954 goto out;
1955
1956 cmd = SDVO_CMD_SET_POSITION_V;
1957 sdvo_connector->cur_vpos = temp_value;
1958 } else if (sdvo_connector->saturation_property == property) {
1959 if (sdvo_connector->cur_saturation == temp_value)
1960 goto out;
1961
1962 cmd = SDVO_CMD_SET_SATURATION;
1963 sdvo_connector->cur_saturation = temp_value;
1964 } else if (sdvo_connector->contrast_property == property) {
1965 if (sdvo_connector->cur_contrast == temp_value)
1966 goto out;
1967
1968 cmd = SDVO_CMD_SET_CONTRAST;
1969 sdvo_connector->cur_contrast = temp_value;
1970 } else if (sdvo_connector->hue_property == property) {
1971 if (sdvo_connector->cur_hue == temp_value)
1972 goto out;
1973
1974 cmd = SDVO_CMD_SET_HUE;
1975 sdvo_connector->cur_hue = temp_value;
1976 } else if (sdvo_connector->brightness_property == property) {
1977 if (sdvo_connector->cur_brightness == temp_value)
1978 goto out;
1979
1980 cmd = SDVO_CMD_SET_BRIGHTNESS;
1981 sdvo_connector->cur_brightness = temp_value;
1982 }
1983 if (cmd) {
1984 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
1985 status = intel_sdvo_read_response(intel_encoder,
1986 NULL, 0);
1987 if (status != SDVO_CMD_STATUS_SUCCESS) {
1988 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1989 return -EINVAL;
1990 }
1991 changed = true;
1992 } 1857 }
1858 CHECK_PROPERTY(hpos, HPOS)
1859 CHECK_PROPERTY(vpos, VPOS)
1860 CHECK_PROPERTY(saturation, SATURATION)
1861 CHECK_PROPERTY(contrast, CONTRAST)
1862 CHECK_PROPERTY(hue, HUE)
1863 CHECK_PROPERTY(brightness, BRIGHTNESS)
1864 CHECK_PROPERTY(sharpness, SHARPNESS)
1865 CHECK_PROPERTY(flicker_filter, FLICKER_FILTER)
1866 CHECK_PROPERTY(flicker_filter_2d, FLICKER_FILTER_2D)
1867 CHECK_PROPERTY(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE)
1868 CHECK_PROPERTY(tv_chroma_filter, TV_CHROMA_FILTER)
1869 CHECK_PROPERTY(tv_luma_filter, TV_LUMA_FILTER)
1870 CHECK_PROPERTY(dot_crawl, DOT_CRAWL)
1993 } 1871 }
1994 if (changed && crtc) 1872
1873 return -EINVAL; /* unknown property */
1874
1875set_value:
1876 if (!intel_sdvo_set_value(intel_sdvo, cmd, &temp_value, 2))
1877 return -EIO;
1878
1879
1880done:
1881 if (encoder->crtc) {
1882 struct drm_crtc *crtc = encoder->crtc;
1883
1995 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, 1884 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1996 crtc->y, crtc->fb); 1885 crtc->y, crtc->fb);
1997out: 1886 }
1998 return ret; 1887
1888 return 0;
1889#undef CHECK_PROPERTY
1999} 1890}
2000 1891
2001static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = { 1892static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
@@ -2022,28 +1913,57 @@ static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs
2022 1913
2023static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) 1914static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2024{ 1915{
2025 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 1916 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
2026 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2027 1917
2028 if (intel_encoder->i2c_bus) 1918 if (intel_sdvo->analog_ddc_bus)
2029 intel_i2c_destroy(intel_encoder->i2c_bus); 1919 intel_i2c_destroy(intel_sdvo->analog_ddc_bus);
2030 if (intel_encoder->ddc_bus)
2031 intel_i2c_destroy(intel_encoder->ddc_bus);
2032 if (sdvo_priv->analog_ddc_bus)
2033 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
2034 1920
2035 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL) 1921 if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
2036 drm_mode_destroy(encoder->dev, 1922 drm_mode_destroy(encoder->dev,
2037 sdvo_priv->sdvo_lvds_fixed_mode); 1923 intel_sdvo->sdvo_lvds_fixed_mode);
2038 1924
2039 drm_encoder_cleanup(encoder); 1925 intel_encoder_destroy(encoder);
2040 kfree(intel_encoder);
2041} 1926}
2042 1927
2043static const struct drm_encoder_funcs intel_sdvo_enc_funcs = { 1928static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2044 .destroy = intel_sdvo_enc_destroy, 1929 .destroy = intel_sdvo_enc_destroy,
2045}; 1930};
2046 1931
1932static void
1933intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
1934{
1935 uint16_t mask = 0;
1936 unsigned int num_bits;
1937
1938 /* Make a mask of outputs less than or equal to our own priority in the
1939 * list.
1940 */
1941 switch (sdvo->controlled_output) {
1942 case SDVO_OUTPUT_LVDS1:
1943 mask |= SDVO_OUTPUT_LVDS1;
1944 case SDVO_OUTPUT_LVDS0:
1945 mask |= SDVO_OUTPUT_LVDS0;
1946 case SDVO_OUTPUT_TMDS1:
1947 mask |= SDVO_OUTPUT_TMDS1;
1948 case SDVO_OUTPUT_TMDS0:
1949 mask |= SDVO_OUTPUT_TMDS0;
1950 case SDVO_OUTPUT_RGB1:
1951 mask |= SDVO_OUTPUT_RGB1;
1952 case SDVO_OUTPUT_RGB0:
1953 mask |= SDVO_OUTPUT_RGB0;
1954 break;
1955 }
1956
1957 /* Count bits to find what number we are in the priority list. */
1958 mask &= sdvo->caps.output_flags;
1959 num_bits = hweight16(mask);
1960 /* If more than 3 outputs, default to DDC bus 3 for now. */
1961 if (num_bits > 3)
1962 num_bits = 3;
1963
1964 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
1965 sdvo->ddc_bus = 1 << num_bits;
1966}
2047 1967
2048/** 1968/**
2049 * Choose the appropriate DDC bus for control bus switch command for this 1969 * Choose the appropriate DDC bus for control bus switch command for this
@@ -2054,7 +1974,7 @@ static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2054 */ 1974 */
2055static void 1975static void
2056intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv, 1976intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
2057 struct intel_sdvo_priv *sdvo, u32 reg) 1977 struct intel_sdvo *sdvo, u32 reg)
2058{ 1978{
2059 struct sdvo_device_mapping *mapping; 1979 struct sdvo_device_mapping *mapping;
2060 1980
@@ -2063,61 +1983,53 @@ intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
2063 else 1983 else
2064 mapping = &(dev_priv->sdvo_mappings[1]); 1984 mapping = &(dev_priv->sdvo_mappings[1]);
2065 1985
2066 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4); 1986 if (mapping->initialized)
1987 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
1988 else
1989 intel_sdvo_guess_ddc_bus(sdvo);
2067} 1990}
2068 1991
2069static bool 1992static bool
2070intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device) 1993intel_sdvo_get_digital_encoding_mode(struct intel_sdvo *intel_sdvo, int device)
2071{ 1994{
2072 struct intel_sdvo_priv *sdvo_priv = output->dev_priv; 1995 return intel_sdvo_set_target_output(intel_sdvo,
2073 uint8_t status; 1996 device == 0 ? SDVO_OUTPUT_TMDS0 : SDVO_OUTPUT_TMDS1) &&
2074 1997 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE,
2075 if (device == 0) 1998 &intel_sdvo->is_hdmi, 1);
2076 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0);
2077 else
2078 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1);
2079
2080 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2081 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
2082 if (status != SDVO_CMD_STATUS_SUCCESS)
2083 return false;
2084 return true;
2085} 1999}
2086 2000
2087static struct intel_encoder * 2001static struct intel_sdvo *
2088intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan) 2002intel_sdvo_chan_to_intel_sdvo(struct intel_i2c_chan *chan)
2089{ 2003{
2090 struct drm_device *dev = chan->drm_dev; 2004 struct drm_device *dev = chan->drm_dev;
2091 struct drm_encoder *encoder; 2005 struct drm_encoder *encoder;
2092 struct intel_encoder *intel_encoder = NULL;
2093 2006
2094 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 2007 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2095 intel_encoder = enc_to_intel_encoder(encoder); 2008 struct intel_sdvo *intel_sdvo = enc_to_intel_sdvo(encoder);
2096 if (intel_encoder->ddc_bus == &chan->adapter) 2009 if (intel_sdvo->base.ddc_bus == &chan->adapter)
2097 break; 2010 return intel_sdvo;
2098 } 2011 }
2099 return intel_encoder; 2012
2013 return NULL;
2100} 2014}
2101 2015
2102static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, 2016static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2103 struct i2c_msg msgs[], int num) 2017 struct i2c_msg msgs[], int num)
2104{ 2018{
2105 struct intel_encoder *intel_encoder; 2019 struct intel_sdvo *intel_sdvo;
2106 struct intel_sdvo_priv *sdvo_priv;
2107 struct i2c_algo_bit_data *algo_data; 2020 struct i2c_algo_bit_data *algo_data;
2108 const struct i2c_algorithm *algo; 2021 const struct i2c_algorithm *algo;
2109 2022
2110 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; 2023 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
2111 intel_encoder = 2024 intel_sdvo =
2112 intel_sdvo_chan_to_intel_encoder( 2025 intel_sdvo_chan_to_intel_sdvo((struct intel_i2c_chan *)
2113 (struct intel_i2c_chan *)(algo_data->data)); 2026 (algo_data->data));
2114 if (intel_encoder == NULL) 2027 if (intel_sdvo == NULL)
2115 return -EINVAL; 2028 return -EINVAL;
2116 2029
2117 sdvo_priv = intel_encoder->dev_priv; 2030 algo = intel_sdvo->base.i2c_bus->algo;
2118 algo = intel_encoder->i2c_bus->algo;
2119 2031
2120 intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus); 2032 intel_sdvo_set_control_bus_switch(intel_sdvo, intel_sdvo->ddc_bus);
2121 return algo->master_xfer(i2c_adap, msgs, num); 2033 return algo->master_xfer(i2c_adap, msgs, num);
2122} 2034}
2123 2035
@@ -2162,27 +2074,9 @@ intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
2162 return 0x72; 2074 return 0x72;
2163} 2075}
2164 2076
2165static bool
2166intel_sdvo_connector_alloc (struct intel_connector **ret)
2167{
2168 struct intel_connector *intel_connector;
2169 struct intel_sdvo_connector *sdvo_connector;
2170
2171 *ret = kzalloc(sizeof(*intel_connector) +
2172 sizeof(*sdvo_connector), GFP_KERNEL);
2173 if (!*ret)
2174 return false;
2175
2176 intel_connector = *ret;
2177 sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1);
2178 intel_connector->dev_priv = sdvo_connector;
2179
2180 return true;
2181}
2182
2183static void 2077static void
2184intel_sdvo_connector_create (struct drm_encoder *encoder, 2078intel_sdvo_connector_init(struct drm_encoder *encoder,
2185 struct drm_connector *connector) 2079 struct drm_connector *connector)
2186{ 2080{
2187 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs, 2081 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs,
2188 connector->connector_type); 2082 connector->connector_type);
@@ -2198,582 +2092,470 @@ intel_sdvo_connector_create (struct drm_encoder *encoder,
2198} 2092}
2199 2093
2200static bool 2094static bool
2201intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device) 2095intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2202{ 2096{
2203 struct drm_encoder *encoder = &intel_encoder->enc; 2097 struct drm_encoder *encoder = &intel_sdvo->base.enc;
2204 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2205 struct drm_connector *connector; 2098 struct drm_connector *connector;
2206 struct intel_connector *intel_connector; 2099 struct intel_connector *intel_connector;
2207 struct intel_sdvo_connector *sdvo_connector; 2100 struct intel_sdvo_connector *intel_sdvo_connector;
2208 2101
2209 if (!intel_sdvo_connector_alloc(&intel_connector)) 2102 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2103 if (!intel_sdvo_connector)
2210 return false; 2104 return false;
2211 2105
2212 sdvo_connector = intel_connector->dev_priv;
2213
2214 if (device == 0) { 2106 if (device == 0) {
2215 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0; 2107 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
2216 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0; 2108 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2217 } else if (device == 1) { 2109 } else if (device == 1) {
2218 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1; 2110 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
2219 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1; 2111 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2220 } 2112 }
2221 2113
2114 intel_connector = &intel_sdvo_connector->base;
2222 connector = &intel_connector->base; 2115 connector = &intel_connector->base;
2223 connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; 2116 connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2224 encoder->encoder_type = DRM_MODE_ENCODER_TMDS; 2117 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2225 connector->connector_type = DRM_MODE_CONNECTOR_DVID; 2118 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2226 2119
2227 if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode) 2120 if (intel_sdvo_get_supp_encode(intel_sdvo, &intel_sdvo->encode)
2228 && intel_sdvo_get_digital_encoding_mode(intel_encoder, device) 2121 && intel_sdvo_get_digital_encoding_mode(intel_sdvo, device)
2229 && sdvo_priv->is_hdmi) { 2122 && intel_sdvo->is_hdmi) {
2230 /* enable hdmi encoding mode if supported */ 2123 /* enable hdmi encoding mode if supported */
2231 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI); 2124 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
2232 intel_sdvo_set_colorimetry(intel_encoder, 2125 intel_sdvo_set_colorimetry(intel_sdvo,
2233 SDVO_COLORIMETRY_RGB256); 2126 SDVO_COLORIMETRY_RGB256);
2234 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; 2127 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2235 } 2128 }
2236 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | 2129 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2237 (1 << INTEL_ANALOG_CLONE_BIT); 2130 (1 << INTEL_ANALOG_CLONE_BIT));
2238 2131
2239 intel_sdvo_connector_create(encoder, connector); 2132 intel_sdvo_connector_init(encoder, connector);
2240 2133
2241 return true; 2134 return true;
2242} 2135}
2243 2136
2244static bool 2137static bool
2245intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type) 2138intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
2246{ 2139{
2247 struct drm_encoder *encoder = &intel_encoder->enc; 2140 struct drm_encoder *encoder = &intel_sdvo->base.enc;
2248 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2249 struct drm_connector *connector; 2141 struct drm_connector *connector;
2250 struct intel_connector *intel_connector; 2142 struct intel_connector *intel_connector;
2251 struct intel_sdvo_connector *sdvo_connector; 2143 struct intel_sdvo_connector *intel_sdvo_connector;
2252 2144
2253 if (!intel_sdvo_connector_alloc(&intel_connector)) 2145 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2254 return false; 2146 if (!intel_sdvo_connector)
2147 return false;
2255 2148
2149 intel_connector = &intel_sdvo_connector->base;
2256 connector = &intel_connector->base; 2150 connector = &intel_connector->base;
2257 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; 2151 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2258 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; 2152 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2259 sdvo_connector = intel_connector->dev_priv;
2260 2153
2261 sdvo_priv->controlled_output |= type; 2154 intel_sdvo->controlled_output |= type;
2262 sdvo_connector->output_flag = type; 2155 intel_sdvo_connector->output_flag = type;
2263 2156
2264 sdvo_priv->is_tv = true; 2157 intel_sdvo->is_tv = true;
2265 intel_encoder->needs_tv_clock = true; 2158 intel_sdvo->base.needs_tv_clock = true;
2266 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; 2159 intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
2267 2160
2268 intel_sdvo_connector_create(encoder, connector); 2161 intel_sdvo_connector_init(encoder, connector);
2269 2162
2270 intel_sdvo_tv_create_property(connector, type); 2163 if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
2164 goto err;
2271 2165
2272 intel_sdvo_create_enhance_property(connector); 2166 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2167 goto err;
2273 2168
2274 return true; 2169 return true;
2170
2171err:
2172 intel_sdvo_destroy_enhance_property(connector);
2173 kfree(intel_sdvo_connector);
2174 return false;
2275} 2175}
2276 2176
2277static bool 2177static bool
2278intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device) 2178intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
2279{ 2179{
2280 struct drm_encoder *encoder = &intel_encoder->enc; 2180 struct drm_encoder *encoder = &intel_sdvo->base.enc;
2281 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2282 struct drm_connector *connector; 2181 struct drm_connector *connector;
2283 struct intel_connector *intel_connector; 2182 struct intel_connector *intel_connector;
2284 struct intel_sdvo_connector *sdvo_connector; 2183 struct intel_sdvo_connector *intel_sdvo_connector;
2285 2184
2286 if (!intel_sdvo_connector_alloc(&intel_connector)) 2185 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2287 return false; 2186 if (!intel_sdvo_connector)
2187 return false;
2288 2188
2189 intel_connector = &intel_sdvo_connector->base;
2289 connector = &intel_connector->base; 2190 connector = &intel_connector->base;
2290 connector->polled = DRM_CONNECTOR_POLL_CONNECT; 2191 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2291 encoder->encoder_type = DRM_MODE_ENCODER_DAC; 2192 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2292 connector->connector_type = DRM_MODE_CONNECTOR_VGA; 2193 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2293 sdvo_connector = intel_connector->dev_priv;
2294 2194
2295 if (device == 0) { 2195 if (device == 0) {
2296 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0; 2196 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
2297 sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; 2197 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2298 } else if (device == 1) { 2198 } else if (device == 1) {
2299 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1; 2199 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
2300 sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; 2200 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2301 } 2201 }
2302 2202
2303 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | 2203 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2304 (1 << INTEL_ANALOG_CLONE_BIT); 2204 (1 << INTEL_ANALOG_CLONE_BIT));
2305 2205
2306 intel_sdvo_connector_create(encoder, connector); 2206 intel_sdvo_connector_init(encoder, connector);
2307 return true; 2207 return true;
2308} 2208}
2309 2209
2310static bool 2210static bool
2311intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device) 2211intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
2312{ 2212{
2313 struct drm_encoder *encoder = &intel_encoder->enc; 2213 struct drm_encoder *encoder = &intel_sdvo->base.enc;
2314 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2315 struct drm_connector *connector; 2214 struct drm_connector *connector;
2316 struct intel_connector *intel_connector; 2215 struct intel_connector *intel_connector;
2317 struct intel_sdvo_connector *sdvo_connector; 2216 struct intel_sdvo_connector *intel_sdvo_connector;
2318 2217
2319 if (!intel_sdvo_connector_alloc(&intel_connector)) 2218 intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
2320 return false; 2219 if (!intel_sdvo_connector)
2220 return false;
2321 2221
2322 connector = &intel_connector->base; 2222 intel_connector = &intel_sdvo_connector->base;
2223 connector = &intel_connector->base;
2323 encoder->encoder_type = DRM_MODE_ENCODER_LVDS; 2224 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2324 connector->connector_type = DRM_MODE_CONNECTOR_LVDS; 2225 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2325 sdvo_connector = intel_connector->dev_priv;
2326
2327 sdvo_priv->is_lvds = true;
2328 2226
2329 if (device == 0) { 2227 if (device == 0) {
2330 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0; 2228 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
2331 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; 2229 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2332 } else if (device == 1) { 2230 } else if (device == 1) {
2333 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1; 2231 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
2334 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; 2232 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2335 } 2233 }
2336 2234
2337 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | 2235 intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) |
2338 (1 << INTEL_SDVO_LVDS_CLONE_BIT); 2236 (1 << INTEL_SDVO_LVDS_CLONE_BIT));
2339 2237
2340 intel_sdvo_connector_create(encoder, connector); 2238 intel_sdvo_connector_init(encoder, connector);
2341 intel_sdvo_create_enhance_property(connector); 2239 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2342 return true; 2240 goto err;
2241
2242 return true;
2243
2244err:
2245 intel_sdvo_destroy_enhance_property(connector);
2246 kfree(intel_sdvo_connector);
2247 return false;
2343} 2248}
2344 2249
2345static bool 2250static bool
2346intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags) 2251intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
2347{ 2252{
2348 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; 2253 intel_sdvo->is_tv = false;
2349 2254 intel_sdvo->base.needs_tv_clock = false;
2350 sdvo_priv->is_tv = false; 2255 intel_sdvo->is_lvds = false;
2351 intel_encoder->needs_tv_clock = false;
2352 sdvo_priv->is_lvds = false;
2353 2256
2354 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/ 2257 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2355 2258
2356 if (flags & SDVO_OUTPUT_TMDS0) 2259 if (flags & SDVO_OUTPUT_TMDS0)
2357 if (!intel_sdvo_dvi_init(intel_encoder, 0)) 2260 if (!intel_sdvo_dvi_init(intel_sdvo, 0))
2358 return false; 2261 return false;
2359 2262
2360 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK) 2263 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2361 if (!intel_sdvo_dvi_init(intel_encoder, 1)) 2264 if (!intel_sdvo_dvi_init(intel_sdvo, 1))
2362 return false; 2265 return false;
2363 2266
2364 /* TV has no XXX1 function block */ 2267 /* TV has no XXX1 function block */
2365 if (flags & SDVO_OUTPUT_SVID0) 2268 if (flags & SDVO_OUTPUT_SVID0)
2366 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0)) 2269 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
2367 return false; 2270 return false;
2368 2271
2369 if (flags & SDVO_OUTPUT_CVBS0) 2272 if (flags & SDVO_OUTPUT_CVBS0)
2370 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0)) 2273 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
2371 return false; 2274 return false;
2372 2275
2373 if (flags & SDVO_OUTPUT_RGB0) 2276 if (flags & SDVO_OUTPUT_RGB0)
2374 if (!intel_sdvo_analog_init(intel_encoder, 0)) 2277 if (!intel_sdvo_analog_init(intel_sdvo, 0))
2375 return false; 2278 return false;
2376 2279
2377 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK) 2280 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2378 if (!intel_sdvo_analog_init(intel_encoder, 1)) 2281 if (!intel_sdvo_analog_init(intel_sdvo, 1))
2379 return false; 2282 return false;
2380 2283
2381 if (flags & SDVO_OUTPUT_LVDS0) 2284 if (flags & SDVO_OUTPUT_LVDS0)
2382 if (!intel_sdvo_lvds_init(intel_encoder, 0)) 2285 if (!intel_sdvo_lvds_init(intel_sdvo, 0))
2383 return false; 2286 return false;
2384 2287
2385 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK) 2288 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2386 if (!intel_sdvo_lvds_init(intel_encoder, 1)) 2289 if (!intel_sdvo_lvds_init(intel_sdvo, 1))
2387 return false; 2290 return false;
2388 2291
2389 if ((flags & SDVO_OUTPUT_MASK) == 0) { 2292 if ((flags & SDVO_OUTPUT_MASK) == 0) {
2390 unsigned char bytes[2]; 2293 unsigned char bytes[2];
2391 2294
2392 sdvo_priv->controlled_output = 0; 2295 intel_sdvo->controlled_output = 0;
2393 memcpy(bytes, &sdvo_priv->caps.output_flags, 2); 2296 memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
2394 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n", 2297 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2395 SDVO_NAME(sdvo_priv), 2298 SDVO_NAME(intel_sdvo),
2396 bytes[0], bytes[1]); 2299 bytes[0], bytes[1]);
2397 return false; 2300 return false;
2398 } 2301 }
2399 intel_encoder->crtc_mask = (1 << 0) | (1 << 1); 2302 intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1);
2400 2303
2401 return true; 2304 return true;
2402} 2305}
2403 2306
2404static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type) 2307static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
2308 struct intel_sdvo_connector *intel_sdvo_connector,
2309 int type)
2405{ 2310{
2406 struct drm_encoder *encoder = intel_attached_encoder(connector); 2311 struct drm_device *dev = intel_sdvo->base.enc.dev;
2407 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
2408 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2409 struct intel_connector *intel_connector = to_intel_connector(connector);
2410 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
2411 struct intel_sdvo_tv_format format; 2312 struct intel_sdvo_tv_format format;
2412 uint32_t format_map, i; 2313 uint32_t format_map, i;
2413 uint8_t status;
2414 2314
2415 intel_sdvo_set_target_output(intel_encoder, type); 2315 if (!intel_sdvo_set_target_output(intel_sdvo, type))
2316 return false;
2416 2317
2417 intel_sdvo_write_cmd(intel_encoder, 2318 if (!intel_sdvo_get_value(intel_sdvo,
2418 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0); 2319 SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
2419 status = intel_sdvo_read_response(intel_encoder, 2320 &format, sizeof(format)))
2420 &format, sizeof(format)); 2321 return false;
2421 if (status != SDVO_CMD_STATUS_SUCCESS)
2422 return;
2423 2322
2424 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ? 2323 memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
2425 sizeof(format_map) : sizeof(format));
2426 2324
2427 if (format_map == 0) 2325 if (format_map == 0)
2428 return; 2326 return false;
2429 2327
2430 sdvo_connector->format_supported_num = 0; 2328 intel_sdvo_connector->format_supported_num = 0;
2431 for (i = 0 ; i < TV_FORMAT_NUM; i++) 2329 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2432 if (format_map & (1 << i)) { 2330 if (format_map & (1 << i))
2433 sdvo_connector->tv_format_supported 2331 intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
2434 [sdvo_connector->format_supported_num++] =
2435 tv_format_names[i];
2436 }
2437 2332
2438 2333
2439 sdvo_connector->tv_format_property = 2334 intel_sdvo_connector->tv_format =
2440 drm_property_create( 2335 drm_property_create(dev, DRM_MODE_PROP_ENUM,
2441 connector->dev, DRM_MODE_PROP_ENUM, 2336 "mode", intel_sdvo_connector->format_supported_num);
2442 "mode", sdvo_connector->format_supported_num); 2337 if (!intel_sdvo_connector->tv_format)
2338 return false;
2443 2339
2444 for (i = 0; i < sdvo_connector->format_supported_num; i++) 2340 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2445 drm_property_add_enum( 2341 drm_property_add_enum(
2446 sdvo_connector->tv_format_property, i, 2342 intel_sdvo_connector->tv_format, i,
2447 i, sdvo_connector->tv_format_supported[i]); 2343 i, tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
2448 2344
2449 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0]; 2345 intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[0];
2450 drm_connector_attach_property( 2346 drm_connector_attach_property(&intel_sdvo_connector->base.base,
2451 connector, sdvo_connector->tv_format_property, 0); 2347 intel_sdvo_connector->tv_format, 0);
2348 return true;
2452 2349
2453} 2350}
2454 2351
2455static void intel_sdvo_create_enhance_property(struct drm_connector *connector) 2352#define ENHANCEMENT(name, NAME) do { \
2353 if (enhancements.name) { \
2354 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
2355 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
2356 return false; \
2357 intel_sdvo_connector->max_##name = data_value[0]; \
2358 intel_sdvo_connector->cur_##name = response; \
2359 intel_sdvo_connector->name = \
2360 drm_property_create(dev, DRM_MODE_PROP_RANGE, #name, 2); \
2361 if (!intel_sdvo_connector->name) return false; \
2362 intel_sdvo_connector->name->values[0] = 0; \
2363 intel_sdvo_connector->name->values[1] = data_value[0]; \
2364 drm_connector_attach_property(connector, \
2365 intel_sdvo_connector->name, \
2366 intel_sdvo_connector->cur_##name); \
2367 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
2368 data_value[0], data_value[1], response); \
2369 } \
2370} while(0)
2371
2372static bool
2373intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
2374 struct intel_sdvo_connector *intel_sdvo_connector,
2375 struct intel_sdvo_enhancements_reply enhancements)
2456{ 2376{
2457 struct drm_encoder *encoder = intel_attached_encoder(connector); 2377 struct drm_device *dev = intel_sdvo->base.enc.dev;
2458 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); 2378 struct drm_connector *connector = &intel_sdvo_connector->base.base;
2459 struct intel_connector *intel_connector = to_intel_connector(connector);
2460 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
2461 struct intel_sdvo_enhancements_reply sdvo_data;
2462 struct drm_device *dev = connector->dev;
2463 uint8_t status;
2464 uint16_t response, data_value[2]; 2379 uint16_t response, data_value[2];
2465 2380
2466 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, 2381 /* when horizontal overscan is supported, Add the left/right property */
2467 NULL, 0); 2382 if (enhancements.overscan_h) {
2468 status = intel_sdvo_read_response(intel_encoder, &sdvo_data, 2383 if (!intel_sdvo_get_value(intel_sdvo,
2469 sizeof(sdvo_data)); 2384 SDVO_CMD_GET_MAX_OVERSCAN_H,
2470 if (status != SDVO_CMD_STATUS_SUCCESS) { 2385 &data_value, 4))
2471 DRM_DEBUG_KMS(" incorrect response is returned\n"); 2386 return false;
2472 return; 2387
2388 if (!intel_sdvo_get_value(intel_sdvo,
2389 SDVO_CMD_GET_OVERSCAN_H,
2390 &response, 2))
2391 return false;
2392
2393 intel_sdvo_connector->max_hscan = data_value[0];
2394 intel_sdvo_connector->left_margin = data_value[0] - response;
2395 intel_sdvo_connector->right_margin = intel_sdvo_connector->left_margin;
2396 intel_sdvo_connector->left =
2397 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2398 "left_margin", 2);
2399 if (!intel_sdvo_connector->left)
2400 return false;
2401
2402 intel_sdvo_connector->left->values[0] = 0;
2403 intel_sdvo_connector->left->values[1] = data_value[0];
2404 drm_connector_attach_property(connector,
2405 intel_sdvo_connector->left,
2406 intel_sdvo_connector->left_margin);
2407
2408 intel_sdvo_connector->right =
2409 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2410 "right_margin", 2);
2411 if (!intel_sdvo_connector->right)
2412 return false;
2413
2414 intel_sdvo_connector->right->values[0] = 0;
2415 intel_sdvo_connector->right->values[1] = data_value[0];
2416 drm_connector_attach_property(connector,
2417 intel_sdvo_connector->right,
2418 intel_sdvo_connector->right_margin);
2419 DRM_DEBUG_KMS("h_overscan: max %d, "
2420 "default %d, current %d\n",
2421 data_value[0], data_value[1], response);
2473 } 2422 }
2474 response = *((uint16_t *)&sdvo_data); 2423
2475 if (!response) { 2424 if (enhancements.overscan_v) {
2476 DRM_DEBUG_KMS("No enhancement is supported\n"); 2425 if (!intel_sdvo_get_value(intel_sdvo,
2477 return; 2426 SDVO_CMD_GET_MAX_OVERSCAN_V,
2427 &data_value, 4))
2428 return false;
2429
2430 if (!intel_sdvo_get_value(intel_sdvo,
2431 SDVO_CMD_GET_OVERSCAN_V,
2432 &response, 2))
2433 return false;
2434
2435 intel_sdvo_connector->max_vscan = data_value[0];
2436 intel_sdvo_connector->top_margin = data_value[0] - response;
2437 intel_sdvo_connector->bottom_margin = intel_sdvo_connector->top_margin;
2438 intel_sdvo_connector->top =
2439 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2440 "top_margin", 2);
2441 if (!intel_sdvo_connector->top)
2442 return false;
2443
2444 intel_sdvo_connector->top->values[0] = 0;
2445 intel_sdvo_connector->top->values[1] = data_value[0];
2446 drm_connector_attach_property(connector,
2447 intel_sdvo_connector->top,
2448 intel_sdvo_connector->top_margin);
2449
2450 intel_sdvo_connector->bottom =
2451 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2452 "bottom_margin", 2);
2453 if (!intel_sdvo_connector->bottom)
2454 return false;
2455
2456 intel_sdvo_connector->bottom->values[0] = 0;
2457 intel_sdvo_connector->bottom->values[1] = data_value[0];
2458 drm_connector_attach_property(connector,
2459 intel_sdvo_connector->bottom,
2460 intel_sdvo_connector->bottom_margin);
2461 DRM_DEBUG_KMS("v_overscan: max %d, "
2462 "default %d, current %d\n",
2463 data_value[0], data_value[1], response);
2478 } 2464 }
2479 if (IS_TV(sdvo_priv)) { 2465
2480 /* when horizontal overscan is supported, Add the left/right 2466 ENHANCEMENT(hpos, HPOS);
2481 * property 2467 ENHANCEMENT(vpos, VPOS);
2482 */ 2468 ENHANCEMENT(saturation, SATURATION);
2483 if (sdvo_data.overscan_h) { 2469 ENHANCEMENT(contrast, CONTRAST);
2484 intel_sdvo_write_cmd(intel_encoder, 2470 ENHANCEMENT(hue, HUE);
2485 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0); 2471 ENHANCEMENT(sharpness, SHARPNESS);
2486 status = intel_sdvo_read_response(intel_encoder, 2472 ENHANCEMENT(brightness, BRIGHTNESS);
2487 &data_value, 4); 2473 ENHANCEMENT(flicker_filter, FLICKER_FILTER);
2488 if (status != SDVO_CMD_STATUS_SUCCESS) { 2474 ENHANCEMENT(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
2489 DRM_DEBUG_KMS("Incorrect SDVO max " 2475 ENHANCEMENT(flicker_filter_2d, FLICKER_FILTER_2D);
2490 "h_overscan\n"); 2476 ENHANCEMENT(tv_chroma_filter, TV_CHROMA_FILTER);
2491 return; 2477 ENHANCEMENT(tv_luma_filter, TV_LUMA_FILTER);
2492 } 2478
2493 intel_sdvo_write_cmd(intel_encoder, 2479 if (enhancements.dot_crawl) {
2494 SDVO_CMD_GET_OVERSCAN_H, NULL, 0); 2480 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
2495 status = intel_sdvo_read_response(intel_encoder, 2481 return false;
2496 &response, 2); 2482
2497 if (status != SDVO_CMD_STATUS_SUCCESS) { 2483 intel_sdvo_connector->max_dot_crawl = 1;
2498 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n"); 2484 intel_sdvo_connector->cur_dot_crawl = response & 0x1;
2499 return; 2485 intel_sdvo_connector->dot_crawl =
2500 } 2486 drm_property_create(dev, DRM_MODE_PROP_RANGE, "dot_crawl", 2);
2501 sdvo_priv->max_hscan = data_value[0]; 2487 if (!intel_sdvo_connector->dot_crawl)
2502 sdvo_priv->left_margin = data_value[0] - response; 2488 return false;
2503 sdvo_priv->right_margin = sdvo_priv->left_margin; 2489
2504 sdvo_priv->left_property = 2490 intel_sdvo_connector->dot_crawl->values[0] = 0;
2505 drm_property_create(dev, DRM_MODE_PROP_RANGE, 2491 intel_sdvo_connector->dot_crawl->values[1] = 1;
2506 "left_margin", 2); 2492 drm_connector_attach_property(connector,
2507 sdvo_priv->left_property->values[0] = 0; 2493 intel_sdvo_connector->dot_crawl,
2508 sdvo_priv->left_property->values[1] = data_value[0]; 2494 intel_sdvo_connector->cur_dot_crawl);
2509 drm_connector_attach_property(connector, 2495 DRM_DEBUG_KMS("dot crawl: current %d\n", response);
2510 sdvo_priv->left_property,
2511 sdvo_priv->left_margin);
2512 sdvo_priv->right_property =
2513 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2514 "right_margin", 2);
2515 sdvo_priv->right_property->values[0] = 0;
2516 sdvo_priv->right_property->values[1] = data_value[0];
2517 drm_connector_attach_property(connector,
2518 sdvo_priv->right_property,
2519 sdvo_priv->right_margin);
2520 DRM_DEBUG_KMS("h_overscan: max %d, "
2521 "default %d, current %d\n",
2522 data_value[0], data_value[1], response);
2523 }
2524 if (sdvo_data.overscan_v) {
2525 intel_sdvo_write_cmd(intel_encoder,
2526 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
2527 status = intel_sdvo_read_response(intel_encoder,
2528 &data_value, 4);
2529 if (status != SDVO_CMD_STATUS_SUCCESS) {
2530 DRM_DEBUG_KMS("Incorrect SDVO max "
2531 "v_overscan\n");
2532 return;
2533 }
2534 intel_sdvo_write_cmd(intel_encoder,
2535 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
2536 status = intel_sdvo_read_response(intel_encoder,
2537 &response, 2);
2538 if (status != SDVO_CMD_STATUS_SUCCESS) {
2539 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2540 return;
2541 }
2542 sdvo_priv->max_vscan = data_value[0];
2543 sdvo_priv->top_margin = data_value[0] - response;
2544 sdvo_priv->bottom_margin = sdvo_priv->top_margin;
2545 sdvo_priv->top_property =
2546 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2547 "top_margin", 2);
2548 sdvo_priv->top_property->values[0] = 0;
2549 sdvo_priv->top_property->values[1] = data_value[0];
2550 drm_connector_attach_property(connector,
2551 sdvo_priv->top_property,
2552 sdvo_priv->top_margin);
2553 sdvo_priv->bottom_property =
2554 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2555 "bottom_margin", 2);
2556 sdvo_priv->bottom_property->values[0] = 0;
2557 sdvo_priv->bottom_property->values[1] = data_value[0];
2558 drm_connector_attach_property(connector,
2559 sdvo_priv->bottom_property,
2560 sdvo_priv->bottom_margin);
2561 DRM_DEBUG_KMS("v_overscan: max %d, "
2562 "default %d, current %d\n",
2563 data_value[0], data_value[1], response);
2564 }
2565 if (sdvo_data.position_h) {
2566 intel_sdvo_write_cmd(intel_encoder,
2567 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
2568 status = intel_sdvo_read_response(intel_encoder,
2569 &data_value, 4);
2570 if (status != SDVO_CMD_STATUS_SUCCESS) {
2571 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2572 return;
2573 }
2574 intel_sdvo_write_cmd(intel_encoder,
2575 SDVO_CMD_GET_POSITION_H, NULL, 0);
2576 status = intel_sdvo_read_response(intel_encoder,
2577 &response, 2);
2578 if (status != SDVO_CMD_STATUS_SUCCESS) {
2579 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2580 return;
2581 }
2582 sdvo_priv->max_hpos = data_value[0];
2583 sdvo_priv->cur_hpos = response;
2584 sdvo_priv->hpos_property =
2585 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2586 "hpos", 2);
2587 sdvo_priv->hpos_property->values[0] = 0;
2588 sdvo_priv->hpos_property->values[1] = data_value[0];
2589 drm_connector_attach_property(connector,
2590 sdvo_priv->hpos_property,
2591 sdvo_priv->cur_hpos);
2592 DRM_DEBUG_KMS("h_position: max %d, "
2593 "default %d, current %d\n",
2594 data_value[0], data_value[1], response);
2595 }
2596 if (sdvo_data.position_v) {
2597 intel_sdvo_write_cmd(intel_encoder,
2598 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
2599 status = intel_sdvo_read_response(intel_encoder,
2600 &data_value, 4);
2601 if (status != SDVO_CMD_STATUS_SUCCESS) {
2602 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2603 return;
2604 }
2605 intel_sdvo_write_cmd(intel_encoder,
2606 SDVO_CMD_GET_POSITION_V, NULL, 0);
2607 status = intel_sdvo_read_response(intel_encoder,
2608 &response, 2);
2609 if (status != SDVO_CMD_STATUS_SUCCESS) {
2610 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2611 return;
2612 }
2613 sdvo_priv->max_vpos = data_value[0];
2614 sdvo_priv->cur_vpos = response;
2615 sdvo_priv->vpos_property =
2616 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2617 "vpos", 2);
2618 sdvo_priv->vpos_property->values[0] = 0;
2619 sdvo_priv->vpos_property->values[1] = data_value[0];
2620 drm_connector_attach_property(connector,
2621 sdvo_priv->vpos_property,
2622 sdvo_priv->cur_vpos);
2623 DRM_DEBUG_KMS("v_position: max %d, "
2624 "default %d, current %d\n",
2625 data_value[0], data_value[1], response);
2626 }
2627 if (sdvo_data.saturation) {
2628 intel_sdvo_write_cmd(intel_encoder,
2629 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
2630 status = intel_sdvo_read_response(intel_encoder,
2631 &data_value, 4);
2632 if (status != SDVO_CMD_STATUS_SUCCESS) {
2633 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2634 return;
2635 }
2636 intel_sdvo_write_cmd(intel_encoder,
2637 SDVO_CMD_GET_SATURATION, NULL, 0);
2638 status = intel_sdvo_read_response(intel_encoder,
2639 &response, 2);
2640 if (status != SDVO_CMD_STATUS_SUCCESS) {
2641 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2642 return;
2643 }
2644 sdvo_priv->max_saturation = data_value[0];
2645 sdvo_priv->cur_saturation = response;
2646 sdvo_priv->saturation_property =
2647 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2648 "saturation", 2);
2649 sdvo_priv->saturation_property->values[0] = 0;
2650 sdvo_priv->saturation_property->values[1] =
2651 data_value[0];
2652 drm_connector_attach_property(connector,
2653 sdvo_priv->saturation_property,
2654 sdvo_priv->cur_saturation);
2655 DRM_DEBUG_KMS("saturation: max %d, "
2656 "default %d, current %d\n",
2657 data_value[0], data_value[1], response);
2658 }
2659 if (sdvo_data.contrast) {
2660 intel_sdvo_write_cmd(intel_encoder,
2661 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
2662 status = intel_sdvo_read_response(intel_encoder,
2663 &data_value, 4);
2664 if (status != SDVO_CMD_STATUS_SUCCESS) {
2665 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2666 return;
2667 }
2668 intel_sdvo_write_cmd(intel_encoder,
2669 SDVO_CMD_GET_CONTRAST, NULL, 0);
2670 status = intel_sdvo_read_response(intel_encoder,
2671 &response, 2);
2672 if (status != SDVO_CMD_STATUS_SUCCESS) {
2673 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2674 return;
2675 }
2676 sdvo_priv->max_contrast = data_value[0];
2677 sdvo_priv->cur_contrast = response;
2678 sdvo_priv->contrast_property =
2679 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2680 "contrast", 2);
2681 sdvo_priv->contrast_property->values[0] = 0;
2682 sdvo_priv->contrast_property->values[1] = data_value[0];
2683 drm_connector_attach_property(connector,
2684 sdvo_priv->contrast_property,
2685 sdvo_priv->cur_contrast);
2686 DRM_DEBUG_KMS("contrast: max %d, "
2687 "default %d, current %d\n",
2688 data_value[0], data_value[1], response);
2689 }
2690 if (sdvo_data.hue) {
2691 intel_sdvo_write_cmd(intel_encoder,
2692 SDVO_CMD_GET_MAX_HUE, NULL, 0);
2693 status = intel_sdvo_read_response(intel_encoder,
2694 &data_value, 4);
2695 if (status != SDVO_CMD_STATUS_SUCCESS) {
2696 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2697 return;
2698 }
2699 intel_sdvo_write_cmd(intel_encoder,
2700 SDVO_CMD_GET_HUE, NULL, 0);
2701 status = intel_sdvo_read_response(intel_encoder,
2702 &response, 2);
2703 if (status != SDVO_CMD_STATUS_SUCCESS) {
2704 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2705 return;
2706 }
2707 sdvo_priv->max_hue = data_value[0];
2708 sdvo_priv->cur_hue = response;
2709 sdvo_priv->hue_property =
2710 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2711 "hue", 2);
2712 sdvo_priv->hue_property->values[0] = 0;
2713 sdvo_priv->hue_property->values[1] =
2714 data_value[0];
2715 drm_connector_attach_property(connector,
2716 sdvo_priv->hue_property,
2717 sdvo_priv->cur_hue);
2718 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2719 data_value[0], data_value[1], response);
2720 }
2721 } 2496 }
2722 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) { 2497
2723 if (sdvo_data.brightness) { 2498 return true;
2724 intel_sdvo_write_cmd(intel_encoder, 2499}
2725 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0); 2500
2726 status = intel_sdvo_read_response(intel_encoder, 2501static bool
2727 &data_value, 4); 2502intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
2728 if (status != SDVO_CMD_STATUS_SUCCESS) { 2503 struct intel_sdvo_connector *intel_sdvo_connector,
2729 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n"); 2504 struct intel_sdvo_enhancements_reply enhancements)
2730 return; 2505{
2731 } 2506 struct drm_device *dev = intel_sdvo->base.enc.dev;
2732 intel_sdvo_write_cmd(intel_encoder, 2507 struct drm_connector *connector = &intel_sdvo_connector->base.base;
2733 SDVO_CMD_GET_BRIGHTNESS, NULL, 0); 2508 uint16_t response, data_value[2];
2734 status = intel_sdvo_read_response(intel_encoder, 2509
2735 &response, 2); 2510 ENHANCEMENT(brightness, BRIGHTNESS);
2736 if (status != SDVO_CMD_STATUS_SUCCESS) { 2511
2737 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n"); 2512 return true;
2738 return; 2513}
2739 } 2514#undef ENHANCEMENT
2740 sdvo_priv->max_brightness = data_value[0]; 2515
2741 sdvo_priv->cur_brightness = response; 2516static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
2742 sdvo_priv->brightness_property = 2517 struct intel_sdvo_connector *intel_sdvo_connector)
2743 drm_property_create(dev, DRM_MODE_PROP_RANGE, 2518{
2744 "brightness", 2); 2519 union {
2745 sdvo_priv->brightness_property->values[0] = 0; 2520 struct intel_sdvo_enhancements_reply reply;
2746 sdvo_priv->brightness_property->values[1] = 2521 uint16_t response;
2747 data_value[0]; 2522 } enhancements;
2748 drm_connector_attach_property(connector, 2523
2749 sdvo_priv->brightness_property, 2524 if (!intel_sdvo_get_value(intel_sdvo,
2750 sdvo_priv->cur_brightness); 2525 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
2751 DRM_DEBUG_KMS("brightness: max %d, " 2526 &enhancements, sizeof(enhancements)))
2752 "default %d, current %d\n", 2527 return false;
2753 data_value[0], data_value[1], response); 2528
2754 } 2529 if (enhancements.response == 0) {
2530 DRM_DEBUG_KMS("No enhancement is supported\n");
2531 return true;
2755 } 2532 }
2756 return; 2533
2534 if (IS_TV(intel_sdvo_connector))
2535 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
2536 else if(IS_LVDS(intel_sdvo_connector))
2537 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
2538 else
2539 return true;
2540
2757} 2541}
2758 2542
2759bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) 2543bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2760{ 2544{
2761 struct drm_i915_private *dev_priv = dev->dev_private; 2545 struct drm_i915_private *dev_priv = dev->dev_private;
2762 struct intel_encoder *intel_encoder; 2546 struct intel_encoder *intel_encoder;
2763 struct intel_sdvo_priv *sdvo_priv; 2547 struct intel_sdvo *intel_sdvo;
2764 u8 ch[0x40]; 2548 u8 ch[0x40];
2765 int i; 2549 int i;
2766 u32 i2c_reg, ddc_reg, analog_ddc_reg; 2550 u32 i2c_reg, ddc_reg, analog_ddc_reg;
2767 2551
2768 intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); 2552 intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
2769 if (!intel_encoder) { 2553 if (!intel_sdvo)
2770 return false; 2554 return false;
2771 }
2772 2555
2773 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1); 2556 intel_sdvo->sdvo_reg = sdvo_reg;
2774 sdvo_priv->sdvo_reg = sdvo_reg;
2775 2557
2776 intel_encoder->dev_priv = sdvo_priv; 2558 intel_encoder = &intel_sdvo->base;
2777 intel_encoder->type = INTEL_OUTPUT_SDVO; 2559 intel_encoder->type = INTEL_OUTPUT_SDVO;
2778 2560
2779 if (HAS_PCH_SPLIT(dev)) { 2561 if (HAS_PCH_SPLIT(dev)) {
@@ -2795,14 +2577,14 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2795 if (!intel_encoder->i2c_bus) 2577 if (!intel_encoder->i2c_bus)
2796 goto err_inteloutput; 2578 goto err_inteloutput;
2797 2579
2798 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg); 2580 intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
2799 2581
2800 /* Save the bit-banging i2c functionality for use by the DDC wrapper */ 2582 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
2801 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality; 2583 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
2802 2584
2803 /* Read the regs to test if we can talk to the device */ 2585 /* Read the regs to test if we can talk to the device */
2804 for (i = 0; i < 0x40; i++) { 2586 for (i = 0; i < 0x40; i++) {
2805 if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) { 2587 if (!intel_sdvo_read_byte(intel_sdvo, i, &ch[i])) {
2806 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", 2588 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
2807 IS_SDVOB(sdvo_reg) ? 'B' : 'C'); 2589 IS_SDVOB(sdvo_reg) ? 'B' : 'C');
2808 goto err_i2c; 2590 goto err_i2c;
@@ -2812,17 +2594,16 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2812 /* setup the DDC bus. */ 2594 /* setup the DDC bus. */
2813 if (IS_SDVOB(sdvo_reg)) { 2595 if (IS_SDVOB(sdvo_reg)) {
2814 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS"); 2596 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS");
2815 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, 2597 intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg,
2816 "SDVOB/VGA DDC BUS"); 2598 "SDVOB/VGA DDC BUS");
2817 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; 2599 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
2818 } else { 2600 } else {
2819 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS"); 2601 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS");
2820 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, 2602 intel_sdvo->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg,
2821 "SDVOC/VGA DDC BUS"); 2603 "SDVOC/VGA DDC BUS");
2822 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; 2604 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
2823 } 2605 }
2824 2606 if (intel_encoder->ddc_bus == NULL || intel_sdvo->analog_ddc_bus == NULL)
2825 if (intel_encoder->ddc_bus == NULL)
2826 goto err_i2c; 2607 goto err_i2c;
2827 2608
2828 /* Wrap with our custom algo which switches to DDC mode */ 2609 /* Wrap with our custom algo which switches to DDC mode */
@@ -2833,53 +2614,56 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
2833 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs); 2614 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2834 2615
2835 /* In default case sdvo lvds is false */ 2616 /* In default case sdvo lvds is false */
2836 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps); 2617 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
2618 goto err_enc;
2837 2619
2838 if (intel_sdvo_output_setup(intel_encoder, 2620 if (intel_sdvo_output_setup(intel_sdvo,
2839 sdvo_priv->caps.output_flags) != true) { 2621 intel_sdvo->caps.output_flags) != true) {
2840 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", 2622 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
2841 IS_SDVOB(sdvo_reg) ? 'B' : 'C'); 2623 IS_SDVOB(sdvo_reg) ? 'B' : 'C');
2842 goto err_i2c; 2624 goto err_enc;
2843 } 2625 }
2844 2626
2845 intel_sdvo_select_ddc_bus(dev_priv, sdvo_priv, sdvo_reg); 2627 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
2846 2628
2847 /* Set the input timing to the screen. Assume always input 0. */ 2629 /* Set the input timing to the screen. Assume always input 0. */
2848 intel_sdvo_set_target_input(intel_encoder, true, false); 2630 if (!intel_sdvo_set_target_input(intel_sdvo))
2849 2631 goto err_enc;
2850 intel_sdvo_get_input_pixel_clock_range(intel_encoder,
2851 &sdvo_priv->pixel_clock_min,
2852 &sdvo_priv->pixel_clock_max);
2853 2632
2633 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
2634 &intel_sdvo->pixel_clock_min,
2635 &intel_sdvo->pixel_clock_max))
2636 goto err_enc;
2854 2637
2855 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " 2638 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
2856 "clock range %dMHz - %dMHz, " 2639 "clock range %dMHz - %dMHz, "
2857 "input 1: %c, input 2: %c, " 2640 "input 1: %c, input 2: %c, "
2858 "output 1: %c, output 2: %c\n", 2641 "output 1: %c, output 2: %c\n",
2859 SDVO_NAME(sdvo_priv), 2642 SDVO_NAME(intel_sdvo),
2860 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id, 2643 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
2861 sdvo_priv->caps.device_rev_id, 2644 intel_sdvo->caps.device_rev_id,
2862 sdvo_priv->pixel_clock_min / 1000, 2645 intel_sdvo->pixel_clock_min / 1000,
2863 sdvo_priv->pixel_clock_max / 1000, 2646 intel_sdvo->pixel_clock_max / 1000,
2864 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N', 2647 (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2865 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N', 2648 (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
2866 /* check currently supported outputs */ 2649 /* check currently supported outputs */
2867 sdvo_priv->caps.output_flags & 2650 intel_sdvo->caps.output_flags &
2868 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N', 2651 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
2869 sdvo_priv->caps.output_flags & 2652 intel_sdvo->caps.output_flags &
2870 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); 2653 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2871
2872 return true; 2654 return true;
2873 2655
2656err_enc:
2657 drm_encoder_cleanup(&intel_encoder->enc);
2874err_i2c: 2658err_i2c:
2875 if (sdvo_priv->analog_ddc_bus != NULL) 2659 if (intel_sdvo->analog_ddc_bus != NULL)
2876 intel_i2c_destroy(sdvo_priv->analog_ddc_bus); 2660 intel_i2c_destroy(intel_sdvo->analog_ddc_bus);
2877 if (intel_encoder->ddc_bus != NULL) 2661 if (intel_encoder->ddc_bus != NULL)
2878 intel_i2c_destroy(intel_encoder->ddc_bus); 2662 intel_i2c_destroy(intel_encoder->ddc_bus);
2879 if (intel_encoder->i2c_bus != NULL) 2663 if (intel_encoder->i2c_bus != NULL)
2880 intel_i2c_destroy(intel_encoder->i2c_bus); 2664 intel_i2c_destroy(intel_encoder->i2c_bus);
2881err_inteloutput: 2665err_inteloutput:
2882 kfree(intel_encoder); 2666 kfree(intel_sdvo);
2883 2667
2884 return false; 2668 return false;
2885} 2669}