2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Eric Anholt <eric@anholt.net>
28 #include <linux/i2c.h>
29 #include <linux/delay.h>
33 #include "intel_drv.h"
37 #include "intel_sdvo_regs.h"
41 static char *tv_format_names
[] = {
42 "NTSC_M" , "NTSC_J" , "NTSC_443",
43 "PAL_B" , "PAL_D" , "PAL_G" ,
44 "PAL_H" , "PAL_I" , "PAL_M" ,
45 "PAL_N" , "PAL_NC" , "PAL_60" ,
46 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
47 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
51 #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
53 struct intel_sdvo_priv
{
56 /* Register for the SDVO device: SDVOB or SDVOC */
59 /* Active outputs controlled by this SDVO output */
60 uint16_t controlled_output
;
63 * Capabilities of the SDVO device returned by
64 * i830_sdvo_get_capabilities()
66 struct intel_sdvo_caps caps
;
68 /* Pixel clock limitations reported by the SDVO device, in kHz */
69 int pixel_clock_min
, pixel_clock_max
;
72 * For multiple function SDVO device,
73 * this is for current attached outputs.
75 uint16_t attached_output
;
78 * This is set if we're going to treat the device as TV-out.
80 * While we have these nice friendly flags for output types that ought
81 * to decide this for us, the S-Video output on our HDMI+S-Video card
82 * shows up as RGB1 (VGA).
86 /* This is for current tv format name */
89 /* This contains all current supported TV format */
90 char *tv_format_supported
[TV_FORMAT_NUM
];
91 int format_supported_num
;
92 struct drm_property
*tv_format_property
;
93 struct drm_property
*tv_format_name_property
[TV_FORMAT_NUM
];
96 * This is set if we treat the device as HDMI, instead of DVI.
101 * This is set if we detect output of sdvo device as LVDS.
106 * This is sdvo flags for input timing.
111 * This is sdvo fixed pannel mode pointer
113 struct drm_display_mode
*sdvo_lvds_fixed_mode
;
116 * Returned SDTV resolutions allowed for the current format, if the
117 * device reported it.
119 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions
;
122 * supported encoding mode, used to determine whether HDMI is
125 struct intel_sdvo_encode encode
;
127 /* DDC bus used by this SDVO output */
130 /* Mac mini hack -- use the same DDC as the analog connector */
131 struct i2c_adapter
*analog_ddc_bus
;
134 u16 save_active_outputs
;
135 struct intel_sdvo_dtd save_input_dtd_1
, save_input_dtd_2
;
136 struct intel_sdvo_dtd save_output_dtd
[16];
138 /* add the property for the SDVO-TV */
139 struct drm_property
*left_property
;
140 struct drm_property
*right_property
;
141 struct drm_property
*top_property
;
142 struct drm_property
*bottom_property
;
143 struct drm_property
*hpos_property
;
144 struct drm_property
*vpos_property
;
146 /* add the property for the SDVO-TV/LVDS */
147 struct drm_property
*brightness_property
;
148 struct drm_property
*contrast_property
;
149 struct drm_property
*saturation_property
;
150 struct drm_property
*hue_property
;
152 /* Add variable to record current setting for the above property */
153 u32 left_margin
, right_margin
, top_margin
, bottom_margin
;
154 /* this is to get the range of margin.*/
155 u32 max_hscan
, max_vscan
;
156 u32 max_hpos
, cur_hpos
;
157 u32 max_vpos
, cur_vpos
;
158 u32 cur_brightness
, max_brightness
;
159 u32 cur_contrast
, max_contrast
;
160 u32 cur_saturation
, max_saturation
;
161 u32 cur_hue
, max_hue
;
165 intel_sdvo_output_setup(struct intel_output
*intel_output
, uint16_t flags
);
168 * Writes the SDVOB or SDVOC with the given value, but always writes both
169 * SDVOB and SDVOC to work around apparent hardware issues (according to
170 * comments in the BIOS).
172 static void intel_sdvo_write_sdvox(struct intel_output
*intel_output
, u32 val
)
174 struct drm_device
*dev
= intel_output
->base
.dev
;
175 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
176 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
177 u32 bval
= val
, cval
= val
;
180 if (sdvo_priv
->output_device
== SDVOB
) {
181 cval
= I915_READ(SDVOC
);
183 bval
= I915_READ(SDVOB
);
186 * Write the registers twice for luck. Sometimes,
187 * writing them only once doesn't appear to 'stick'.
188 * The BIOS does this too. Yay, magic
190 for (i
= 0; i
< 2; i
++)
192 I915_WRITE(SDVOB
, bval
);
194 I915_WRITE(SDVOC
, cval
);
199 static bool intel_sdvo_read_byte(struct intel_output
*intel_output
, u8 addr
,
202 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
207 struct i2c_msg msgs
[] = {
209 .addr
= sdvo_priv
->slave_addr
>> 1,
215 .addr
= sdvo_priv
->slave_addr
>> 1,
225 if ((ret
= i2c_transfer(intel_output
->i2c_bus
, msgs
, 2)) == 2)
231 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret
);
235 static bool intel_sdvo_write_byte(struct intel_output
*intel_output
, int addr
,
238 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
240 struct i2c_msg msgs
[] = {
242 .addr
= sdvo_priv
->slave_addr
>> 1,
252 if (i2c_transfer(intel_output
->i2c_bus
, msgs
, 1) == 1)
259 #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
260 /** Mapping of command numbers to names, for debug output */
261 static const struct _sdvo_cmd_name
{
264 } sdvo_cmd_names
[] = {
265 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET
),
266 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS
),
267 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV
),
268 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS
),
269 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS
),
270 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS
),
271 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP
),
272 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP
),
273 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS
),
274 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT
),
275 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG
),
276 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG
),
277 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE
),
278 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT
),
279 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT
),
280 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1
),
281 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2
),
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1
),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2
),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1
),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2
),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1
),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2
),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE
),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS
),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT
),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT
),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS
),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT
),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT
),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES
),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE
),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE
),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE
),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH
),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT
),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
),
308 /* Add the op code for SDVO enhancements */
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H
),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H
),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H
),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V
),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V
),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V
),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION
),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION
),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION
),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE
),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE
),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE
),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST
),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST
),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST
),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS
),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS
),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS
),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H
),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H
),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H
),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V
),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V
),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V
),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE
),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE
),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE
),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI
),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI
),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP
),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY
),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY
),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER
),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT
),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT
),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX
),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX
),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO
),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT
),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT
),
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE
),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE
),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA
),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA
),
356 #define SDVO_NAME(dev_priv) ((dev_priv)->output_device == SDVOB ? "SDVOB" : "SDVOC")
357 #define SDVO_PRIV(output) ((struct intel_sdvo_priv *) (output)->dev_priv)
360 static void intel_sdvo_debug_write(struct intel_output
*intel_output
, u8 cmd
,
361 void *args
, int args_len
)
363 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
366 DRM_DEBUG_KMS("%s: W: %02X ",
367 SDVO_NAME(sdvo_priv
), cmd
);
368 for (i
= 0; i
< args_len
; i
++)
369 DRM_LOG_KMS("%02X ", ((u8
*)args
)[i
]);
372 for (i
= 0; i
< sizeof(sdvo_cmd_names
) / sizeof(sdvo_cmd_names
[0]); i
++) {
373 if (cmd
== sdvo_cmd_names
[i
].cmd
) {
374 DRM_LOG_KMS("(%s)", sdvo_cmd_names
[i
].name
);
378 if (i
== sizeof(sdvo_cmd_names
)/ sizeof(sdvo_cmd_names
[0]))
379 DRM_LOG_KMS("(%02X)", cmd
);
383 #define intel_sdvo_debug_write(o, c, a, l)
386 static void intel_sdvo_write_cmd(struct intel_output
*intel_output
, u8 cmd
,
387 void *args
, int args_len
)
391 intel_sdvo_debug_write(intel_output
, cmd
, args
, args_len
);
393 for (i
= 0; i
< args_len
; i
++) {
394 intel_sdvo_write_byte(intel_output
, SDVO_I2C_ARG_0
- i
,
398 intel_sdvo_write_byte(intel_output
, SDVO_I2C_OPCODE
, cmd
);
402 static const char *cmd_status_names
[] = {
408 "Target not specified",
409 "Scaling not supported"
412 static void intel_sdvo_debug_response(struct intel_output
*intel_output
,
413 void *response
, int response_len
,
416 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
419 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv
));
420 for (i
= 0; i
< response_len
; i
++)
421 DRM_LOG_KMS("%02X ", ((u8
*)response
)[i
]);
424 if (status
<= SDVO_CMD_STATUS_SCALING_NOT_SUPP
)
425 DRM_LOG_KMS("(%s)", cmd_status_names
[status
]);
427 DRM_LOG_KMS("(??? %d)", status
);
431 #define intel_sdvo_debug_response(o, r, l, s)
434 static u8
intel_sdvo_read_response(struct intel_output
*intel_output
,
435 void *response
, int response_len
)
442 /* Read the command response */
443 for (i
= 0; i
< response_len
; i
++) {
444 intel_sdvo_read_byte(intel_output
,
445 SDVO_I2C_RETURN_0
+ i
,
446 &((u8
*)response
)[i
]);
449 /* read the return status */
450 intel_sdvo_read_byte(intel_output
, SDVO_I2C_CMD_STATUS
,
453 intel_sdvo_debug_response(intel_output
, response
, response_len
,
455 if (status
!= SDVO_CMD_STATUS_PENDING
)
464 static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode
*mode
)
466 if (mode
->clock
>= 100000)
468 else if (mode
->clock
>= 50000)
475 * Don't check status code from this as it switches the bus back to the
476 * SDVO chips which defeats the purpose of doing a bus switch in the first
479 static void intel_sdvo_set_control_bus_switch(struct intel_output
*intel_output
,
482 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_CONTROL_BUS_SWITCH
, &target
, 1);
485 static bool intel_sdvo_set_target_input(struct intel_output
*intel_output
, bool target_0
, bool target_1
)
487 struct intel_sdvo_set_target_input_args targets
= {0};
490 if (target_0
&& target_1
)
491 return SDVO_CMD_STATUS_NOTSUPP
;
494 targets
.target_1
= 1;
496 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_TARGET_INPUT
, &targets
,
499 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
501 return (status
== SDVO_CMD_STATUS_SUCCESS
);
505 * Return whether each input is trained.
507 * This function is making an assumption about the layout of the response,
508 * which should be checked against the docs.
510 static bool intel_sdvo_get_trained_inputs(struct intel_output
*intel_output
, bool *input_1
, bool *input_2
)
512 struct intel_sdvo_get_trained_inputs_response response
;
515 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_TRAINED_INPUTS
, NULL
, 0);
516 status
= intel_sdvo_read_response(intel_output
, &response
, sizeof(response
));
517 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
520 *input_1
= response
.input0_trained
;
521 *input_2
= response
.input1_trained
;
525 static bool intel_sdvo_get_active_outputs(struct intel_output
*intel_output
,
530 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_ACTIVE_OUTPUTS
, NULL
, 0);
531 status
= intel_sdvo_read_response(intel_output
, outputs
, sizeof(*outputs
));
533 return (status
== SDVO_CMD_STATUS_SUCCESS
);
536 static bool intel_sdvo_set_active_outputs(struct intel_output
*intel_output
,
541 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ACTIVE_OUTPUTS
, &outputs
,
543 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
544 return (status
== SDVO_CMD_STATUS_SUCCESS
);
547 static bool intel_sdvo_set_encoder_power_state(struct intel_output
*intel_output
,
550 u8 status
, state
= SDVO_ENCODER_STATE_ON
;
553 case DRM_MODE_DPMS_ON
:
554 state
= SDVO_ENCODER_STATE_ON
;
556 case DRM_MODE_DPMS_STANDBY
:
557 state
= SDVO_ENCODER_STATE_STANDBY
;
559 case DRM_MODE_DPMS_SUSPEND
:
560 state
= SDVO_ENCODER_STATE_SUSPEND
;
562 case DRM_MODE_DPMS_OFF
:
563 state
= SDVO_ENCODER_STATE_OFF
;
567 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ENCODER_POWER_STATE
, &state
,
569 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
571 return (status
== SDVO_CMD_STATUS_SUCCESS
);
574 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output
*intel_output
,
578 struct intel_sdvo_pixel_clock_range clocks
;
581 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
,
584 status
= intel_sdvo_read_response(intel_output
, &clocks
, sizeof(clocks
));
586 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
589 /* Convert the values from units of 10 kHz to kHz. */
590 *clock_min
= clocks
.min
* 10;
591 *clock_max
= clocks
.max
* 10;
596 static bool intel_sdvo_set_target_output(struct intel_output
*intel_output
,
601 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_TARGET_OUTPUT
, &outputs
,
604 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
605 return (status
== SDVO_CMD_STATUS_SUCCESS
);
608 static bool intel_sdvo_get_timing(struct intel_output
*intel_output
, u8 cmd
,
609 struct intel_sdvo_dtd
*dtd
)
613 intel_sdvo_write_cmd(intel_output
, cmd
, NULL
, 0);
614 status
= intel_sdvo_read_response(intel_output
, &dtd
->part1
,
616 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
619 intel_sdvo_write_cmd(intel_output
, cmd
+ 1, NULL
, 0);
620 status
= intel_sdvo_read_response(intel_output
, &dtd
->part2
,
622 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
628 static bool intel_sdvo_get_input_timing(struct intel_output
*intel_output
,
629 struct intel_sdvo_dtd
*dtd
)
631 return intel_sdvo_get_timing(intel_output
,
632 SDVO_CMD_GET_INPUT_TIMINGS_PART1
, dtd
);
635 static bool intel_sdvo_get_output_timing(struct intel_output
*intel_output
,
636 struct intel_sdvo_dtd
*dtd
)
638 return intel_sdvo_get_timing(intel_output
,
639 SDVO_CMD_GET_OUTPUT_TIMINGS_PART1
, dtd
);
642 static bool intel_sdvo_set_timing(struct intel_output
*intel_output
, u8 cmd
,
643 struct intel_sdvo_dtd
*dtd
)
647 intel_sdvo_write_cmd(intel_output
, cmd
, &dtd
->part1
, sizeof(dtd
->part1
));
648 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
649 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
652 intel_sdvo_write_cmd(intel_output
, cmd
+ 1, &dtd
->part2
, sizeof(dtd
->part2
));
653 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
654 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
660 static bool intel_sdvo_set_input_timing(struct intel_output
*intel_output
,
661 struct intel_sdvo_dtd
*dtd
)
663 return intel_sdvo_set_timing(intel_output
,
664 SDVO_CMD_SET_INPUT_TIMINGS_PART1
, dtd
);
667 static bool intel_sdvo_set_output_timing(struct intel_output
*intel_output
,
668 struct intel_sdvo_dtd
*dtd
)
670 return intel_sdvo_set_timing(intel_output
,
671 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
, dtd
);
675 intel_sdvo_create_preferred_input_timing(struct intel_output
*output
,
680 struct intel_sdvo_preferred_input_timing_args args
;
681 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
684 memset(&args
, 0, sizeof(args
));
687 args
.height
= height
;
690 if (sdvo_priv
->is_lvds
&&
691 (sdvo_priv
->sdvo_lvds_fixed_mode
->hdisplay
!= width
||
692 sdvo_priv
->sdvo_lvds_fixed_mode
->vdisplay
!= height
))
695 intel_sdvo_write_cmd(output
, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
,
696 &args
, sizeof(args
));
697 status
= intel_sdvo_read_response(output
, NULL
, 0);
698 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
704 static bool intel_sdvo_get_preferred_input_timing(struct intel_output
*output
,
705 struct intel_sdvo_dtd
*dtd
)
709 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
,
712 status
= intel_sdvo_read_response(output
, &dtd
->part1
,
714 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
717 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
,
720 status
= intel_sdvo_read_response(output
, &dtd
->part2
,
722 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
728 static int intel_sdvo_get_clock_rate_mult(struct intel_output
*intel_output
)
732 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_CLOCK_RATE_MULT
, NULL
, 0);
733 status
= intel_sdvo_read_response(intel_output
, &response
, 1);
735 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
736 DRM_DEBUG_KMS("Couldn't get SDVO clock rate multiplier\n");
737 return SDVO_CLOCK_RATE_MULT_1X
;
739 DRM_DEBUG_KMS("Current clock rate multiplier: %d\n", response
);
745 static bool intel_sdvo_set_clock_rate_mult(struct intel_output
*intel_output
, u8 val
)
749 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_CLOCK_RATE_MULT
, &val
, 1);
750 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
751 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
757 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd
*dtd
,
758 struct drm_display_mode
*mode
)
760 uint16_t width
, height
;
761 uint16_t h_blank_len
, h_sync_len
, v_blank_len
, v_sync_len
;
762 uint16_t h_sync_offset
, v_sync_offset
;
764 width
= mode
->crtc_hdisplay
;
765 height
= mode
->crtc_vdisplay
;
767 /* do some mode translations */
768 h_blank_len
= mode
->crtc_hblank_end
- mode
->crtc_hblank_start
;
769 h_sync_len
= mode
->crtc_hsync_end
- mode
->crtc_hsync_start
;
771 v_blank_len
= mode
->crtc_vblank_end
- mode
->crtc_vblank_start
;
772 v_sync_len
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
;
774 h_sync_offset
= mode
->crtc_hsync_start
- mode
->crtc_hblank_start
;
775 v_sync_offset
= mode
->crtc_vsync_start
- mode
->crtc_vblank_start
;
777 dtd
->part1
.clock
= mode
->clock
/ 10;
778 dtd
->part1
.h_active
= width
& 0xff;
779 dtd
->part1
.h_blank
= h_blank_len
& 0xff;
780 dtd
->part1
.h_high
= (((width
>> 8) & 0xf) << 4) |
781 ((h_blank_len
>> 8) & 0xf);
782 dtd
->part1
.v_active
= height
& 0xff;
783 dtd
->part1
.v_blank
= v_blank_len
& 0xff;
784 dtd
->part1
.v_high
= (((height
>> 8) & 0xf) << 4) |
785 ((v_blank_len
>> 8) & 0xf);
787 dtd
->part2
.h_sync_off
= h_sync_offset
& 0xff;
788 dtd
->part2
.h_sync_width
= h_sync_len
& 0xff;
789 dtd
->part2
.v_sync_off_width
= (v_sync_offset
& 0xf) << 4 |
791 dtd
->part2
.sync_off_width_high
= ((h_sync_offset
& 0x300) >> 2) |
792 ((h_sync_len
& 0x300) >> 4) | ((v_sync_offset
& 0x30) >> 2) |
793 ((v_sync_len
& 0x30) >> 4);
795 dtd
->part2
.dtd_flags
= 0x18;
796 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
797 dtd
->part2
.dtd_flags
|= 0x2;
798 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
799 dtd
->part2
.dtd_flags
|= 0x4;
801 dtd
->part2
.sdvo_flags
= 0;
802 dtd
->part2
.v_sync_off_high
= v_sync_offset
& 0xc0;
803 dtd
->part2
.reserved
= 0;
806 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode
* mode
,
807 struct intel_sdvo_dtd
*dtd
)
809 mode
->hdisplay
= dtd
->part1
.h_active
;
810 mode
->hdisplay
+= ((dtd
->part1
.h_high
>> 4) & 0x0f) << 8;
811 mode
->hsync_start
= mode
->hdisplay
+ dtd
->part2
.h_sync_off
;
812 mode
->hsync_start
+= (dtd
->part2
.sync_off_width_high
& 0xc0) << 2;
813 mode
->hsync_end
= mode
->hsync_start
+ dtd
->part2
.h_sync_width
;
814 mode
->hsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x30) << 4;
815 mode
->htotal
= mode
->hdisplay
+ dtd
->part1
.h_blank
;
816 mode
->htotal
+= (dtd
->part1
.h_high
& 0xf) << 8;
818 mode
->vdisplay
= dtd
->part1
.v_active
;
819 mode
->vdisplay
+= ((dtd
->part1
.v_high
>> 4) & 0x0f) << 8;
820 mode
->vsync_start
= mode
->vdisplay
;
821 mode
->vsync_start
+= (dtd
->part2
.v_sync_off_width
>> 4) & 0xf;
822 mode
->vsync_start
+= (dtd
->part2
.sync_off_width_high
& 0x0c) << 2;
823 mode
->vsync_start
+= dtd
->part2
.v_sync_off_high
& 0xc0;
824 mode
->vsync_end
= mode
->vsync_start
+
825 (dtd
->part2
.v_sync_off_width
& 0xf);
826 mode
->vsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x3) << 4;
827 mode
->vtotal
= mode
->vdisplay
+ dtd
->part1
.v_blank
;
828 mode
->vtotal
+= (dtd
->part1
.v_high
& 0xf) << 8;
830 mode
->clock
= dtd
->part1
.clock
* 10;
832 mode
->flags
&= ~(DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
);
833 if (dtd
->part2
.dtd_flags
& 0x2)
834 mode
->flags
|= DRM_MODE_FLAG_PHSYNC
;
835 if (dtd
->part2
.dtd_flags
& 0x4)
836 mode
->flags
|= DRM_MODE_FLAG_PVSYNC
;
839 static bool intel_sdvo_get_supp_encode(struct intel_output
*output
,
840 struct intel_sdvo_encode
*encode
)
844 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_SUPP_ENCODE
, NULL
, 0);
845 status
= intel_sdvo_read_response(output
, encode
, sizeof(*encode
));
846 if (status
!= SDVO_CMD_STATUS_SUCCESS
) { /* non-support means DVI */
847 memset(encode
, 0, sizeof(*encode
));
854 static bool intel_sdvo_set_encode(struct intel_output
*output
, uint8_t mode
)
858 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_ENCODE
, &mode
, 1);
859 status
= intel_sdvo_read_response(output
, NULL
, 0);
861 return (status
== SDVO_CMD_STATUS_SUCCESS
);
864 static bool intel_sdvo_set_colorimetry(struct intel_output
*output
,
869 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_COLORIMETRY
, &mode
, 1);
870 status
= intel_sdvo_read_response(output
, NULL
, 0);
872 return (status
== SDVO_CMD_STATUS_SUCCESS
);
876 static void intel_sdvo_dump_hdmi_buf(struct intel_output
*output
)
879 uint8_t set_buf_index
[2];
885 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_HBUF_AV_SPLIT
, NULL
, 0);
886 intel_sdvo_read_response(output
, &av_split
, 1);
888 for (i
= 0; i
<= av_split
; i
++) {
889 set_buf_index
[0] = i
; set_buf_index
[1] = 0;
890 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_INDEX
,
892 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_HBUF_INFO
, NULL
, 0);
893 intel_sdvo_read_response(output
, &buf_size
, 1);
896 for (j
= 0; j
<= buf_size
; j
+= 8) {
897 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_HBUF_DATA
,
899 intel_sdvo_read_response(output
, pos
, 8);
906 static void intel_sdvo_set_hdmi_buf(struct intel_output
*output
, int index
,
907 uint8_t *data
, int8_t size
, uint8_t tx_rate
)
909 uint8_t set_buf_index
[2];
911 set_buf_index
[0] = index
;
912 set_buf_index
[1] = 0;
914 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_INDEX
, set_buf_index
, 2);
916 for (; size
> 0; size
-= 8) {
917 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_DATA
, data
, 8);
921 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_TXRATE
, &tx_rate
, 1);
924 static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data
, uint8_t size
)
929 for (i
= 0; i
< size
; i
++)
935 #define DIP_TYPE_AVI 0x82
936 #define DIP_VERSION_AVI 0x2
937 #define DIP_LEN_AVI 13
939 struct dip_infoframe
{
967 /* Packet Byte #6~13 */
968 uint16_t top_bar_end
;
969 uint16_t bottom_bar_start
;
970 uint16_t left_bar_end
;
971 uint16_t right_bar_start
;
975 uint8_t channel_count
:3;
977 uint8_t coding_type
:4;
979 uint8_t sample_size
:2; /* SS0, SS1 */
980 uint8_t sample_frequency
:3;
983 uint8_t coding_type_private
:5;
986 uint8_t channel_allocation
;
989 uint8_t level_shift
:4;
990 uint8_t downmix_inhibit
:1;
993 } __attribute__ ((packed
)) u
;
994 } __attribute__((packed
));
996 static void intel_sdvo_set_avi_infoframe(struct intel_output
*output
,
997 struct drm_display_mode
* mode
)
999 struct dip_infoframe avi_if
= {
1000 .type
= DIP_TYPE_AVI
,
1001 .version
= DIP_VERSION_AVI
,
1005 avi_if
.checksum
= intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if
,
1007 intel_sdvo_set_hdmi_buf(output
, 1, (uint8_t *)&avi_if
, 4 + avi_if
.len
,
1008 SDVO_HBUF_TX_VSYNC
);
1011 static void intel_sdvo_set_tv_format(struct intel_output
*output
)
1014 struct intel_sdvo_tv_format format
;
1015 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1016 uint32_t format_map
, i
;
1019 for (i
= 0; i
< TV_FORMAT_NUM
; i
++)
1020 if (tv_format_names
[i
] == sdvo_priv
->tv_format_name
)
1023 format_map
= 1 << i
;
1024 memset(&format
, 0, sizeof(format
));
1025 memcpy(&format
, &format_map
, sizeof(format_map
) > sizeof(format
) ?
1026 sizeof(format
) : sizeof(format_map
));
1028 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_TV_FORMAT
, &format_map
,
1031 status
= intel_sdvo_read_response(output
, NULL
, 0);
1032 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1033 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
1034 SDVO_NAME(sdvo_priv
));
1037 static bool intel_sdvo_mode_fixup(struct drm_encoder
*encoder
,
1038 struct drm_display_mode
*mode
,
1039 struct drm_display_mode
*adjusted_mode
)
1041 struct intel_output
*output
= enc_to_intel_output(encoder
);
1042 struct intel_sdvo_priv
*dev_priv
= output
->dev_priv
;
1044 if (dev_priv
->is_tv
) {
1045 struct intel_sdvo_dtd output_dtd
;
1048 /* We need to construct preferred input timings based on our
1049 * output timings. To do that, we have to set the output
1050 * timings, even though this isn't really the right place in
1051 * the sequence to do it. Oh well.
1055 /* Set output timings */
1056 intel_sdvo_get_dtd_from_mode(&output_dtd
, mode
);
1057 intel_sdvo_set_target_output(output
,
1058 dev_priv
->controlled_output
);
1059 intel_sdvo_set_output_timing(output
, &output_dtd
);
1061 /* Set the input timing to the screen. Assume always input 0. */
1062 intel_sdvo_set_target_input(output
, true, false);
1065 success
= intel_sdvo_create_preferred_input_timing(output
,
1070 struct intel_sdvo_dtd input_dtd
;
1072 intel_sdvo_get_preferred_input_timing(output
,
1074 intel_sdvo_get_mode_from_dtd(adjusted_mode
, &input_dtd
);
1075 dev_priv
->sdvo_flags
= input_dtd
.part2
.sdvo_flags
;
1077 drm_mode_set_crtcinfo(adjusted_mode
, 0);
1079 mode
->clock
= adjusted_mode
->clock
;
1081 adjusted_mode
->clock
*=
1082 intel_sdvo_get_pixel_multiplier(mode
);
1086 } else if (dev_priv
->is_lvds
) {
1087 struct intel_sdvo_dtd output_dtd
;
1090 drm_mode_set_crtcinfo(dev_priv
->sdvo_lvds_fixed_mode
, 0);
1091 /* Set output timings */
1092 intel_sdvo_get_dtd_from_mode(&output_dtd
,
1093 dev_priv
->sdvo_lvds_fixed_mode
);
1095 intel_sdvo_set_target_output(output
,
1096 dev_priv
->controlled_output
);
1097 intel_sdvo_set_output_timing(output
, &output_dtd
);
1099 /* Set the input timing to the screen. Assume always input 0. */
1100 intel_sdvo_set_target_input(output
, true, false);
1103 success
= intel_sdvo_create_preferred_input_timing(
1110 struct intel_sdvo_dtd input_dtd
;
1112 intel_sdvo_get_preferred_input_timing(output
,
1114 intel_sdvo_get_mode_from_dtd(adjusted_mode
, &input_dtd
);
1115 dev_priv
->sdvo_flags
= input_dtd
.part2
.sdvo_flags
;
1117 drm_mode_set_crtcinfo(adjusted_mode
, 0);
1119 mode
->clock
= adjusted_mode
->clock
;
1121 adjusted_mode
->clock
*=
1122 intel_sdvo_get_pixel_multiplier(mode
);
1128 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1129 * SDVO device will be told of the multiplier during mode_set.
1131 adjusted_mode
->clock
*= intel_sdvo_get_pixel_multiplier(mode
);
1136 static void intel_sdvo_mode_set(struct drm_encoder
*encoder
,
1137 struct drm_display_mode
*mode
,
1138 struct drm_display_mode
*adjusted_mode
)
1140 struct drm_device
*dev
= encoder
->dev
;
1141 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1142 struct drm_crtc
*crtc
= encoder
->crtc
;
1143 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1144 struct intel_output
*output
= enc_to_intel_output(encoder
);
1145 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1147 int sdvo_pixel_multiply
;
1148 struct intel_sdvo_in_out_map in_out
;
1149 struct intel_sdvo_dtd input_dtd
;
1155 /* First, set the input mapping for the first input to our controlled
1156 * output. This is only correct if we're a single-input device, in
1157 * which case the first input is the output from the appropriate SDVO
1158 * channel on the motherboard. In a two-input device, the first input
1159 * will be SDVOB and the second SDVOC.
1161 in_out
.in0
= sdvo_priv
->controlled_output
;
1164 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_IN_OUT_MAP
,
1165 &in_out
, sizeof(in_out
));
1166 status
= intel_sdvo_read_response(output
, NULL
, 0);
1168 if (sdvo_priv
->is_hdmi
) {
1169 intel_sdvo_set_avi_infoframe(output
, mode
);
1170 sdvox
|= SDVO_AUDIO_ENABLE
;
1173 /* We have tried to get input timing in mode_fixup, and filled into
1175 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
1176 intel_sdvo_get_dtd_from_mode(&input_dtd
, adjusted_mode
);
1177 input_dtd
.part2
.sdvo_flags
= sdvo_priv
->sdvo_flags
;
1179 intel_sdvo_get_dtd_from_mode(&input_dtd
, mode
);
1181 /* If it's a TV, we already set the output timing in mode_fixup.
1182 * Otherwise, the output timing is equal to the input timing.
1184 if (!sdvo_priv
->is_tv
&& !sdvo_priv
->is_lvds
) {
1185 /* Set the output timing to the screen */
1186 intel_sdvo_set_target_output(output
,
1187 sdvo_priv
->controlled_output
);
1188 intel_sdvo_set_output_timing(output
, &input_dtd
);
1191 /* Set the input timing to the screen. Assume always input 0. */
1192 intel_sdvo_set_target_input(output
, true, false);
1194 if (sdvo_priv
->is_tv
)
1195 intel_sdvo_set_tv_format(output
);
1197 /* We would like to use intel_sdvo_create_preferred_input_timing() to
1198 * provide the device with a timing it can support, if it supports that
1199 * feature. However, presumably we would need to adjust the CRTC to
1200 * output the preferred timing, and we don't support that currently.
1203 success
= intel_sdvo_create_preferred_input_timing(output
, clock
,
1206 struct intel_sdvo_dtd
*input_dtd
;
1208 intel_sdvo_get_preferred_input_timing(output
, &input_dtd
);
1209 intel_sdvo_set_input_timing(output
, &input_dtd
);
1212 intel_sdvo_set_input_timing(output
, &input_dtd
);
1215 switch (intel_sdvo_get_pixel_multiplier(mode
)) {
1217 intel_sdvo_set_clock_rate_mult(output
,
1218 SDVO_CLOCK_RATE_MULT_1X
);
1221 intel_sdvo_set_clock_rate_mult(output
,
1222 SDVO_CLOCK_RATE_MULT_2X
);
1225 intel_sdvo_set_clock_rate_mult(output
,
1226 SDVO_CLOCK_RATE_MULT_4X
);
1230 /* Set the SDVO control regs. */
1231 if (IS_I965G(dev
)) {
1232 sdvox
|= SDVO_BORDER_ENABLE
|
1233 SDVO_VSYNC_ACTIVE_HIGH
|
1234 SDVO_HSYNC_ACTIVE_HIGH
;
1236 sdvox
|= I915_READ(sdvo_priv
->output_device
);
1237 switch (sdvo_priv
->output_device
) {
1239 sdvox
&= SDVOB_PRESERVE_MASK
;
1242 sdvox
&= SDVOC_PRESERVE_MASK
;
1245 sdvox
|= (9 << 19) | SDVO_BORDER_ENABLE
;
1247 if (intel_crtc
->pipe
== 1)
1248 sdvox
|= SDVO_PIPE_B_SELECT
;
1250 sdvo_pixel_multiply
= intel_sdvo_get_pixel_multiplier(mode
);
1251 if (IS_I965G(dev
)) {
1252 /* done in crtc_mode_set as the dpll_md reg must be written early */
1253 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
1254 /* done in crtc_mode_set as it lives inside the dpll register */
1256 sdvox
|= (sdvo_pixel_multiply
- 1) << SDVO_PORT_MULTIPLY_SHIFT
;
1259 if (sdvo_priv
->sdvo_flags
& SDVO_NEED_TO_STALL
)
1260 sdvox
|= SDVO_STALL_SELECT
;
1261 intel_sdvo_write_sdvox(output
, sdvox
);
1264 static void intel_sdvo_dpms(struct drm_encoder
*encoder
, int mode
)
1266 struct drm_device
*dev
= encoder
->dev
;
1267 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1268 struct intel_output
*intel_output
= enc_to_intel_output(encoder
);
1269 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1272 if (mode
!= DRM_MODE_DPMS_ON
) {
1273 intel_sdvo_set_active_outputs(intel_output
, 0);
1275 intel_sdvo_set_encoder_power_state(intel_output
, mode
);
1277 if (mode
== DRM_MODE_DPMS_OFF
) {
1278 temp
= I915_READ(sdvo_priv
->output_device
);
1279 if ((temp
& SDVO_ENABLE
) != 0) {
1280 intel_sdvo_write_sdvox(intel_output
, temp
& ~SDVO_ENABLE
);
1284 bool input1
, input2
;
1288 temp
= I915_READ(sdvo_priv
->output_device
);
1289 if ((temp
& SDVO_ENABLE
) == 0)
1290 intel_sdvo_write_sdvox(intel_output
, temp
| SDVO_ENABLE
);
1291 for (i
= 0; i
< 2; i
++)
1292 intel_wait_for_vblank(dev
);
1294 status
= intel_sdvo_get_trained_inputs(intel_output
, &input1
,
1298 /* Warn if the device reported failure to sync.
1299 * A lot of SDVO devices fail to notify of sync, but it's
1300 * a given it the status is a success, we succeeded.
1302 if (status
== SDVO_CMD_STATUS_SUCCESS
&& !input1
) {
1303 DRM_DEBUG_KMS("First %s output reported failure to "
1304 "sync\n", SDVO_NAME(sdvo_priv
));
1308 intel_sdvo_set_encoder_power_state(intel_output
, mode
);
1309 intel_sdvo_set_active_outputs(intel_output
, sdvo_priv
->controlled_output
);
1314 static void intel_sdvo_save(struct drm_connector
*connector
)
1316 struct drm_device
*dev
= connector
->dev
;
1317 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1318 struct intel_output
*intel_output
= to_intel_output(connector
);
1319 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1322 sdvo_priv
->save_sdvo_mult
= intel_sdvo_get_clock_rate_mult(intel_output
);
1323 intel_sdvo_get_active_outputs(intel_output
, &sdvo_priv
->save_active_outputs
);
1325 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x1) {
1326 intel_sdvo_set_target_input(intel_output
, true, false);
1327 intel_sdvo_get_input_timing(intel_output
,
1328 &sdvo_priv
->save_input_dtd_1
);
1331 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x2) {
1332 intel_sdvo_set_target_input(intel_output
, false, true);
1333 intel_sdvo_get_input_timing(intel_output
,
1334 &sdvo_priv
->save_input_dtd_2
);
1337 for (o
= SDVO_OUTPUT_FIRST
; o
<= SDVO_OUTPUT_LAST
; o
++)
1339 u16 this_output
= (1 << o
);
1340 if (sdvo_priv
->caps
.output_flags
& this_output
)
1342 intel_sdvo_set_target_output(intel_output
, this_output
);
1343 intel_sdvo_get_output_timing(intel_output
,
1344 &sdvo_priv
->save_output_dtd
[o
]);
1347 if (sdvo_priv
->is_tv
) {
1348 /* XXX: Save TV format/enhancements. */
1351 sdvo_priv
->save_SDVOX
= I915_READ(sdvo_priv
->output_device
);
1354 static void intel_sdvo_restore(struct drm_connector
*connector
)
1356 struct drm_device
*dev
= connector
->dev
;
1357 struct intel_output
*intel_output
= to_intel_output(connector
);
1358 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1361 bool input1
, input2
;
1364 intel_sdvo_set_active_outputs(intel_output
, 0);
1366 for (o
= SDVO_OUTPUT_FIRST
; o
<= SDVO_OUTPUT_LAST
; o
++)
1368 u16 this_output
= (1 << o
);
1369 if (sdvo_priv
->caps
.output_flags
& this_output
) {
1370 intel_sdvo_set_target_output(intel_output
, this_output
);
1371 intel_sdvo_set_output_timing(intel_output
, &sdvo_priv
->save_output_dtd
[o
]);
1375 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x1) {
1376 intel_sdvo_set_target_input(intel_output
, true, false);
1377 intel_sdvo_set_input_timing(intel_output
, &sdvo_priv
->save_input_dtd_1
);
1380 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x2) {
1381 intel_sdvo_set_target_input(intel_output
, false, true);
1382 intel_sdvo_set_input_timing(intel_output
, &sdvo_priv
->save_input_dtd_2
);
1385 intel_sdvo_set_clock_rate_mult(intel_output
, sdvo_priv
->save_sdvo_mult
);
1387 if (sdvo_priv
->is_tv
) {
1388 /* XXX: Restore TV format/enhancements. */
1391 intel_sdvo_write_sdvox(intel_output
, sdvo_priv
->save_SDVOX
);
1393 if (sdvo_priv
->save_SDVOX
& SDVO_ENABLE
)
1395 for (i
= 0; i
< 2; i
++)
1396 intel_wait_for_vblank(dev
);
1397 status
= intel_sdvo_get_trained_inputs(intel_output
, &input1
, &input2
);
1398 if (status
== SDVO_CMD_STATUS_SUCCESS
&& !input1
)
1399 DRM_DEBUG_KMS("First %s output reported failure to "
1400 "sync\n", SDVO_NAME(sdvo_priv
));
1403 intel_sdvo_set_active_outputs(intel_output
, sdvo_priv
->save_active_outputs
);
1406 static int intel_sdvo_mode_valid(struct drm_connector
*connector
,
1407 struct drm_display_mode
*mode
)
1409 struct intel_output
*intel_output
= to_intel_output(connector
);
1410 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1412 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
1413 return MODE_NO_DBLESCAN
;
1415 if (sdvo_priv
->pixel_clock_min
> mode
->clock
)
1416 return MODE_CLOCK_LOW
;
1418 if (sdvo_priv
->pixel_clock_max
< mode
->clock
)
1419 return MODE_CLOCK_HIGH
;
1421 if (sdvo_priv
->is_lvds
== true) {
1422 if (sdvo_priv
->sdvo_lvds_fixed_mode
== NULL
)
1425 if (mode
->hdisplay
> sdvo_priv
->sdvo_lvds_fixed_mode
->hdisplay
)
1428 if (mode
->vdisplay
> sdvo_priv
->sdvo_lvds_fixed_mode
->vdisplay
)
1435 static bool intel_sdvo_get_capabilities(struct intel_output
*intel_output
, struct intel_sdvo_caps
*caps
)
1439 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_DEVICE_CAPS
, NULL
, 0);
1440 status
= intel_sdvo_read_response(intel_output
, caps
, sizeof(*caps
));
1441 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1447 struct drm_connector
* intel_sdvo_find(struct drm_device
*dev
, int sdvoB
)
1449 struct drm_connector
*connector
= NULL
;
1450 struct intel_output
*iout
= NULL
;
1451 struct intel_sdvo_priv
*sdvo
;
1453 /* find the sdvo connector */
1454 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1455 iout
= to_intel_output(connector
);
1457 if (iout
->type
!= INTEL_OUTPUT_SDVO
)
1460 sdvo
= iout
->dev_priv
;
1462 if (sdvo
->output_device
== SDVOB
&& sdvoB
)
1465 if (sdvo
->output_device
== SDVOC
&& !sdvoB
)
1473 int intel_sdvo_supports_hotplug(struct drm_connector
*connector
)
1477 struct intel_output
*intel_output
;
1478 DRM_DEBUG_KMS("\n");
1483 intel_output
= to_intel_output(connector
);
1485 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
, NULL
, 0);
1486 status
= intel_sdvo_read_response(intel_output
, &response
, 2);
1488 if (response
[0] !=0)
1494 void intel_sdvo_set_hotplug(struct drm_connector
*connector
, int on
)
1498 struct intel_output
*intel_output
= to_intel_output(connector
);
1500 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_ACTIVE_HOT_PLUG
, NULL
, 0);
1501 intel_sdvo_read_response(intel_output
, &response
, 2);
1504 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
, NULL
, 0);
1505 status
= intel_sdvo_read_response(intel_output
, &response
, 2);
1507 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
, &response
, 2);
1511 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
, &response
, 2);
1514 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_ACTIVE_HOT_PLUG
, NULL
, 0);
1515 intel_sdvo_read_response(intel_output
, &response
, 2);
1519 intel_sdvo_multifunc_encoder(struct intel_output
*intel_output
)
1521 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1524 if (sdvo_priv
->caps
.output_flags
&
1525 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
))
1527 if (sdvo_priv
->caps
.output_flags
&
1528 (SDVO_OUTPUT_RGB0
| SDVO_OUTPUT_RGB1
))
1530 if (sdvo_priv
->caps
.output_flags
&
1531 (SDVO_OUTPUT_SVID0
| SDVO_OUTPUT_SVID1
))
1533 if (sdvo_priv
->caps
.output_flags
&
1534 (SDVO_OUTPUT_CVBS0
| SDVO_OUTPUT_CVBS1
))
1536 if (sdvo_priv
->caps
.output_flags
&
1537 (SDVO_OUTPUT_YPRPB0
| SDVO_OUTPUT_YPRPB1
))
1540 if (sdvo_priv
->caps
.output_flags
&
1541 (SDVO_OUTPUT_SCART0
| SDVO_OUTPUT_SCART1
))
1544 if (sdvo_priv
->caps
.output_flags
&
1545 (SDVO_OUTPUT_LVDS0
| SDVO_OUTPUT_LVDS1
))
1551 static struct drm_connector
*
1552 intel_find_analog_connector(struct drm_device
*dev
)
1554 struct drm_connector
*connector
;
1555 struct intel_output
*intel_output
;
1557 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1558 intel_output
= to_intel_output(connector
);
1559 if (intel_output
->type
== INTEL_OUTPUT_ANALOG
)
1566 intel_analog_is_connected(struct drm_device
*dev
)
1568 struct drm_connector
*analog_connector
;
1569 analog_connector
= intel_find_analog_connector(dev
);
1571 if (!analog_connector
)
1574 if (analog_connector
->funcs
->detect(analog_connector
) ==
1575 connector_status_disconnected
)
1581 enum drm_connector_status
1582 intel_sdvo_hdmi_sink_detect(struct drm_connector
*connector
, u16 response
)
1584 struct intel_output
*intel_output
= to_intel_output(connector
);
1585 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1586 enum drm_connector_status status
= connector_status_connected
;
1587 struct edid
*edid
= NULL
;
1589 edid
= drm_get_edid(&intel_output
->base
,
1590 intel_output
->ddc_bus
);
1592 /* when there is no edid and no monitor is connected with VGA
1593 * port, try to use the CRT ddc to read the EDID for DVI-connector
1596 sdvo_priv
->analog_ddc_bus
&&
1597 !intel_analog_is_connected(intel_output
->base
.dev
))
1598 edid
= drm_get_edid(&intel_output
->base
,
1599 sdvo_priv
->analog_ddc_bus
);
1601 /* Don't report the output as connected if it's a DVI-I
1602 * connector with a non-digital EDID coming out.
1604 if (response
& (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
)) {
1605 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
)
1606 sdvo_priv
->is_hdmi
=
1607 drm_detect_hdmi_monitor(edid
);
1609 status
= connector_status_disconnected
;
1613 intel_output
->base
.display_info
.raw_edid
= NULL
;
1615 } else if (response
& (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
))
1616 status
= connector_status_disconnected
;
1621 static enum drm_connector_status
intel_sdvo_detect(struct drm_connector
*connector
)
1625 struct intel_output
*intel_output
= to_intel_output(connector
);
1626 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1628 intel_sdvo_write_cmd(intel_output
,
1629 SDVO_CMD_GET_ATTACHED_DISPLAYS
, NULL
, 0);
1630 status
= intel_sdvo_read_response(intel_output
, &response
, 2);
1632 DRM_DEBUG_KMS("SDVO response %d %d\n", response
& 0xff, response
>> 8);
1634 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1635 return connector_status_unknown
;
1638 return connector_status_disconnected
;
1640 if (intel_sdvo_multifunc_encoder(intel_output
) &&
1641 sdvo_priv
->attached_output
!= response
) {
1642 if (sdvo_priv
->controlled_output
!= response
&&
1643 intel_sdvo_output_setup(intel_output
, response
) != true)
1644 return connector_status_unknown
;
1645 sdvo_priv
->attached_output
= response
;
1647 return intel_sdvo_hdmi_sink_detect(connector
, response
);
1650 static void intel_sdvo_get_ddc_modes(struct drm_connector
*connector
)
1652 struct intel_output
*intel_output
= to_intel_output(connector
);
1653 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1656 /* set the bus switch and get the modes */
1657 num_modes
= intel_ddc_get_modes(intel_output
);
1660 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1661 * link between analog and digital outputs. So, if the regular SDVO
1662 * DDC fails, check to see if the analog output is disconnected, in
1663 * which case we'll look there for the digital DDC data.
1665 if (num_modes
== 0 &&
1666 sdvo_priv
->analog_ddc_bus
&&
1667 !intel_analog_is_connected(intel_output
->base
.dev
)) {
1668 struct i2c_adapter
*digital_ddc_bus
;
1670 /* Switch to the analog ddc bus and try that
1672 digital_ddc_bus
= intel_output
->ddc_bus
;
1673 intel_output
->ddc_bus
= sdvo_priv
->analog_ddc_bus
;
1675 (void) intel_ddc_get_modes(intel_output
);
1677 intel_output
->ddc_bus
= digital_ddc_bus
;
1682 * Set of SDVO TV modes.
1683 * Note! This is in reply order (see loop in get_tv_modes).
1684 * XXX: all 60Hz refresh?
1686 struct drm_display_mode sdvo_tv_modes
[] = {
1687 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER
, 5815, 320, 321, 384,
1688 416, 0, 200, 201, 232, 233, 0,
1689 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1690 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER
, 6814, 320, 321, 384,
1691 416, 0, 240, 241, 272, 273, 0,
1692 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1693 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER
, 9910, 400, 401, 464,
1694 496, 0, 300, 301, 332, 333, 0,
1695 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1696 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER
, 16913, 640, 641, 704,
1697 736, 0, 350, 351, 382, 383, 0,
1698 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1699 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER
, 19121, 640, 641, 704,
1700 736, 0, 400, 401, 432, 433, 0,
1701 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1702 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 22654, 640, 641, 704,
1703 736, 0, 480, 481, 512, 513, 0,
1704 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1705 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER
, 24624, 704, 705, 768,
1706 800, 0, 480, 481, 512, 513, 0,
1707 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1708 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER
, 29232, 704, 705, 768,
1709 800, 0, 576, 577, 608, 609, 0,
1710 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1711 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER
, 18751, 720, 721, 784,
1712 816, 0, 350, 351, 382, 383, 0,
1713 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1714 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 21199, 720, 721, 784,
1715 816, 0, 400, 401, 432, 433, 0,
1716 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1717 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 25116, 720, 721, 784,
1718 816, 0, 480, 481, 512, 513, 0,
1719 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1720 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER
, 28054, 720, 721, 784,
1721 816, 0, 540, 541, 572, 573, 0,
1722 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1723 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 29816, 720, 721, 784,
1724 816, 0, 576, 577, 608, 609, 0,
1725 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1726 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER
, 31570, 768, 769, 832,
1727 864, 0, 576, 577, 608, 609, 0,
1728 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1729 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 34030, 800, 801, 864,
1730 896, 0, 600, 601, 632, 633, 0,
1731 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1732 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER
, 36581, 832, 833, 896,
1733 928, 0, 624, 625, 656, 657, 0,
1734 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1735 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER
, 48707, 920, 921, 984,
1736 1016, 0, 766, 767, 798, 799, 0,
1737 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1738 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 53827, 1024, 1025, 1088,
1739 1120, 0, 768, 769, 800, 801, 0,
1740 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1741 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 87265, 1280, 1281, 1344,
1742 1376, 0, 1024, 1025, 1056, 1057, 0,
1743 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1746 static void intel_sdvo_get_tv_modes(struct drm_connector
*connector
)
1748 struct intel_output
*output
= to_intel_output(connector
);
1749 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1750 struct intel_sdvo_sdtv_resolution_request tv_res
;
1751 uint32_t reply
= 0, format_map
= 0;
1756 /* Read the list of supported input resolutions for the selected TV
1759 for (i
= 0; i
< TV_FORMAT_NUM
; i
++)
1760 if (tv_format_names
[i
] == sdvo_priv
->tv_format_name
)
1763 format_map
= (1 << i
);
1764 memcpy(&tv_res
, &format_map
,
1765 sizeof(struct intel_sdvo_sdtv_resolution_request
) >
1766 sizeof(format_map
) ? sizeof(format_map
) :
1767 sizeof(struct intel_sdvo_sdtv_resolution_request
));
1769 intel_sdvo_set_target_output(output
, sdvo_priv
->controlled_output
);
1771 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
,
1772 &tv_res
, sizeof(tv_res
));
1773 status
= intel_sdvo_read_response(output
, &reply
, 3);
1774 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1777 for (i
= 0; i
< ARRAY_SIZE(sdvo_tv_modes
); i
++)
1778 if (reply
& (1 << i
)) {
1779 struct drm_display_mode
*nmode
;
1780 nmode
= drm_mode_duplicate(connector
->dev
,
1783 drm_mode_probed_add(connector
, nmode
);
1788 static void intel_sdvo_get_lvds_modes(struct drm_connector
*connector
)
1790 struct intel_output
*intel_output
= to_intel_output(connector
);
1791 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
1792 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1793 struct drm_display_mode
*newmode
;
1796 * Attempt to get the mode list from DDC.
1797 * Assume that the preferred modes are
1798 * arranged in priority order.
1800 intel_ddc_get_modes(intel_output
);
1801 if (list_empty(&connector
->probed_modes
) == false)
1804 /* Fetch modes from VBT */
1805 if (dev_priv
->sdvo_lvds_vbt_mode
!= NULL
) {
1806 newmode
= drm_mode_duplicate(connector
->dev
,
1807 dev_priv
->sdvo_lvds_vbt_mode
);
1808 if (newmode
!= NULL
) {
1809 /* Guarantee the mode is preferred */
1810 newmode
->type
= (DRM_MODE_TYPE_PREFERRED
|
1811 DRM_MODE_TYPE_DRIVER
);
1812 drm_mode_probed_add(connector
, newmode
);
1817 list_for_each_entry(newmode
, &connector
->probed_modes
, head
) {
1818 if (newmode
->type
& DRM_MODE_TYPE_PREFERRED
) {
1819 sdvo_priv
->sdvo_lvds_fixed_mode
=
1820 drm_mode_duplicate(connector
->dev
, newmode
);
1827 static int intel_sdvo_get_modes(struct drm_connector
*connector
)
1829 struct intel_output
*output
= to_intel_output(connector
);
1830 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1832 if (sdvo_priv
->is_tv
)
1833 intel_sdvo_get_tv_modes(connector
);
1834 else if (sdvo_priv
->is_lvds
== true)
1835 intel_sdvo_get_lvds_modes(connector
);
1837 intel_sdvo_get_ddc_modes(connector
);
1839 if (list_empty(&connector
->probed_modes
))
1845 void intel_sdvo_destroy_enhance_property(struct drm_connector
*connector
)
1847 struct intel_output
*intel_output
= to_intel_output(connector
);
1848 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1849 struct drm_device
*dev
= connector
->dev
;
1851 if (sdvo_priv
->is_tv
) {
1852 if (sdvo_priv
->left_property
)
1853 drm_property_destroy(dev
, sdvo_priv
->left_property
);
1854 if (sdvo_priv
->right_property
)
1855 drm_property_destroy(dev
, sdvo_priv
->right_property
);
1856 if (sdvo_priv
->top_property
)
1857 drm_property_destroy(dev
, sdvo_priv
->top_property
);
1858 if (sdvo_priv
->bottom_property
)
1859 drm_property_destroy(dev
, sdvo_priv
->bottom_property
);
1860 if (sdvo_priv
->hpos_property
)
1861 drm_property_destroy(dev
, sdvo_priv
->hpos_property
);
1862 if (sdvo_priv
->vpos_property
)
1863 drm_property_destroy(dev
, sdvo_priv
->vpos_property
);
1865 if (sdvo_priv
->is_tv
) {
1866 if (sdvo_priv
->saturation_property
)
1867 drm_property_destroy(dev
,
1868 sdvo_priv
->saturation_property
);
1869 if (sdvo_priv
->contrast_property
)
1870 drm_property_destroy(dev
,
1871 sdvo_priv
->contrast_property
);
1872 if (sdvo_priv
->hue_property
)
1873 drm_property_destroy(dev
, sdvo_priv
->hue_property
);
1875 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
1876 if (sdvo_priv
->brightness_property
)
1877 drm_property_destroy(dev
,
1878 sdvo_priv
->brightness_property
);
1883 static void intel_sdvo_destroy(struct drm_connector
*connector
)
1885 struct intel_output
*intel_output
= to_intel_output(connector
);
1886 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1888 if (intel_output
->i2c_bus
)
1889 intel_i2c_destroy(intel_output
->i2c_bus
);
1890 if (intel_output
->ddc_bus
)
1891 intel_i2c_destroy(intel_output
->ddc_bus
);
1892 if (sdvo_priv
->analog_ddc_bus
)
1893 intel_i2c_destroy(sdvo_priv
->analog_ddc_bus
);
1895 if (sdvo_priv
->sdvo_lvds_fixed_mode
!= NULL
)
1896 drm_mode_destroy(connector
->dev
,
1897 sdvo_priv
->sdvo_lvds_fixed_mode
);
1899 if (sdvo_priv
->tv_format_property
)
1900 drm_property_destroy(connector
->dev
,
1901 sdvo_priv
->tv_format_property
);
1903 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
)
1904 intel_sdvo_destroy_enhance_property(connector
);
1906 drm_sysfs_connector_remove(connector
);
1907 drm_connector_cleanup(connector
);
1909 kfree(intel_output
);
1913 intel_sdvo_set_property(struct drm_connector
*connector
,
1914 struct drm_property
*property
,
1917 struct intel_output
*intel_output
= to_intel_output(connector
);
1918 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1919 struct drm_encoder
*encoder
= &intel_output
->enc
;
1920 struct drm_crtc
*crtc
= encoder
->crtc
;
1922 bool changed
= false;
1923 uint8_t cmd
, status
;
1924 uint16_t temp_value
;
1926 ret
= drm_connector_property_set_value(connector
, property
, val
);
1930 if (property
== sdvo_priv
->tv_format_property
) {
1931 if (val
>= TV_FORMAT_NUM
) {
1935 if (sdvo_priv
->tv_format_name
==
1936 sdvo_priv
->tv_format_supported
[val
])
1939 sdvo_priv
->tv_format_name
= sdvo_priv
->tv_format_supported
[val
];
1943 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
1946 if (sdvo_priv
->left_property
== property
) {
1947 drm_connector_property_set_value(connector
,
1948 sdvo_priv
->right_property
, val
);
1949 if (sdvo_priv
->left_margin
== temp_value
)
1952 sdvo_priv
->left_margin
= temp_value
;
1953 sdvo_priv
->right_margin
= temp_value
;
1954 temp_value
= sdvo_priv
->max_hscan
-
1955 sdvo_priv
->left_margin
;
1956 cmd
= SDVO_CMD_SET_OVERSCAN_H
;
1957 } else if (sdvo_priv
->right_property
== property
) {
1958 drm_connector_property_set_value(connector
,
1959 sdvo_priv
->left_property
, val
);
1960 if (sdvo_priv
->right_margin
== temp_value
)
1963 sdvo_priv
->left_margin
= temp_value
;
1964 sdvo_priv
->right_margin
= temp_value
;
1965 temp_value
= sdvo_priv
->max_hscan
-
1966 sdvo_priv
->left_margin
;
1967 cmd
= SDVO_CMD_SET_OVERSCAN_H
;
1968 } else if (sdvo_priv
->top_property
== property
) {
1969 drm_connector_property_set_value(connector
,
1970 sdvo_priv
->bottom_property
, val
);
1971 if (sdvo_priv
->top_margin
== temp_value
)
1974 sdvo_priv
->top_margin
= temp_value
;
1975 sdvo_priv
->bottom_margin
= temp_value
;
1976 temp_value
= sdvo_priv
->max_vscan
-
1977 sdvo_priv
->top_margin
;
1978 cmd
= SDVO_CMD_SET_OVERSCAN_V
;
1979 } else if (sdvo_priv
->bottom_property
== property
) {
1980 drm_connector_property_set_value(connector
,
1981 sdvo_priv
->top_property
, val
);
1982 if (sdvo_priv
->bottom_margin
== temp_value
)
1984 sdvo_priv
->top_margin
= temp_value
;
1985 sdvo_priv
->bottom_margin
= temp_value
;
1986 temp_value
= sdvo_priv
->max_vscan
-
1987 sdvo_priv
->top_margin
;
1988 cmd
= SDVO_CMD_SET_OVERSCAN_V
;
1989 } else if (sdvo_priv
->hpos_property
== property
) {
1990 if (sdvo_priv
->cur_hpos
== temp_value
)
1993 cmd
= SDVO_CMD_SET_POSITION_H
;
1994 sdvo_priv
->cur_hpos
= temp_value
;
1995 } else if (sdvo_priv
->vpos_property
== property
) {
1996 if (sdvo_priv
->cur_vpos
== temp_value
)
1999 cmd
= SDVO_CMD_SET_POSITION_V
;
2000 sdvo_priv
->cur_vpos
= temp_value
;
2001 } else if (sdvo_priv
->saturation_property
== property
) {
2002 if (sdvo_priv
->cur_saturation
== temp_value
)
2005 cmd
= SDVO_CMD_SET_SATURATION
;
2006 sdvo_priv
->cur_saturation
= temp_value
;
2007 } else if (sdvo_priv
->contrast_property
== property
) {
2008 if (sdvo_priv
->cur_contrast
== temp_value
)
2011 cmd
= SDVO_CMD_SET_CONTRAST
;
2012 sdvo_priv
->cur_contrast
= temp_value
;
2013 } else if (sdvo_priv
->hue_property
== property
) {
2014 if (sdvo_priv
->cur_hue
== temp_value
)
2017 cmd
= SDVO_CMD_SET_HUE
;
2018 sdvo_priv
->cur_hue
= temp_value
;
2019 } else if (sdvo_priv
->brightness_property
== property
) {
2020 if (sdvo_priv
->cur_brightness
== temp_value
)
2023 cmd
= SDVO_CMD_SET_BRIGHTNESS
;
2024 sdvo_priv
->cur_brightness
= temp_value
;
2027 intel_sdvo_write_cmd(intel_output
, cmd
, &temp_value
, 2);
2028 status
= intel_sdvo_read_response(intel_output
,
2030 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2031 DRM_DEBUG_KMS("Incorrect SDVO command \n");
2037 if (changed
&& crtc
)
2038 drm_crtc_helper_set_mode(crtc
, &crtc
->mode
, crtc
->x
,
2044 static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs
= {
2045 .dpms
= intel_sdvo_dpms
,
2046 .mode_fixup
= intel_sdvo_mode_fixup
,
2047 .prepare
= intel_encoder_prepare
,
2048 .mode_set
= intel_sdvo_mode_set
,
2049 .commit
= intel_encoder_commit
,
2052 static const struct drm_connector_funcs intel_sdvo_connector_funcs
= {
2053 .dpms
= drm_helper_connector_dpms
,
2054 .save
= intel_sdvo_save
,
2055 .restore
= intel_sdvo_restore
,
2056 .detect
= intel_sdvo_detect
,
2057 .fill_modes
= drm_helper_probe_single_connector_modes
,
2058 .set_property
= intel_sdvo_set_property
,
2059 .destroy
= intel_sdvo_destroy
,
2062 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs
= {
2063 .get_modes
= intel_sdvo_get_modes
,
2064 .mode_valid
= intel_sdvo_mode_valid
,
2065 .best_encoder
= intel_best_encoder
,
2068 static void intel_sdvo_enc_destroy(struct drm_encoder
*encoder
)
2070 drm_encoder_cleanup(encoder
);
2073 static const struct drm_encoder_funcs intel_sdvo_enc_funcs
= {
2074 .destroy
= intel_sdvo_enc_destroy
,
2079 * Choose the appropriate DDC bus for control bus switch command for this
2080 * SDVO output based on the controlled output.
2082 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2083 * outputs, then LVDS outputs.
2086 intel_sdvo_select_ddc_bus(struct intel_sdvo_priv
*dev_priv
)
2089 unsigned int num_bits
;
2091 /* Make a mask of outputs less than or equal to our own priority in the
2094 switch (dev_priv
->controlled_output
) {
2095 case SDVO_OUTPUT_LVDS1
:
2096 mask
|= SDVO_OUTPUT_LVDS1
;
2097 case SDVO_OUTPUT_LVDS0
:
2098 mask
|= SDVO_OUTPUT_LVDS0
;
2099 case SDVO_OUTPUT_TMDS1
:
2100 mask
|= SDVO_OUTPUT_TMDS1
;
2101 case SDVO_OUTPUT_TMDS0
:
2102 mask
|= SDVO_OUTPUT_TMDS0
;
2103 case SDVO_OUTPUT_RGB1
:
2104 mask
|= SDVO_OUTPUT_RGB1
;
2105 case SDVO_OUTPUT_RGB0
:
2106 mask
|= SDVO_OUTPUT_RGB0
;
2110 /* Count bits to find what number we are in the priority list. */
2111 mask
&= dev_priv
->caps
.output_flags
;
2112 num_bits
= hweight16(mask
);
2114 /* if more than 3 outputs, default to DDC bus 3 for now */
2118 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2119 dev_priv
->ddc_bus
= 1 << num_bits
;
2123 intel_sdvo_get_digital_encoding_mode(struct intel_output
*output
)
2125 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
2128 intel_sdvo_set_target_output(output
, sdvo_priv
->controlled_output
);
2130 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_ENCODE
, NULL
, 0);
2131 status
= intel_sdvo_read_response(output
, &sdvo_priv
->is_hdmi
, 1);
2132 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
2137 static struct intel_output
*
2138 intel_sdvo_chan_to_intel_output(struct intel_i2c_chan
*chan
)
2140 struct drm_device
*dev
= chan
->drm_dev
;
2141 struct drm_connector
*connector
;
2142 struct intel_output
*intel_output
= NULL
;
2144 list_for_each_entry(connector
,
2145 &dev
->mode_config
.connector_list
, head
) {
2146 if (to_intel_output(connector
)->ddc_bus
== &chan
->adapter
) {
2147 intel_output
= to_intel_output(connector
);
2151 return intel_output
;
2154 static int intel_sdvo_master_xfer(struct i2c_adapter
*i2c_adap
,
2155 struct i2c_msg msgs
[], int num
)
2157 struct intel_output
*intel_output
;
2158 struct intel_sdvo_priv
*sdvo_priv
;
2159 struct i2c_algo_bit_data
*algo_data
;
2160 const struct i2c_algorithm
*algo
;
2162 algo_data
= (struct i2c_algo_bit_data
*)i2c_adap
->algo_data
;
2164 intel_sdvo_chan_to_intel_output(
2165 (struct intel_i2c_chan
*)(algo_data
->data
));
2166 if (intel_output
== NULL
)
2169 sdvo_priv
= intel_output
->dev_priv
;
2170 algo
= intel_output
->i2c_bus
->algo
;
2172 intel_sdvo_set_control_bus_switch(intel_output
, sdvo_priv
->ddc_bus
);
2173 return algo
->master_xfer(i2c_adap
, msgs
, num
);
2176 static struct i2c_algorithm intel_sdvo_i2c_bit_algo
= {
2177 .master_xfer
= intel_sdvo_master_xfer
,
2181 intel_sdvo_get_slave_addr(struct drm_device
*dev
, int output_device
)
2183 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2184 struct sdvo_device_mapping
*my_mapping
, *other_mapping
;
2186 if (output_device
== SDVOB
) {
2187 my_mapping
= &dev_priv
->sdvo_mappings
[0];
2188 other_mapping
= &dev_priv
->sdvo_mappings
[1];
2190 my_mapping
= &dev_priv
->sdvo_mappings
[1];
2191 other_mapping
= &dev_priv
->sdvo_mappings
[0];
2194 /* If the BIOS described our SDVO device, take advantage of it. */
2195 if (my_mapping
->slave_addr
)
2196 return my_mapping
->slave_addr
;
2198 /* If the BIOS only described a different SDVO device, use the
2199 * address that it isn't using.
2201 if (other_mapping
->slave_addr
) {
2202 if (other_mapping
->slave_addr
== 0x70)
2208 /* No SDVO device info is found for another DVO port,
2209 * so use mapping assumption we had before BIOS parsing.
2211 if (output_device
== SDVOB
)
2218 intel_sdvo_output_setup(struct intel_output
*intel_output
, uint16_t flags
)
2220 struct drm_connector
*connector
= &intel_output
->base
;
2221 struct drm_encoder
*encoder
= &intel_output
->enc
;
2222 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
2223 bool ret
= true, registered
= false;
2225 sdvo_priv
->is_tv
= false;
2226 intel_output
->needs_tv_clock
= false;
2227 sdvo_priv
->is_lvds
= false;
2229 if (device_is_registered(&connector
->kdev
)) {
2230 drm_sysfs_connector_remove(connector
);
2235 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
)) {
2236 if (sdvo_priv
->caps
.output_flags
& SDVO_OUTPUT_TMDS0
)
2237 sdvo_priv
->controlled_output
= SDVO_OUTPUT_TMDS0
;
2239 sdvo_priv
->controlled_output
= SDVO_OUTPUT_TMDS1
;
2241 encoder
->encoder_type
= DRM_MODE_ENCODER_TMDS
;
2242 connector
->connector_type
= DRM_MODE_CONNECTOR_DVID
;
2244 if (intel_sdvo_get_supp_encode(intel_output
,
2245 &sdvo_priv
->encode
) &&
2246 intel_sdvo_get_digital_encoding_mode(intel_output
) &&
2247 sdvo_priv
->is_hdmi
) {
2248 /* enable hdmi encoding mode if supported */
2249 intel_sdvo_set_encode(intel_output
, SDVO_ENCODE_HDMI
);
2250 intel_sdvo_set_colorimetry(intel_output
,
2251 SDVO_COLORIMETRY_RGB256
);
2252 connector
->connector_type
= DRM_MODE_CONNECTOR_HDMIA
;
2253 intel_output
->clone_mask
=
2254 (1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2255 (1 << INTEL_ANALOG_CLONE_BIT
);
2257 } else if (flags
& SDVO_OUTPUT_SVID0
) {
2259 sdvo_priv
->controlled_output
= SDVO_OUTPUT_SVID0
;
2260 encoder
->encoder_type
= DRM_MODE_ENCODER_TVDAC
;
2261 connector
->connector_type
= DRM_MODE_CONNECTOR_SVIDEO
;
2262 sdvo_priv
->is_tv
= true;
2263 intel_output
->needs_tv_clock
= true;
2264 intel_output
->clone_mask
= 1 << INTEL_SDVO_TV_CLONE_BIT
;
2265 } else if (flags
& SDVO_OUTPUT_RGB0
) {
2267 sdvo_priv
->controlled_output
= SDVO_OUTPUT_RGB0
;
2268 encoder
->encoder_type
= DRM_MODE_ENCODER_DAC
;
2269 connector
->connector_type
= DRM_MODE_CONNECTOR_VGA
;
2270 intel_output
->clone_mask
= (1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2271 (1 << INTEL_ANALOG_CLONE_BIT
);
2272 } else if (flags
& SDVO_OUTPUT_RGB1
) {
2274 sdvo_priv
->controlled_output
= SDVO_OUTPUT_RGB1
;
2275 encoder
->encoder_type
= DRM_MODE_ENCODER_DAC
;
2276 connector
->connector_type
= DRM_MODE_CONNECTOR_VGA
;
2277 intel_output
->clone_mask
= (1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2278 (1 << INTEL_ANALOG_CLONE_BIT
);
2279 } else if (flags
& SDVO_OUTPUT_LVDS0
) {
2281 sdvo_priv
->controlled_output
= SDVO_OUTPUT_LVDS0
;
2282 encoder
->encoder_type
= DRM_MODE_ENCODER_LVDS
;
2283 connector
->connector_type
= DRM_MODE_CONNECTOR_LVDS
;
2284 sdvo_priv
->is_lvds
= true;
2285 intel_output
->clone_mask
= (1 << INTEL_ANALOG_CLONE_BIT
) |
2286 (1 << INTEL_SDVO_LVDS_CLONE_BIT
);
2287 } else if (flags
& SDVO_OUTPUT_LVDS1
) {
2289 sdvo_priv
->controlled_output
= SDVO_OUTPUT_LVDS1
;
2290 encoder
->encoder_type
= DRM_MODE_ENCODER_LVDS
;
2291 connector
->connector_type
= DRM_MODE_CONNECTOR_LVDS
;
2292 sdvo_priv
->is_lvds
= true;
2293 intel_output
->clone_mask
= (1 << INTEL_ANALOG_CLONE_BIT
) |
2294 (1 << INTEL_SDVO_LVDS_CLONE_BIT
);
2297 unsigned char bytes
[2];
2299 sdvo_priv
->controlled_output
= 0;
2300 memcpy(bytes
, &sdvo_priv
->caps
.output_flags
, 2);
2301 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2302 SDVO_NAME(sdvo_priv
),
2303 bytes
[0], bytes
[1]);
2306 intel_output
->crtc_mask
= (1 << 0) | (1 << 1);
2308 if (ret
&& registered
)
2309 ret
= drm_sysfs_connector_add(connector
) == 0 ? true : false;
2316 static void intel_sdvo_tv_create_property(struct drm_connector
*connector
)
2318 struct intel_output
*intel_output
= to_intel_output(connector
);
2319 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
2320 struct intel_sdvo_tv_format format
;
2321 uint32_t format_map
, i
;
2324 intel_sdvo_set_target_output(intel_output
,
2325 sdvo_priv
->controlled_output
);
2327 intel_sdvo_write_cmd(intel_output
,
2328 SDVO_CMD_GET_SUPPORTED_TV_FORMATS
, NULL
, 0);
2329 status
= intel_sdvo_read_response(intel_output
,
2330 &format
, sizeof(format
));
2331 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
2334 memcpy(&format_map
, &format
, sizeof(format
) > sizeof(format_map
) ?
2335 sizeof(format_map
) : sizeof(format
));
2337 if (format_map
== 0)
2340 sdvo_priv
->format_supported_num
= 0;
2341 for (i
= 0 ; i
< TV_FORMAT_NUM
; i
++)
2342 if (format_map
& (1 << i
)) {
2343 sdvo_priv
->tv_format_supported
2344 [sdvo_priv
->format_supported_num
++] =
2349 sdvo_priv
->tv_format_property
=
2350 drm_property_create(
2351 connector
->dev
, DRM_MODE_PROP_ENUM
,
2352 "mode", sdvo_priv
->format_supported_num
);
2354 for (i
= 0; i
< sdvo_priv
->format_supported_num
; i
++)
2355 drm_property_add_enum(
2356 sdvo_priv
->tv_format_property
, i
,
2357 i
, sdvo_priv
->tv_format_supported
[i
]);
2359 sdvo_priv
->tv_format_name
= sdvo_priv
->tv_format_supported
[0];
2360 drm_connector_attach_property(
2361 connector
, sdvo_priv
->tv_format_property
, 0);
2365 static void intel_sdvo_create_enhance_property(struct drm_connector
*connector
)
2367 struct intel_output
*intel_output
= to_intel_output(connector
);
2368 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
2369 struct intel_sdvo_enhancements_reply sdvo_data
;
2370 struct drm_device
*dev
= connector
->dev
;
2372 uint16_t response
, data_value
[2];
2374 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
,
2376 status
= intel_sdvo_read_response(intel_output
, &sdvo_data
,
2378 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2379 DRM_DEBUG_KMS(" incorrect response is returned\n");
2382 response
= *((uint16_t *)&sdvo_data
);
2384 DRM_DEBUG_KMS("No enhancement is supported\n");
2387 if (sdvo_priv
->is_tv
) {
2388 /* when horizontal overscan is supported, Add the left/right
2391 if (sdvo_data
.overscan_h
) {
2392 intel_sdvo_write_cmd(intel_output
,
2393 SDVO_CMD_GET_MAX_OVERSCAN_H
, NULL
, 0);
2394 status
= intel_sdvo_read_response(intel_output
,
2396 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2397 DRM_DEBUG_KMS("Incorrect SDVO max "
2401 intel_sdvo_write_cmd(intel_output
,
2402 SDVO_CMD_GET_OVERSCAN_H
, NULL
, 0);
2403 status
= intel_sdvo_read_response(intel_output
,
2405 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2406 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2409 sdvo_priv
->max_hscan
= data_value
[0];
2410 sdvo_priv
->left_margin
= data_value
[0] - response
;
2411 sdvo_priv
->right_margin
= sdvo_priv
->left_margin
;
2412 sdvo_priv
->left_property
=
2413 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2415 sdvo_priv
->left_property
->values
[0] = 0;
2416 sdvo_priv
->left_property
->values
[1] = data_value
[0];
2417 drm_connector_attach_property(connector
,
2418 sdvo_priv
->left_property
,
2419 sdvo_priv
->left_margin
);
2420 sdvo_priv
->right_property
=
2421 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2423 sdvo_priv
->right_property
->values
[0] = 0;
2424 sdvo_priv
->right_property
->values
[1] = data_value
[0];
2425 drm_connector_attach_property(connector
,
2426 sdvo_priv
->right_property
,
2427 sdvo_priv
->right_margin
);
2428 DRM_DEBUG_KMS("h_overscan: max %d, "
2429 "default %d, current %d\n",
2430 data_value
[0], data_value
[1], response
);
2432 if (sdvo_data
.overscan_v
) {
2433 intel_sdvo_write_cmd(intel_output
,
2434 SDVO_CMD_GET_MAX_OVERSCAN_V
, NULL
, 0);
2435 status
= intel_sdvo_read_response(intel_output
,
2437 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2438 DRM_DEBUG_KMS("Incorrect SDVO max "
2442 intel_sdvo_write_cmd(intel_output
,
2443 SDVO_CMD_GET_OVERSCAN_V
, NULL
, 0);
2444 status
= intel_sdvo_read_response(intel_output
,
2446 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2447 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2450 sdvo_priv
->max_vscan
= data_value
[0];
2451 sdvo_priv
->top_margin
= data_value
[0] - response
;
2452 sdvo_priv
->bottom_margin
= sdvo_priv
->top_margin
;
2453 sdvo_priv
->top_property
=
2454 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2456 sdvo_priv
->top_property
->values
[0] = 0;
2457 sdvo_priv
->top_property
->values
[1] = data_value
[0];
2458 drm_connector_attach_property(connector
,
2459 sdvo_priv
->top_property
,
2460 sdvo_priv
->top_margin
);
2461 sdvo_priv
->bottom_property
=
2462 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2463 "bottom_margin", 2);
2464 sdvo_priv
->bottom_property
->values
[0] = 0;
2465 sdvo_priv
->bottom_property
->values
[1] = data_value
[0];
2466 drm_connector_attach_property(connector
,
2467 sdvo_priv
->bottom_property
,
2468 sdvo_priv
->bottom_margin
);
2469 DRM_DEBUG_KMS("v_overscan: max %d, "
2470 "default %d, current %d\n",
2471 data_value
[0], data_value
[1], response
);
2473 if (sdvo_data
.position_h
) {
2474 intel_sdvo_write_cmd(intel_output
,
2475 SDVO_CMD_GET_MAX_POSITION_H
, NULL
, 0);
2476 status
= intel_sdvo_read_response(intel_output
,
2478 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2479 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2482 intel_sdvo_write_cmd(intel_output
,
2483 SDVO_CMD_GET_POSITION_H
, NULL
, 0);
2484 status
= intel_sdvo_read_response(intel_output
,
2486 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2487 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2490 sdvo_priv
->max_hpos
= data_value
[0];
2491 sdvo_priv
->cur_hpos
= response
;
2492 sdvo_priv
->hpos_property
=
2493 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2495 sdvo_priv
->hpos_property
->values
[0] = 0;
2496 sdvo_priv
->hpos_property
->values
[1] = data_value
[0];
2497 drm_connector_attach_property(connector
,
2498 sdvo_priv
->hpos_property
,
2499 sdvo_priv
->cur_hpos
);
2500 DRM_DEBUG_KMS("h_position: max %d, "
2501 "default %d, current %d\n",
2502 data_value
[0], data_value
[1], response
);
2504 if (sdvo_data
.position_v
) {
2505 intel_sdvo_write_cmd(intel_output
,
2506 SDVO_CMD_GET_MAX_POSITION_V
, NULL
, 0);
2507 status
= intel_sdvo_read_response(intel_output
,
2509 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2510 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2513 intel_sdvo_write_cmd(intel_output
,
2514 SDVO_CMD_GET_POSITION_V
, NULL
, 0);
2515 status
= intel_sdvo_read_response(intel_output
,
2517 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2518 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2521 sdvo_priv
->max_vpos
= data_value
[0];
2522 sdvo_priv
->cur_vpos
= response
;
2523 sdvo_priv
->vpos_property
=
2524 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2526 sdvo_priv
->vpos_property
->values
[0] = 0;
2527 sdvo_priv
->vpos_property
->values
[1] = data_value
[0];
2528 drm_connector_attach_property(connector
,
2529 sdvo_priv
->vpos_property
,
2530 sdvo_priv
->cur_vpos
);
2531 DRM_DEBUG_KMS("v_position: max %d, "
2532 "default %d, current %d\n",
2533 data_value
[0], data_value
[1], response
);
2536 if (sdvo_priv
->is_tv
) {
2537 if (sdvo_data
.saturation
) {
2538 intel_sdvo_write_cmd(intel_output
,
2539 SDVO_CMD_GET_MAX_SATURATION
, NULL
, 0);
2540 status
= intel_sdvo_read_response(intel_output
,
2542 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2543 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2546 intel_sdvo_write_cmd(intel_output
,
2547 SDVO_CMD_GET_SATURATION
, NULL
, 0);
2548 status
= intel_sdvo_read_response(intel_output
,
2550 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2551 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2554 sdvo_priv
->max_saturation
= data_value
[0];
2555 sdvo_priv
->cur_saturation
= response
;
2556 sdvo_priv
->saturation_property
=
2557 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2559 sdvo_priv
->saturation_property
->values
[0] = 0;
2560 sdvo_priv
->saturation_property
->values
[1] =
2562 drm_connector_attach_property(connector
,
2563 sdvo_priv
->saturation_property
,
2564 sdvo_priv
->cur_saturation
);
2565 DRM_DEBUG_KMS("saturation: max %d, "
2566 "default %d, current %d\n",
2567 data_value
[0], data_value
[1], response
);
2569 if (sdvo_data
.contrast
) {
2570 intel_sdvo_write_cmd(intel_output
,
2571 SDVO_CMD_GET_MAX_CONTRAST
, NULL
, 0);
2572 status
= intel_sdvo_read_response(intel_output
,
2574 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2575 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2578 intel_sdvo_write_cmd(intel_output
,
2579 SDVO_CMD_GET_CONTRAST
, NULL
, 0);
2580 status
= intel_sdvo_read_response(intel_output
,
2582 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2583 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2586 sdvo_priv
->max_contrast
= data_value
[0];
2587 sdvo_priv
->cur_contrast
= response
;
2588 sdvo_priv
->contrast_property
=
2589 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2591 sdvo_priv
->contrast_property
->values
[0] = 0;
2592 sdvo_priv
->contrast_property
->values
[1] = data_value
[0];
2593 drm_connector_attach_property(connector
,
2594 sdvo_priv
->contrast_property
,
2595 sdvo_priv
->cur_contrast
);
2596 DRM_DEBUG_KMS("contrast: max %d, "
2597 "default %d, current %d\n",
2598 data_value
[0], data_value
[1], response
);
2600 if (sdvo_data
.hue
) {
2601 intel_sdvo_write_cmd(intel_output
,
2602 SDVO_CMD_GET_MAX_HUE
, NULL
, 0);
2603 status
= intel_sdvo_read_response(intel_output
,
2605 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2606 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2609 intel_sdvo_write_cmd(intel_output
,
2610 SDVO_CMD_GET_HUE
, NULL
, 0);
2611 status
= intel_sdvo_read_response(intel_output
,
2613 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2614 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2617 sdvo_priv
->max_hue
= data_value
[0];
2618 sdvo_priv
->cur_hue
= response
;
2619 sdvo_priv
->hue_property
=
2620 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2622 sdvo_priv
->hue_property
->values
[0] = 0;
2623 sdvo_priv
->hue_property
->values
[1] =
2625 drm_connector_attach_property(connector
,
2626 sdvo_priv
->hue_property
,
2627 sdvo_priv
->cur_hue
);
2628 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2629 data_value
[0], data_value
[1], response
);
2632 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
2633 if (sdvo_data
.brightness
) {
2634 intel_sdvo_write_cmd(intel_output
,
2635 SDVO_CMD_GET_MAX_BRIGHTNESS
, NULL
, 0);
2636 status
= intel_sdvo_read_response(intel_output
,
2638 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2639 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2642 intel_sdvo_write_cmd(intel_output
,
2643 SDVO_CMD_GET_BRIGHTNESS
, NULL
, 0);
2644 status
= intel_sdvo_read_response(intel_output
,
2646 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2647 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2650 sdvo_priv
->max_brightness
= data_value
[0];
2651 sdvo_priv
->cur_brightness
= response
;
2652 sdvo_priv
->brightness_property
=
2653 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2655 sdvo_priv
->brightness_property
->values
[0] = 0;
2656 sdvo_priv
->brightness_property
->values
[1] =
2658 drm_connector_attach_property(connector
,
2659 sdvo_priv
->brightness_property
,
2660 sdvo_priv
->cur_brightness
);
2661 DRM_DEBUG_KMS("brightness: max %d, "
2662 "default %d, current %d\n",
2663 data_value
[0], data_value
[1], response
);
2669 bool intel_sdvo_init(struct drm_device
*dev
, int output_device
)
2671 struct drm_connector
*connector
;
2672 struct intel_output
*intel_output
;
2673 struct intel_sdvo_priv
*sdvo_priv
;
2678 intel_output
= kcalloc(sizeof(struct intel_output
)+sizeof(struct intel_sdvo_priv
), 1, GFP_KERNEL
);
2679 if (!intel_output
) {
2683 sdvo_priv
= (struct intel_sdvo_priv
*)(intel_output
+ 1);
2684 sdvo_priv
->output_device
= output_device
;
2686 intel_output
->dev_priv
= sdvo_priv
;
2687 intel_output
->type
= INTEL_OUTPUT_SDVO
;
2689 /* setup the DDC bus. */
2690 if (output_device
== SDVOB
)
2691 intel_output
->i2c_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOCTRL_E for SDVOB");
2693 intel_output
->i2c_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOCTRL_E for SDVOC");
2695 if (!intel_output
->i2c_bus
)
2696 goto err_inteloutput
;
2698 sdvo_priv
->slave_addr
= intel_sdvo_get_slave_addr(dev
, output_device
);
2700 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
2701 intel_sdvo_i2c_bit_algo
.functionality
= intel_output
->i2c_bus
->algo
->functionality
;
2703 /* Read the regs to test if we can talk to the device */
2704 for (i
= 0; i
< 0x40; i
++) {
2705 if (!intel_sdvo_read_byte(intel_output
, i
, &ch
[i
])) {
2706 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
2707 output_device
== SDVOB
? 'B' : 'C');
2712 /* setup the DDC bus. */
2713 if (output_device
== SDVOB
) {
2714 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOB DDC BUS");
2715 sdvo_priv
->analog_ddc_bus
= intel_i2c_create(dev
, GPIOA
,
2716 "SDVOB/VGA DDC BUS");
2718 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOC DDC BUS");
2719 sdvo_priv
->analog_ddc_bus
= intel_i2c_create(dev
, GPIOA
,
2720 "SDVOC/VGA DDC BUS");
2723 if (intel_output
->ddc_bus
== NULL
)
2726 /* Wrap with our custom algo which switches to DDC mode */
2727 intel_output
->ddc_bus
->algo
= &intel_sdvo_i2c_bit_algo
;
2729 /* In defaut case sdvo lvds is false */
2730 intel_sdvo_get_capabilities(intel_output
, &sdvo_priv
->caps
);
2732 if (intel_sdvo_output_setup(intel_output
,
2733 sdvo_priv
->caps
.output_flags
) != true) {
2734 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
2735 output_device
== SDVOB
? 'B' : 'C');
2740 connector
= &intel_output
->base
;
2741 drm_connector_init(dev
, connector
, &intel_sdvo_connector_funcs
,
2742 connector
->connector_type
);
2744 drm_connector_helper_add(connector
, &intel_sdvo_connector_helper_funcs
);
2745 connector
->interlace_allowed
= 0;
2746 connector
->doublescan_allowed
= 0;
2747 connector
->display_info
.subpixel_order
= SubPixelHorizontalRGB
;
2749 drm_encoder_init(dev
, &intel_output
->enc
,
2750 &intel_sdvo_enc_funcs
, intel_output
->enc
.encoder_type
);
2752 drm_encoder_helper_add(&intel_output
->enc
, &intel_sdvo_helper_funcs
);
2754 drm_mode_connector_attach_encoder(&intel_output
->base
, &intel_output
->enc
);
2755 if (sdvo_priv
->is_tv
)
2756 intel_sdvo_tv_create_property(connector
);
2758 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
)
2759 intel_sdvo_create_enhance_property(connector
);
2761 drm_sysfs_connector_add(connector
);
2763 intel_sdvo_select_ddc_bus(sdvo_priv
);
2765 /* Set the input timing to the screen. Assume always input 0. */
2766 intel_sdvo_set_target_input(intel_output
, true, false);
2768 intel_sdvo_get_input_pixel_clock_range(intel_output
,
2769 &sdvo_priv
->pixel_clock_min
,
2770 &sdvo_priv
->pixel_clock_max
);
2773 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
2774 "clock range %dMHz - %dMHz, "
2775 "input 1: %c, input 2: %c, "
2776 "output 1: %c, output 2: %c\n",
2777 SDVO_NAME(sdvo_priv
),
2778 sdvo_priv
->caps
.vendor_id
, sdvo_priv
->caps
.device_id
,
2779 sdvo_priv
->caps
.device_rev_id
,
2780 sdvo_priv
->pixel_clock_min
/ 1000,
2781 sdvo_priv
->pixel_clock_max
/ 1000,
2782 (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x1) ? 'Y' : 'N',
2783 (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x2) ? 'Y' : 'N',
2784 /* check currently supported outputs */
2785 sdvo_priv
->caps
.output_flags
&
2786 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_RGB0
) ? 'Y' : 'N',
2787 sdvo_priv
->caps
.output_flags
&
2788 (SDVO_OUTPUT_TMDS1
| SDVO_OUTPUT_RGB1
) ? 'Y' : 'N');
2793 if (sdvo_priv
->analog_ddc_bus
!= NULL
)
2794 intel_i2c_destroy(sdvo_priv
->analog_ddc_bus
);
2795 if (intel_output
->ddc_bus
!= NULL
)
2796 intel_i2c_destroy(intel_output
->ddc_bus
);
2797 if (intel_output
->i2c_bus
!= NULL
)
2798 intel_i2c_destroy(intel_output
->i2c_bus
);
2800 kfree(intel_output
);