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"
38 #include <linux/dmi.h>
42 static char *tv_format_names
[] = {
43 "NTSC_M" , "NTSC_J" , "NTSC_443",
44 "PAL_B" , "PAL_D" , "PAL_G" ,
45 "PAL_H" , "PAL_I" , "PAL_M" ,
46 "PAL_N" , "PAL_NC" , "PAL_60" ,
47 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
48 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
52 #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
54 struct intel_sdvo_priv
{
57 /* Register for the SDVO device: SDVOB or SDVOC */
60 /* Active outputs controlled by this SDVO output */
61 uint16_t controlled_output
;
64 * Capabilities of the SDVO device returned by
65 * i830_sdvo_get_capabilities()
67 struct intel_sdvo_caps caps
;
69 /* Pixel clock limitations reported by the SDVO device, in kHz */
70 int pixel_clock_min
, pixel_clock_max
;
73 * For multiple function SDVO device,
74 * this is for current attached outputs.
76 uint16_t attached_output
;
79 * This is set if we're going to treat the device as TV-out.
81 * While we have these nice friendly flags for output types that ought
82 * to decide this for us, the S-Video output on our HDMI+S-Video card
83 * shows up as RGB1 (VGA).
87 /* This is for current tv format name */
90 /* This contains all current supported TV format */
91 char *tv_format_supported
[TV_FORMAT_NUM
];
92 int format_supported_num
;
93 struct drm_property
*tv_format_property
;
94 struct drm_property
*tv_format_name_property
[TV_FORMAT_NUM
];
97 * This is set if we treat the device as HDMI, instead of DVI.
102 * This is set if we detect output of sdvo device as LVDS.
107 * This is sdvo flags for input timing.
112 * This is sdvo fixed pannel mode pointer
114 struct drm_display_mode
*sdvo_lvds_fixed_mode
;
117 * Returned SDTV resolutions allowed for the current format, if the
118 * device reported it.
120 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions
;
123 * supported encoding mode, used to determine whether HDMI is
126 struct intel_sdvo_encode encode
;
128 /* DDC bus used by this SDVO output */
131 /* Mac mini hack -- use the same DDC as the analog connector */
132 struct i2c_adapter
*analog_ddc_bus
;
135 u16 save_active_outputs
;
136 struct intel_sdvo_dtd save_input_dtd_1
, save_input_dtd_2
;
137 struct intel_sdvo_dtd save_output_dtd
[16];
139 /* add the property for the SDVO-TV */
140 struct drm_property
*left_property
;
141 struct drm_property
*right_property
;
142 struct drm_property
*top_property
;
143 struct drm_property
*bottom_property
;
144 struct drm_property
*hpos_property
;
145 struct drm_property
*vpos_property
;
147 /* add the property for the SDVO-TV/LVDS */
148 struct drm_property
*brightness_property
;
149 struct drm_property
*contrast_property
;
150 struct drm_property
*saturation_property
;
151 struct drm_property
*hue_property
;
153 /* Add variable to record current setting for the above property */
154 u32 left_margin
, right_margin
, top_margin
, bottom_margin
;
155 /* this is to get the range of margin.*/
156 u32 max_hscan
, max_vscan
;
157 u32 max_hpos
, cur_hpos
;
158 u32 max_vpos
, cur_vpos
;
159 u32 cur_brightness
, max_brightness
;
160 u32 cur_contrast
, max_contrast
;
161 u32 cur_saturation
, max_saturation
;
162 u32 cur_hue
, max_hue
;
166 intel_sdvo_output_setup(struct intel_output
*intel_output
, uint16_t flags
);
169 * Writes the SDVOB or SDVOC with the given value, but always writes both
170 * SDVOB and SDVOC to work around apparent hardware issues (according to
171 * comments in the BIOS).
173 static void intel_sdvo_write_sdvox(struct intel_output
*intel_output
, u32 val
)
175 struct drm_device
*dev
= intel_output
->base
.dev
;
176 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
177 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
178 u32 bval
= val
, cval
= val
;
181 if (sdvo_priv
->output_device
== SDVOB
) {
182 cval
= I915_READ(SDVOC
);
184 bval
= I915_READ(SDVOB
);
187 * Write the registers twice for luck. Sometimes,
188 * writing them only once doesn't appear to 'stick'.
189 * The BIOS does this too. Yay, magic
191 for (i
= 0; i
< 2; i
++)
193 I915_WRITE(SDVOB
, bval
);
195 I915_WRITE(SDVOC
, cval
);
200 static bool intel_sdvo_read_byte(struct intel_output
*intel_output
, u8 addr
,
203 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
208 struct i2c_msg msgs
[] = {
210 .addr
= sdvo_priv
->slave_addr
>> 1,
216 .addr
= sdvo_priv
->slave_addr
>> 1,
226 if ((ret
= i2c_transfer(intel_output
->i2c_bus
, msgs
, 2)) == 2)
232 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret
);
236 static bool intel_sdvo_write_byte(struct intel_output
*intel_output
, int addr
,
239 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
241 struct i2c_msg msgs
[] = {
243 .addr
= sdvo_priv
->slave_addr
>> 1,
253 if (i2c_transfer(intel_output
->i2c_bus
, msgs
, 1) == 1)
260 #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
261 /** Mapping of command numbers to names, for debug output */
262 static const struct _sdvo_cmd_name
{
265 } sdvo_cmd_names
[] = {
266 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET
),
267 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS
),
268 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV
),
269 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS
),
270 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS
),
271 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS
),
272 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP
),
273 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP
),
274 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS
),
275 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT
),
276 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG
),
277 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG
),
278 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE
),
279 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT
),
280 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT
),
281 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1
),
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2
),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1
),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2
),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1
),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2
),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1
),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2
),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE
),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS
),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT
),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT
),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS
),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT
),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT
),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES
),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE
),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE
),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE
),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH
),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT
),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
),
309 /* Add the op code for SDVO enhancements */
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H
),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H
),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H
),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V
),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V
),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V
),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION
),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION
),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION
),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE
),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE
),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE
),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST
),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST
),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST
),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS
),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS
),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS
),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H
),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H
),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H
),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V
),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V
),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V
),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE
),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE
),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE
),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI
),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI
),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP
),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY
),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY
),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER
),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT
),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT
),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX
),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX
),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO
),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT
),
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT
),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE
),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE
),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA
),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA
),
357 #define SDVO_NAME(dev_priv) ((dev_priv)->output_device == SDVOB ? "SDVOB" : "SDVOC")
358 #define SDVO_PRIV(output) ((struct intel_sdvo_priv *) (output)->dev_priv)
361 static void intel_sdvo_debug_write(struct intel_output
*intel_output
, u8 cmd
,
362 void *args
, int args_len
)
364 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
367 DRM_DEBUG_KMS("%s: W: %02X ",
368 SDVO_NAME(sdvo_priv
), cmd
);
369 for (i
= 0; i
< args_len
; i
++)
370 DRM_LOG_KMS("%02X ", ((u8
*)args
)[i
]);
373 for (i
= 0; i
< sizeof(sdvo_cmd_names
) / sizeof(sdvo_cmd_names
[0]); i
++) {
374 if (cmd
== sdvo_cmd_names
[i
].cmd
) {
375 DRM_LOG_KMS("(%s)", sdvo_cmd_names
[i
].name
);
379 if (i
== sizeof(sdvo_cmd_names
)/ sizeof(sdvo_cmd_names
[0]))
380 DRM_LOG_KMS("(%02X)", cmd
);
384 #define intel_sdvo_debug_write(o, c, a, l)
387 static void intel_sdvo_write_cmd(struct intel_output
*intel_output
, u8 cmd
,
388 void *args
, int args_len
)
392 intel_sdvo_debug_write(intel_output
, cmd
, args
, args_len
);
394 for (i
= 0; i
< args_len
; i
++) {
395 intel_sdvo_write_byte(intel_output
, SDVO_I2C_ARG_0
- i
,
399 intel_sdvo_write_byte(intel_output
, SDVO_I2C_OPCODE
, cmd
);
403 static const char *cmd_status_names
[] = {
409 "Target not specified",
410 "Scaling not supported"
413 static void intel_sdvo_debug_response(struct intel_output
*intel_output
,
414 void *response
, int response_len
,
417 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
420 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv
));
421 for (i
= 0; i
< response_len
; i
++)
422 DRM_LOG_KMS("%02X ", ((u8
*)response
)[i
]);
425 if (status
<= SDVO_CMD_STATUS_SCALING_NOT_SUPP
)
426 DRM_LOG_KMS("(%s)", cmd_status_names
[status
]);
428 DRM_LOG_KMS("(??? %d)", status
);
432 #define intel_sdvo_debug_response(o, r, l, s)
435 static u8
intel_sdvo_read_response(struct intel_output
*intel_output
,
436 void *response
, int response_len
)
443 /* Read the command response */
444 for (i
= 0; i
< response_len
; i
++) {
445 intel_sdvo_read_byte(intel_output
,
446 SDVO_I2C_RETURN_0
+ i
,
447 &((u8
*)response
)[i
]);
450 /* read the return status */
451 intel_sdvo_read_byte(intel_output
, SDVO_I2C_CMD_STATUS
,
454 intel_sdvo_debug_response(intel_output
, response
, response_len
,
456 if (status
!= SDVO_CMD_STATUS_PENDING
)
465 static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode
*mode
)
467 if (mode
->clock
>= 100000)
469 else if (mode
->clock
>= 50000)
476 * Try to read the response after issuie the DDC switch command. But it
477 * is noted that we must do the action of reading response and issuing DDC
478 * switch command in one I2C transaction. Otherwise when we try to start
479 * another I2C transaction after issuing the DDC bus switch, it will be
480 * switched to the internal SDVO register.
482 static void intel_sdvo_set_control_bus_switch(struct intel_output
*intel_output
,
485 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
486 u8 out_buf
[2], cmd_buf
[2], ret_value
[2], ret
;
487 struct i2c_msg msgs
[] = {
489 .addr
= sdvo_priv
->slave_addr
>> 1,
494 /* the following two are to read the response */
496 .addr
= sdvo_priv
->slave_addr
>> 1,
502 .addr
= sdvo_priv
->slave_addr
>> 1,
509 intel_sdvo_debug_write(intel_output
, SDVO_CMD_SET_CONTROL_BUS_SWITCH
,
511 /* write the DDC switch command argument */
512 intel_sdvo_write_byte(intel_output
, SDVO_I2C_ARG_0
, target
);
514 out_buf
[0] = SDVO_I2C_OPCODE
;
515 out_buf
[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH
;
516 cmd_buf
[0] = SDVO_I2C_CMD_STATUS
;
521 ret
= i2c_transfer(intel_output
->i2c_bus
, msgs
, 3);
523 /* failure in I2C transfer */
524 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret
);
527 if (ret_value
[0] != SDVO_CMD_STATUS_SUCCESS
) {
528 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
535 static bool intel_sdvo_set_target_input(struct intel_output
*intel_output
, bool target_0
, bool target_1
)
537 struct intel_sdvo_set_target_input_args targets
= {0};
540 if (target_0
&& target_1
)
541 return SDVO_CMD_STATUS_NOTSUPP
;
544 targets
.target_1
= 1;
546 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_TARGET_INPUT
, &targets
,
549 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
551 return (status
== SDVO_CMD_STATUS_SUCCESS
);
555 * Return whether each input is trained.
557 * This function is making an assumption about the layout of the response,
558 * which should be checked against the docs.
560 static bool intel_sdvo_get_trained_inputs(struct intel_output
*intel_output
, bool *input_1
, bool *input_2
)
562 struct intel_sdvo_get_trained_inputs_response response
;
565 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_TRAINED_INPUTS
, NULL
, 0);
566 status
= intel_sdvo_read_response(intel_output
, &response
, sizeof(response
));
567 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
570 *input_1
= response
.input0_trained
;
571 *input_2
= response
.input1_trained
;
575 static bool intel_sdvo_get_active_outputs(struct intel_output
*intel_output
,
580 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_ACTIVE_OUTPUTS
, NULL
, 0);
581 status
= intel_sdvo_read_response(intel_output
, outputs
, sizeof(*outputs
));
583 return (status
== SDVO_CMD_STATUS_SUCCESS
);
586 static bool intel_sdvo_set_active_outputs(struct intel_output
*intel_output
,
591 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ACTIVE_OUTPUTS
, &outputs
,
593 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
594 return (status
== SDVO_CMD_STATUS_SUCCESS
);
597 static bool intel_sdvo_set_encoder_power_state(struct intel_output
*intel_output
,
600 u8 status
, state
= SDVO_ENCODER_STATE_ON
;
603 case DRM_MODE_DPMS_ON
:
604 state
= SDVO_ENCODER_STATE_ON
;
606 case DRM_MODE_DPMS_STANDBY
:
607 state
= SDVO_ENCODER_STATE_STANDBY
;
609 case DRM_MODE_DPMS_SUSPEND
:
610 state
= SDVO_ENCODER_STATE_SUSPEND
;
612 case DRM_MODE_DPMS_OFF
:
613 state
= SDVO_ENCODER_STATE_OFF
;
617 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ENCODER_POWER_STATE
, &state
,
619 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
621 return (status
== SDVO_CMD_STATUS_SUCCESS
);
624 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output
*intel_output
,
628 struct intel_sdvo_pixel_clock_range clocks
;
631 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
,
634 status
= intel_sdvo_read_response(intel_output
, &clocks
, sizeof(clocks
));
636 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
639 /* Convert the values from units of 10 kHz to kHz. */
640 *clock_min
= clocks
.min
* 10;
641 *clock_max
= clocks
.max
* 10;
646 static bool intel_sdvo_set_target_output(struct intel_output
*intel_output
,
651 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_TARGET_OUTPUT
, &outputs
,
654 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
655 return (status
== SDVO_CMD_STATUS_SUCCESS
);
658 static bool intel_sdvo_get_timing(struct intel_output
*intel_output
, u8 cmd
,
659 struct intel_sdvo_dtd
*dtd
)
663 intel_sdvo_write_cmd(intel_output
, cmd
, NULL
, 0);
664 status
= intel_sdvo_read_response(intel_output
, &dtd
->part1
,
666 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
669 intel_sdvo_write_cmd(intel_output
, cmd
+ 1, NULL
, 0);
670 status
= intel_sdvo_read_response(intel_output
, &dtd
->part2
,
672 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
678 static bool intel_sdvo_get_input_timing(struct intel_output
*intel_output
,
679 struct intel_sdvo_dtd
*dtd
)
681 return intel_sdvo_get_timing(intel_output
,
682 SDVO_CMD_GET_INPUT_TIMINGS_PART1
, dtd
);
685 static bool intel_sdvo_get_output_timing(struct intel_output
*intel_output
,
686 struct intel_sdvo_dtd
*dtd
)
688 return intel_sdvo_get_timing(intel_output
,
689 SDVO_CMD_GET_OUTPUT_TIMINGS_PART1
, dtd
);
692 static bool intel_sdvo_set_timing(struct intel_output
*intel_output
, u8 cmd
,
693 struct intel_sdvo_dtd
*dtd
)
697 intel_sdvo_write_cmd(intel_output
, cmd
, &dtd
->part1
, sizeof(dtd
->part1
));
698 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
699 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
702 intel_sdvo_write_cmd(intel_output
, cmd
+ 1, &dtd
->part2
, sizeof(dtd
->part2
));
703 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
704 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
710 static bool intel_sdvo_set_input_timing(struct intel_output
*intel_output
,
711 struct intel_sdvo_dtd
*dtd
)
713 return intel_sdvo_set_timing(intel_output
,
714 SDVO_CMD_SET_INPUT_TIMINGS_PART1
, dtd
);
717 static bool intel_sdvo_set_output_timing(struct intel_output
*intel_output
,
718 struct intel_sdvo_dtd
*dtd
)
720 return intel_sdvo_set_timing(intel_output
,
721 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
, dtd
);
725 intel_sdvo_create_preferred_input_timing(struct intel_output
*output
,
730 struct intel_sdvo_preferred_input_timing_args args
;
731 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
734 memset(&args
, 0, sizeof(args
));
737 args
.height
= height
;
740 if (sdvo_priv
->is_lvds
&&
741 (sdvo_priv
->sdvo_lvds_fixed_mode
->hdisplay
!= width
||
742 sdvo_priv
->sdvo_lvds_fixed_mode
->vdisplay
!= height
))
745 intel_sdvo_write_cmd(output
, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
,
746 &args
, sizeof(args
));
747 status
= intel_sdvo_read_response(output
, NULL
, 0);
748 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
754 static bool intel_sdvo_get_preferred_input_timing(struct intel_output
*output
,
755 struct intel_sdvo_dtd
*dtd
)
759 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
,
762 status
= intel_sdvo_read_response(output
, &dtd
->part1
,
764 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
767 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
,
770 status
= intel_sdvo_read_response(output
, &dtd
->part2
,
772 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
778 static int intel_sdvo_get_clock_rate_mult(struct intel_output
*intel_output
)
782 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_CLOCK_RATE_MULT
, NULL
, 0);
783 status
= intel_sdvo_read_response(intel_output
, &response
, 1);
785 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
786 DRM_DEBUG_KMS("Couldn't get SDVO clock rate multiplier\n");
787 return SDVO_CLOCK_RATE_MULT_1X
;
789 DRM_DEBUG_KMS("Current clock rate multiplier: %d\n", response
);
795 static bool intel_sdvo_set_clock_rate_mult(struct intel_output
*intel_output
, u8 val
)
799 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_CLOCK_RATE_MULT
, &val
, 1);
800 status
= intel_sdvo_read_response(intel_output
, NULL
, 0);
801 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
807 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd
*dtd
,
808 struct drm_display_mode
*mode
)
810 uint16_t width
, height
;
811 uint16_t h_blank_len
, h_sync_len
, v_blank_len
, v_sync_len
;
812 uint16_t h_sync_offset
, v_sync_offset
;
814 width
= mode
->crtc_hdisplay
;
815 height
= mode
->crtc_vdisplay
;
817 /* do some mode translations */
818 h_blank_len
= mode
->crtc_hblank_end
- mode
->crtc_hblank_start
;
819 h_sync_len
= mode
->crtc_hsync_end
- mode
->crtc_hsync_start
;
821 v_blank_len
= mode
->crtc_vblank_end
- mode
->crtc_vblank_start
;
822 v_sync_len
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
;
824 h_sync_offset
= mode
->crtc_hsync_start
- mode
->crtc_hblank_start
;
825 v_sync_offset
= mode
->crtc_vsync_start
- mode
->crtc_vblank_start
;
827 dtd
->part1
.clock
= mode
->clock
/ 10;
828 dtd
->part1
.h_active
= width
& 0xff;
829 dtd
->part1
.h_blank
= h_blank_len
& 0xff;
830 dtd
->part1
.h_high
= (((width
>> 8) & 0xf) << 4) |
831 ((h_blank_len
>> 8) & 0xf);
832 dtd
->part1
.v_active
= height
& 0xff;
833 dtd
->part1
.v_blank
= v_blank_len
& 0xff;
834 dtd
->part1
.v_high
= (((height
>> 8) & 0xf) << 4) |
835 ((v_blank_len
>> 8) & 0xf);
837 dtd
->part2
.h_sync_off
= h_sync_offset
& 0xff;
838 dtd
->part2
.h_sync_width
= h_sync_len
& 0xff;
839 dtd
->part2
.v_sync_off_width
= (v_sync_offset
& 0xf) << 4 |
841 dtd
->part2
.sync_off_width_high
= ((h_sync_offset
& 0x300) >> 2) |
842 ((h_sync_len
& 0x300) >> 4) | ((v_sync_offset
& 0x30) >> 2) |
843 ((v_sync_len
& 0x30) >> 4);
845 dtd
->part2
.dtd_flags
= 0x18;
846 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
847 dtd
->part2
.dtd_flags
|= 0x2;
848 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
849 dtd
->part2
.dtd_flags
|= 0x4;
851 dtd
->part2
.sdvo_flags
= 0;
852 dtd
->part2
.v_sync_off_high
= v_sync_offset
& 0xc0;
853 dtd
->part2
.reserved
= 0;
856 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode
* mode
,
857 struct intel_sdvo_dtd
*dtd
)
859 mode
->hdisplay
= dtd
->part1
.h_active
;
860 mode
->hdisplay
+= ((dtd
->part1
.h_high
>> 4) & 0x0f) << 8;
861 mode
->hsync_start
= mode
->hdisplay
+ dtd
->part2
.h_sync_off
;
862 mode
->hsync_start
+= (dtd
->part2
.sync_off_width_high
& 0xc0) << 2;
863 mode
->hsync_end
= mode
->hsync_start
+ dtd
->part2
.h_sync_width
;
864 mode
->hsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x30) << 4;
865 mode
->htotal
= mode
->hdisplay
+ dtd
->part1
.h_blank
;
866 mode
->htotal
+= (dtd
->part1
.h_high
& 0xf) << 8;
868 mode
->vdisplay
= dtd
->part1
.v_active
;
869 mode
->vdisplay
+= ((dtd
->part1
.v_high
>> 4) & 0x0f) << 8;
870 mode
->vsync_start
= mode
->vdisplay
;
871 mode
->vsync_start
+= (dtd
->part2
.v_sync_off_width
>> 4) & 0xf;
872 mode
->vsync_start
+= (dtd
->part2
.sync_off_width_high
& 0x0c) << 2;
873 mode
->vsync_start
+= dtd
->part2
.v_sync_off_high
& 0xc0;
874 mode
->vsync_end
= mode
->vsync_start
+
875 (dtd
->part2
.v_sync_off_width
& 0xf);
876 mode
->vsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x3) << 4;
877 mode
->vtotal
= mode
->vdisplay
+ dtd
->part1
.v_blank
;
878 mode
->vtotal
+= (dtd
->part1
.v_high
& 0xf) << 8;
880 mode
->clock
= dtd
->part1
.clock
* 10;
882 mode
->flags
&= ~(DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
);
883 if (dtd
->part2
.dtd_flags
& 0x2)
884 mode
->flags
|= DRM_MODE_FLAG_PHSYNC
;
885 if (dtd
->part2
.dtd_flags
& 0x4)
886 mode
->flags
|= DRM_MODE_FLAG_PVSYNC
;
889 static bool intel_sdvo_get_supp_encode(struct intel_output
*output
,
890 struct intel_sdvo_encode
*encode
)
894 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_SUPP_ENCODE
, NULL
, 0);
895 status
= intel_sdvo_read_response(output
, encode
, sizeof(*encode
));
896 if (status
!= SDVO_CMD_STATUS_SUCCESS
) { /* non-support means DVI */
897 memset(encode
, 0, sizeof(*encode
));
904 static bool intel_sdvo_set_encode(struct intel_output
*output
, uint8_t mode
)
908 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_ENCODE
, &mode
, 1);
909 status
= intel_sdvo_read_response(output
, NULL
, 0);
911 return (status
== SDVO_CMD_STATUS_SUCCESS
);
914 static bool intel_sdvo_set_colorimetry(struct intel_output
*output
,
919 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_COLORIMETRY
, &mode
, 1);
920 status
= intel_sdvo_read_response(output
, NULL
, 0);
922 return (status
== SDVO_CMD_STATUS_SUCCESS
);
926 static void intel_sdvo_dump_hdmi_buf(struct intel_output
*output
)
929 uint8_t set_buf_index
[2];
935 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_HBUF_AV_SPLIT
, NULL
, 0);
936 intel_sdvo_read_response(output
, &av_split
, 1);
938 for (i
= 0; i
<= av_split
; i
++) {
939 set_buf_index
[0] = i
; set_buf_index
[1] = 0;
940 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_INDEX
,
942 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_HBUF_INFO
, NULL
, 0);
943 intel_sdvo_read_response(output
, &buf_size
, 1);
946 for (j
= 0; j
<= buf_size
; j
+= 8) {
947 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_HBUF_DATA
,
949 intel_sdvo_read_response(output
, pos
, 8);
956 static void intel_sdvo_set_hdmi_buf(struct intel_output
*output
, int index
,
957 uint8_t *data
, int8_t size
, uint8_t tx_rate
)
959 uint8_t set_buf_index
[2];
961 set_buf_index
[0] = index
;
962 set_buf_index
[1] = 0;
964 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_INDEX
, set_buf_index
, 2);
966 for (; size
> 0; size
-= 8) {
967 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_DATA
, data
, 8);
971 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_HBUF_TXRATE
, &tx_rate
, 1);
974 static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data
, uint8_t size
)
979 for (i
= 0; i
< size
; i
++)
985 #define DIP_TYPE_AVI 0x82
986 #define DIP_VERSION_AVI 0x2
987 #define DIP_LEN_AVI 13
989 struct dip_infoframe
{
1002 /* Packet Byte #2 */
1006 /* Packet Byte #3 */
1011 /* Packet Byte #4 */
1014 /* Packet Byte #5 */
1017 /* Packet Byte #6~13 */
1018 uint16_t top_bar_end
;
1019 uint16_t bottom_bar_start
;
1020 uint16_t left_bar_end
;
1021 uint16_t right_bar_start
;
1024 /* Packet Byte #1 */
1025 uint8_t channel_count
:3;
1027 uint8_t coding_type
:4;
1028 /* Packet Byte #2 */
1029 uint8_t sample_size
:2; /* SS0, SS1 */
1030 uint8_t sample_frequency
:3;
1032 /* Packet Byte #3 */
1033 uint8_t coding_type_private
:5;
1035 /* Packet Byte #4 */
1036 uint8_t channel_allocation
;
1037 /* Packet Byte #5 */
1039 uint8_t level_shift
:4;
1040 uint8_t downmix_inhibit
:1;
1042 uint8_t payload
[28];
1043 } __attribute__ ((packed
)) u
;
1044 } __attribute__((packed
));
1046 static void intel_sdvo_set_avi_infoframe(struct intel_output
*output
,
1047 struct drm_display_mode
* mode
)
1049 struct dip_infoframe avi_if
= {
1050 .type
= DIP_TYPE_AVI
,
1051 .version
= DIP_VERSION_AVI
,
1055 avi_if
.checksum
= intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if
,
1057 intel_sdvo_set_hdmi_buf(output
, 1, (uint8_t *)&avi_if
, 4 + avi_if
.len
,
1058 SDVO_HBUF_TX_VSYNC
);
1061 static void intel_sdvo_set_tv_format(struct intel_output
*output
)
1064 struct intel_sdvo_tv_format format
;
1065 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1066 uint32_t format_map
, i
;
1069 for (i
= 0; i
< TV_FORMAT_NUM
; i
++)
1070 if (tv_format_names
[i
] == sdvo_priv
->tv_format_name
)
1073 format_map
= 1 << i
;
1074 memset(&format
, 0, sizeof(format
));
1075 memcpy(&format
, &format_map
, sizeof(format_map
) > sizeof(format
) ?
1076 sizeof(format
) : sizeof(format_map
));
1078 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_TV_FORMAT
, &format_map
,
1081 status
= intel_sdvo_read_response(output
, NULL
, 0);
1082 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1083 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
1084 SDVO_NAME(sdvo_priv
));
1087 static bool intel_sdvo_mode_fixup(struct drm_encoder
*encoder
,
1088 struct drm_display_mode
*mode
,
1089 struct drm_display_mode
*adjusted_mode
)
1091 struct intel_output
*output
= enc_to_intel_output(encoder
);
1092 struct intel_sdvo_priv
*dev_priv
= output
->dev_priv
;
1094 if (dev_priv
->is_tv
) {
1095 struct intel_sdvo_dtd output_dtd
;
1098 /* We need to construct preferred input timings based on our
1099 * output timings. To do that, we have to set the output
1100 * timings, even though this isn't really the right place in
1101 * the sequence to do it. Oh well.
1105 /* Set output timings */
1106 intel_sdvo_get_dtd_from_mode(&output_dtd
, mode
);
1107 intel_sdvo_set_target_output(output
,
1108 dev_priv
->controlled_output
);
1109 intel_sdvo_set_output_timing(output
, &output_dtd
);
1111 /* Set the input timing to the screen. Assume always input 0. */
1112 intel_sdvo_set_target_input(output
, true, false);
1115 success
= intel_sdvo_create_preferred_input_timing(output
,
1120 struct intel_sdvo_dtd input_dtd
;
1122 intel_sdvo_get_preferred_input_timing(output
,
1124 intel_sdvo_get_mode_from_dtd(adjusted_mode
, &input_dtd
);
1125 dev_priv
->sdvo_flags
= input_dtd
.part2
.sdvo_flags
;
1127 drm_mode_set_crtcinfo(adjusted_mode
, 0);
1129 mode
->clock
= adjusted_mode
->clock
;
1131 adjusted_mode
->clock
*=
1132 intel_sdvo_get_pixel_multiplier(mode
);
1136 } else if (dev_priv
->is_lvds
) {
1137 struct intel_sdvo_dtd output_dtd
;
1140 drm_mode_set_crtcinfo(dev_priv
->sdvo_lvds_fixed_mode
, 0);
1141 /* Set output timings */
1142 intel_sdvo_get_dtd_from_mode(&output_dtd
,
1143 dev_priv
->sdvo_lvds_fixed_mode
);
1145 intel_sdvo_set_target_output(output
,
1146 dev_priv
->controlled_output
);
1147 intel_sdvo_set_output_timing(output
, &output_dtd
);
1149 /* Set the input timing to the screen. Assume always input 0. */
1150 intel_sdvo_set_target_input(output
, true, false);
1153 success
= intel_sdvo_create_preferred_input_timing(
1160 struct intel_sdvo_dtd input_dtd
;
1162 intel_sdvo_get_preferred_input_timing(output
,
1164 intel_sdvo_get_mode_from_dtd(adjusted_mode
, &input_dtd
);
1165 dev_priv
->sdvo_flags
= input_dtd
.part2
.sdvo_flags
;
1167 drm_mode_set_crtcinfo(adjusted_mode
, 0);
1169 mode
->clock
= adjusted_mode
->clock
;
1171 adjusted_mode
->clock
*=
1172 intel_sdvo_get_pixel_multiplier(mode
);
1178 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1179 * SDVO device will be told of the multiplier during mode_set.
1181 adjusted_mode
->clock
*= intel_sdvo_get_pixel_multiplier(mode
);
1186 static void intel_sdvo_mode_set(struct drm_encoder
*encoder
,
1187 struct drm_display_mode
*mode
,
1188 struct drm_display_mode
*adjusted_mode
)
1190 struct drm_device
*dev
= encoder
->dev
;
1191 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1192 struct drm_crtc
*crtc
= encoder
->crtc
;
1193 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1194 struct intel_output
*output
= enc_to_intel_output(encoder
);
1195 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1197 int sdvo_pixel_multiply
;
1198 struct intel_sdvo_in_out_map in_out
;
1199 struct intel_sdvo_dtd input_dtd
;
1205 /* First, set the input mapping for the first input to our controlled
1206 * output. This is only correct if we're a single-input device, in
1207 * which case the first input is the output from the appropriate SDVO
1208 * channel on the motherboard. In a two-input device, the first input
1209 * will be SDVOB and the second SDVOC.
1211 in_out
.in0
= sdvo_priv
->controlled_output
;
1214 intel_sdvo_write_cmd(output
, SDVO_CMD_SET_IN_OUT_MAP
,
1215 &in_out
, sizeof(in_out
));
1216 status
= intel_sdvo_read_response(output
, NULL
, 0);
1218 if (sdvo_priv
->is_hdmi
) {
1219 intel_sdvo_set_avi_infoframe(output
, mode
);
1220 sdvox
|= SDVO_AUDIO_ENABLE
;
1223 /* We have tried to get input timing in mode_fixup, and filled into
1225 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
1226 intel_sdvo_get_dtd_from_mode(&input_dtd
, adjusted_mode
);
1227 input_dtd
.part2
.sdvo_flags
= sdvo_priv
->sdvo_flags
;
1229 intel_sdvo_get_dtd_from_mode(&input_dtd
, mode
);
1231 /* If it's a TV, we already set the output timing in mode_fixup.
1232 * Otherwise, the output timing is equal to the input timing.
1234 if (!sdvo_priv
->is_tv
&& !sdvo_priv
->is_lvds
) {
1235 /* Set the output timing to the screen */
1236 intel_sdvo_set_target_output(output
,
1237 sdvo_priv
->controlled_output
);
1238 intel_sdvo_set_output_timing(output
, &input_dtd
);
1241 /* Set the input timing to the screen. Assume always input 0. */
1242 intel_sdvo_set_target_input(output
, true, false);
1244 if (sdvo_priv
->is_tv
)
1245 intel_sdvo_set_tv_format(output
);
1247 /* We would like to use intel_sdvo_create_preferred_input_timing() to
1248 * provide the device with a timing it can support, if it supports that
1249 * feature. However, presumably we would need to adjust the CRTC to
1250 * output the preferred timing, and we don't support that currently.
1253 success
= intel_sdvo_create_preferred_input_timing(output
, clock
,
1256 struct intel_sdvo_dtd
*input_dtd
;
1258 intel_sdvo_get_preferred_input_timing(output
, &input_dtd
);
1259 intel_sdvo_set_input_timing(output
, &input_dtd
);
1262 intel_sdvo_set_input_timing(output
, &input_dtd
);
1265 switch (intel_sdvo_get_pixel_multiplier(mode
)) {
1267 intel_sdvo_set_clock_rate_mult(output
,
1268 SDVO_CLOCK_RATE_MULT_1X
);
1271 intel_sdvo_set_clock_rate_mult(output
,
1272 SDVO_CLOCK_RATE_MULT_2X
);
1275 intel_sdvo_set_clock_rate_mult(output
,
1276 SDVO_CLOCK_RATE_MULT_4X
);
1280 /* Set the SDVO control regs. */
1281 if (IS_I965G(dev
)) {
1282 sdvox
|= SDVO_BORDER_ENABLE
|
1283 SDVO_VSYNC_ACTIVE_HIGH
|
1284 SDVO_HSYNC_ACTIVE_HIGH
;
1286 sdvox
|= I915_READ(sdvo_priv
->output_device
);
1287 switch (sdvo_priv
->output_device
) {
1289 sdvox
&= SDVOB_PRESERVE_MASK
;
1292 sdvox
&= SDVOC_PRESERVE_MASK
;
1295 sdvox
|= (9 << 19) | SDVO_BORDER_ENABLE
;
1297 if (intel_crtc
->pipe
== 1)
1298 sdvox
|= SDVO_PIPE_B_SELECT
;
1300 sdvo_pixel_multiply
= intel_sdvo_get_pixel_multiplier(mode
);
1301 if (IS_I965G(dev
)) {
1302 /* done in crtc_mode_set as the dpll_md reg must be written early */
1303 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
1304 /* done in crtc_mode_set as it lives inside the dpll register */
1306 sdvox
|= (sdvo_pixel_multiply
- 1) << SDVO_PORT_MULTIPLY_SHIFT
;
1309 if (sdvo_priv
->sdvo_flags
& SDVO_NEED_TO_STALL
)
1310 sdvox
|= SDVO_STALL_SELECT
;
1311 intel_sdvo_write_sdvox(output
, sdvox
);
1314 static void intel_sdvo_dpms(struct drm_encoder
*encoder
, int mode
)
1316 struct drm_device
*dev
= encoder
->dev
;
1317 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1318 struct intel_output
*intel_output
= enc_to_intel_output(encoder
);
1319 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1322 if (mode
!= DRM_MODE_DPMS_ON
) {
1323 intel_sdvo_set_active_outputs(intel_output
, 0);
1325 intel_sdvo_set_encoder_power_state(intel_output
, mode
);
1327 if (mode
== DRM_MODE_DPMS_OFF
) {
1328 temp
= I915_READ(sdvo_priv
->output_device
);
1329 if ((temp
& SDVO_ENABLE
) != 0) {
1330 intel_sdvo_write_sdvox(intel_output
, temp
& ~SDVO_ENABLE
);
1334 bool input1
, input2
;
1338 temp
= I915_READ(sdvo_priv
->output_device
);
1339 if ((temp
& SDVO_ENABLE
) == 0)
1340 intel_sdvo_write_sdvox(intel_output
, temp
| SDVO_ENABLE
);
1341 for (i
= 0; i
< 2; i
++)
1342 intel_wait_for_vblank(dev
);
1344 status
= intel_sdvo_get_trained_inputs(intel_output
, &input1
,
1348 /* Warn if the device reported failure to sync.
1349 * A lot of SDVO devices fail to notify of sync, but it's
1350 * a given it the status is a success, we succeeded.
1352 if (status
== SDVO_CMD_STATUS_SUCCESS
&& !input1
) {
1353 DRM_DEBUG_KMS("First %s output reported failure to "
1354 "sync\n", SDVO_NAME(sdvo_priv
));
1358 intel_sdvo_set_encoder_power_state(intel_output
, mode
);
1359 intel_sdvo_set_active_outputs(intel_output
, sdvo_priv
->controlled_output
);
1364 static void intel_sdvo_save(struct drm_connector
*connector
)
1366 struct drm_device
*dev
= connector
->dev
;
1367 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1368 struct intel_output
*intel_output
= to_intel_output(connector
);
1369 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1372 sdvo_priv
->save_sdvo_mult
= intel_sdvo_get_clock_rate_mult(intel_output
);
1373 intel_sdvo_get_active_outputs(intel_output
, &sdvo_priv
->save_active_outputs
);
1375 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x1) {
1376 intel_sdvo_set_target_input(intel_output
, true, false);
1377 intel_sdvo_get_input_timing(intel_output
,
1378 &sdvo_priv
->save_input_dtd_1
);
1381 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x2) {
1382 intel_sdvo_set_target_input(intel_output
, false, true);
1383 intel_sdvo_get_input_timing(intel_output
,
1384 &sdvo_priv
->save_input_dtd_2
);
1387 for (o
= SDVO_OUTPUT_FIRST
; o
<= SDVO_OUTPUT_LAST
; o
++)
1389 u16 this_output
= (1 << o
);
1390 if (sdvo_priv
->caps
.output_flags
& this_output
)
1392 intel_sdvo_set_target_output(intel_output
, this_output
);
1393 intel_sdvo_get_output_timing(intel_output
,
1394 &sdvo_priv
->save_output_dtd
[o
]);
1397 if (sdvo_priv
->is_tv
) {
1398 /* XXX: Save TV format/enhancements. */
1401 sdvo_priv
->save_SDVOX
= I915_READ(sdvo_priv
->output_device
);
1404 static void intel_sdvo_restore(struct drm_connector
*connector
)
1406 struct drm_device
*dev
= connector
->dev
;
1407 struct intel_output
*intel_output
= to_intel_output(connector
);
1408 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1411 bool input1
, input2
;
1414 intel_sdvo_set_active_outputs(intel_output
, 0);
1416 for (o
= SDVO_OUTPUT_FIRST
; o
<= SDVO_OUTPUT_LAST
; o
++)
1418 u16 this_output
= (1 << o
);
1419 if (sdvo_priv
->caps
.output_flags
& this_output
) {
1420 intel_sdvo_set_target_output(intel_output
, this_output
);
1421 intel_sdvo_set_output_timing(intel_output
, &sdvo_priv
->save_output_dtd
[o
]);
1425 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x1) {
1426 intel_sdvo_set_target_input(intel_output
, true, false);
1427 intel_sdvo_set_input_timing(intel_output
, &sdvo_priv
->save_input_dtd_1
);
1430 if (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x2) {
1431 intel_sdvo_set_target_input(intel_output
, false, true);
1432 intel_sdvo_set_input_timing(intel_output
, &sdvo_priv
->save_input_dtd_2
);
1435 intel_sdvo_set_clock_rate_mult(intel_output
, sdvo_priv
->save_sdvo_mult
);
1437 if (sdvo_priv
->is_tv
) {
1438 /* XXX: Restore TV format/enhancements. */
1441 intel_sdvo_write_sdvox(intel_output
, sdvo_priv
->save_SDVOX
);
1443 if (sdvo_priv
->save_SDVOX
& SDVO_ENABLE
)
1445 for (i
= 0; i
< 2; i
++)
1446 intel_wait_for_vblank(dev
);
1447 status
= intel_sdvo_get_trained_inputs(intel_output
, &input1
, &input2
);
1448 if (status
== SDVO_CMD_STATUS_SUCCESS
&& !input1
)
1449 DRM_DEBUG_KMS("First %s output reported failure to "
1450 "sync\n", SDVO_NAME(sdvo_priv
));
1453 intel_sdvo_set_active_outputs(intel_output
, sdvo_priv
->save_active_outputs
);
1456 static int intel_sdvo_mode_valid(struct drm_connector
*connector
,
1457 struct drm_display_mode
*mode
)
1459 struct intel_output
*intel_output
= to_intel_output(connector
);
1460 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1462 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
1463 return MODE_NO_DBLESCAN
;
1465 if (sdvo_priv
->pixel_clock_min
> mode
->clock
)
1466 return MODE_CLOCK_LOW
;
1468 if (sdvo_priv
->pixel_clock_max
< mode
->clock
)
1469 return MODE_CLOCK_HIGH
;
1471 if (sdvo_priv
->is_lvds
== true) {
1472 if (sdvo_priv
->sdvo_lvds_fixed_mode
== NULL
)
1475 if (mode
->hdisplay
> sdvo_priv
->sdvo_lvds_fixed_mode
->hdisplay
)
1478 if (mode
->vdisplay
> sdvo_priv
->sdvo_lvds_fixed_mode
->vdisplay
)
1485 static bool intel_sdvo_get_capabilities(struct intel_output
*intel_output
, struct intel_sdvo_caps
*caps
)
1489 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_DEVICE_CAPS
, NULL
, 0);
1490 status
= intel_sdvo_read_response(intel_output
, caps
, sizeof(*caps
));
1491 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1497 struct drm_connector
* intel_sdvo_find(struct drm_device
*dev
, int sdvoB
)
1499 struct drm_connector
*connector
= NULL
;
1500 struct intel_output
*iout
= NULL
;
1501 struct intel_sdvo_priv
*sdvo
;
1503 /* find the sdvo connector */
1504 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1505 iout
= to_intel_output(connector
);
1507 if (iout
->type
!= INTEL_OUTPUT_SDVO
)
1510 sdvo
= iout
->dev_priv
;
1512 if (sdvo
->output_device
== SDVOB
&& sdvoB
)
1515 if (sdvo
->output_device
== SDVOC
&& !sdvoB
)
1523 int intel_sdvo_supports_hotplug(struct drm_connector
*connector
)
1527 struct intel_output
*intel_output
;
1528 DRM_DEBUG_KMS("\n");
1533 intel_output
= to_intel_output(connector
);
1535 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
, NULL
, 0);
1536 status
= intel_sdvo_read_response(intel_output
, &response
, 2);
1538 if (response
[0] !=0)
1544 void intel_sdvo_set_hotplug(struct drm_connector
*connector
, int on
)
1548 struct intel_output
*intel_output
= to_intel_output(connector
);
1550 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_ACTIVE_HOT_PLUG
, NULL
, 0);
1551 intel_sdvo_read_response(intel_output
, &response
, 2);
1554 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
, NULL
, 0);
1555 status
= intel_sdvo_read_response(intel_output
, &response
, 2);
1557 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
, &response
, 2);
1561 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
, &response
, 2);
1564 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_ACTIVE_HOT_PLUG
, NULL
, 0);
1565 intel_sdvo_read_response(intel_output
, &response
, 2);
1569 intel_sdvo_multifunc_encoder(struct intel_output
*intel_output
)
1571 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1574 if (sdvo_priv
->caps
.output_flags
&
1575 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
))
1577 if (sdvo_priv
->caps
.output_flags
&
1578 (SDVO_OUTPUT_RGB0
| SDVO_OUTPUT_RGB1
))
1580 if (sdvo_priv
->caps
.output_flags
&
1581 (SDVO_OUTPUT_SVID0
| SDVO_OUTPUT_SVID1
))
1583 if (sdvo_priv
->caps
.output_flags
&
1584 (SDVO_OUTPUT_CVBS0
| SDVO_OUTPUT_CVBS1
))
1586 if (sdvo_priv
->caps
.output_flags
&
1587 (SDVO_OUTPUT_YPRPB0
| SDVO_OUTPUT_YPRPB1
))
1590 if (sdvo_priv
->caps
.output_flags
&
1591 (SDVO_OUTPUT_SCART0
| SDVO_OUTPUT_SCART1
))
1594 if (sdvo_priv
->caps
.output_flags
&
1595 (SDVO_OUTPUT_LVDS0
| SDVO_OUTPUT_LVDS1
))
1601 static struct drm_connector
*
1602 intel_find_analog_connector(struct drm_device
*dev
)
1604 struct drm_connector
*connector
;
1605 struct intel_output
*intel_output
;
1607 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1608 intel_output
= to_intel_output(connector
);
1609 if (intel_output
->type
== INTEL_OUTPUT_ANALOG
)
1616 intel_analog_is_connected(struct drm_device
*dev
)
1618 struct drm_connector
*analog_connector
;
1619 analog_connector
= intel_find_analog_connector(dev
);
1621 if (!analog_connector
)
1624 if (analog_connector
->funcs
->detect(analog_connector
) ==
1625 connector_status_disconnected
)
1631 enum drm_connector_status
1632 intel_sdvo_hdmi_sink_detect(struct drm_connector
*connector
, u16 response
)
1634 struct intel_output
*intel_output
= to_intel_output(connector
);
1635 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1636 enum drm_connector_status status
= connector_status_connected
;
1637 struct edid
*edid
= NULL
;
1639 edid
= drm_get_edid(&intel_output
->base
,
1640 intel_output
->ddc_bus
);
1642 /* This is only applied to SDVO cards with multiple outputs */
1643 if (edid
== NULL
&& intel_sdvo_multifunc_encoder(intel_output
)) {
1644 uint8_t saved_ddc
, temp_ddc
;
1645 saved_ddc
= sdvo_priv
->ddc_bus
;
1646 temp_ddc
= sdvo_priv
->ddc_bus
>> 1;
1648 * Don't use the 1 as the argument of DDC bus switch to get
1649 * the EDID. It is used for SDVO SPD ROM.
1651 while(temp_ddc
> 1) {
1652 sdvo_priv
->ddc_bus
= temp_ddc
;
1653 edid
= drm_get_edid(&intel_output
->base
,
1654 intel_output
->ddc_bus
);
1657 * When we can get the EDID, maybe it is the
1658 * correct DDC bus. Update it.
1660 sdvo_priv
->ddc_bus
= temp_ddc
;
1666 sdvo_priv
->ddc_bus
= saved_ddc
;
1668 /* when there is no edid and no monitor is connected with VGA
1669 * port, try to use the CRT ddc to read the EDID for DVI-connector
1672 sdvo_priv
->analog_ddc_bus
&&
1673 !intel_analog_is_connected(intel_output
->base
.dev
))
1674 edid
= drm_get_edid(&intel_output
->base
,
1675 sdvo_priv
->analog_ddc_bus
);
1677 /* Don't report the output as connected if it's a DVI-I
1678 * connector with a non-digital EDID coming out.
1680 if (response
& (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
)) {
1681 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
)
1682 sdvo_priv
->is_hdmi
=
1683 drm_detect_hdmi_monitor(edid
);
1685 status
= connector_status_disconnected
;
1689 intel_output
->base
.display_info
.raw_edid
= NULL
;
1691 } else if (response
& (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
))
1692 status
= connector_status_disconnected
;
1697 static enum drm_connector_status
intel_sdvo_detect(struct drm_connector
*connector
)
1701 struct intel_output
*intel_output
= to_intel_output(connector
);
1702 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1704 intel_sdvo_write_cmd(intel_output
,
1705 SDVO_CMD_GET_ATTACHED_DISPLAYS
, NULL
, 0);
1706 status
= intel_sdvo_read_response(intel_output
, &response
, 2);
1708 DRM_DEBUG_KMS("SDVO response %d %d\n", response
& 0xff, response
>> 8);
1710 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1711 return connector_status_unknown
;
1714 return connector_status_disconnected
;
1716 if (intel_sdvo_multifunc_encoder(intel_output
) &&
1717 sdvo_priv
->attached_output
!= response
) {
1718 if (sdvo_priv
->controlled_output
!= response
&&
1719 intel_sdvo_output_setup(intel_output
, response
) != true)
1720 return connector_status_unknown
;
1721 sdvo_priv
->attached_output
= response
;
1723 return intel_sdvo_hdmi_sink_detect(connector
, response
);
1726 static void intel_sdvo_get_ddc_modes(struct drm_connector
*connector
)
1728 struct intel_output
*intel_output
= to_intel_output(connector
);
1729 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1732 /* set the bus switch and get the modes */
1733 num_modes
= intel_ddc_get_modes(intel_output
);
1736 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1737 * link between analog and digital outputs. So, if the regular SDVO
1738 * DDC fails, check to see if the analog output is disconnected, in
1739 * which case we'll look there for the digital DDC data.
1741 if (num_modes
== 0 &&
1742 sdvo_priv
->analog_ddc_bus
&&
1743 !intel_analog_is_connected(intel_output
->base
.dev
)) {
1744 struct i2c_adapter
*digital_ddc_bus
;
1746 /* Switch to the analog ddc bus and try that
1748 digital_ddc_bus
= intel_output
->ddc_bus
;
1749 intel_output
->ddc_bus
= sdvo_priv
->analog_ddc_bus
;
1751 (void) intel_ddc_get_modes(intel_output
);
1753 intel_output
->ddc_bus
= digital_ddc_bus
;
1758 * Set of SDVO TV modes.
1759 * Note! This is in reply order (see loop in get_tv_modes).
1760 * XXX: all 60Hz refresh?
1762 struct drm_display_mode sdvo_tv_modes
[] = {
1763 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER
, 5815, 320, 321, 384,
1764 416, 0, 200, 201, 232, 233, 0,
1765 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1766 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER
, 6814, 320, 321, 384,
1767 416, 0, 240, 241, 272, 273, 0,
1768 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1769 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER
, 9910, 400, 401, 464,
1770 496, 0, 300, 301, 332, 333, 0,
1771 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1772 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER
, 16913, 640, 641, 704,
1773 736, 0, 350, 351, 382, 383, 0,
1774 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1775 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER
, 19121, 640, 641, 704,
1776 736, 0, 400, 401, 432, 433, 0,
1777 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1778 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 22654, 640, 641, 704,
1779 736, 0, 480, 481, 512, 513, 0,
1780 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1781 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER
, 24624, 704, 705, 768,
1782 800, 0, 480, 481, 512, 513, 0,
1783 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1784 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER
, 29232, 704, 705, 768,
1785 800, 0, 576, 577, 608, 609, 0,
1786 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1787 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER
, 18751, 720, 721, 784,
1788 816, 0, 350, 351, 382, 383, 0,
1789 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1790 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 21199, 720, 721, 784,
1791 816, 0, 400, 401, 432, 433, 0,
1792 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1793 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 25116, 720, 721, 784,
1794 816, 0, 480, 481, 512, 513, 0,
1795 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1796 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER
, 28054, 720, 721, 784,
1797 816, 0, 540, 541, 572, 573, 0,
1798 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1799 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 29816, 720, 721, 784,
1800 816, 0, 576, 577, 608, 609, 0,
1801 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1802 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER
, 31570, 768, 769, 832,
1803 864, 0, 576, 577, 608, 609, 0,
1804 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1805 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 34030, 800, 801, 864,
1806 896, 0, 600, 601, 632, 633, 0,
1807 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1808 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER
, 36581, 832, 833, 896,
1809 928, 0, 624, 625, 656, 657, 0,
1810 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1811 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER
, 48707, 920, 921, 984,
1812 1016, 0, 766, 767, 798, 799, 0,
1813 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1814 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 53827, 1024, 1025, 1088,
1815 1120, 0, 768, 769, 800, 801, 0,
1816 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1817 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 87265, 1280, 1281, 1344,
1818 1376, 0, 1024, 1025, 1056, 1057, 0,
1819 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1822 static void intel_sdvo_get_tv_modes(struct drm_connector
*connector
)
1824 struct intel_output
*output
= to_intel_output(connector
);
1825 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1826 struct intel_sdvo_sdtv_resolution_request tv_res
;
1827 uint32_t reply
= 0, format_map
= 0;
1832 /* Read the list of supported input resolutions for the selected TV
1835 for (i
= 0; i
< TV_FORMAT_NUM
; i
++)
1836 if (tv_format_names
[i
] == sdvo_priv
->tv_format_name
)
1839 format_map
= (1 << i
);
1840 memcpy(&tv_res
, &format_map
,
1841 sizeof(struct intel_sdvo_sdtv_resolution_request
) >
1842 sizeof(format_map
) ? sizeof(format_map
) :
1843 sizeof(struct intel_sdvo_sdtv_resolution_request
));
1845 intel_sdvo_set_target_output(output
, sdvo_priv
->controlled_output
);
1847 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
,
1848 &tv_res
, sizeof(tv_res
));
1849 status
= intel_sdvo_read_response(output
, &reply
, 3);
1850 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
1853 for (i
= 0; i
< ARRAY_SIZE(sdvo_tv_modes
); i
++)
1854 if (reply
& (1 << i
)) {
1855 struct drm_display_mode
*nmode
;
1856 nmode
= drm_mode_duplicate(connector
->dev
,
1859 drm_mode_probed_add(connector
, nmode
);
1864 static void intel_sdvo_get_lvds_modes(struct drm_connector
*connector
)
1866 struct intel_output
*intel_output
= to_intel_output(connector
);
1867 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
1868 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1869 struct drm_display_mode
*newmode
;
1872 * Attempt to get the mode list from DDC.
1873 * Assume that the preferred modes are
1874 * arranged in priority order.
1876 intel_ddc_get_modes(intel_output
);
1877 if (list_empty(&connector
->probed_modes
) == false)
1880 /* Fetch modes from VBT */
1881 if (dev_priv
->sdvo_lvds_vbt_mode
!= NULL
) {
1882 newmode
= drm_mode_duplicate(connector
->dev
,
1883 dev_priv
->sdvo_lvds_vbt_mode
);
1884 if (newmode
!= NULL
) {
1885 /* Guarantee the mode is preferred */
1886 newmode
->type
= (DRM_MODE_TYPE_PREFERRED
|
1887 DRM_MODE_TYPE_DRIVER
);
1888 drm_mode_probed_add(connector
, newmode
);
1893 list_for_each_entry(newmode
, &connector
->probed_modes
, head
) {
1894 if (newmode
->type
& DRM_MODE_TYPE_PREFERRED
) {
1895 sdvo_priv
->sdvo_lvds_fixed_mode
=
1896 drm_mode_duplicate(connector
->dev
, newmode
);
1903 static int intel_sdvo_get_modes(struct drm_connector
*connector
)
1905 struct intel_output
*output
= to_intel_output(connector
);
1906 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
1908 if (sdvo_priv
->is_tv
)
1909 intel_sdvo_get_tv_modes(connector
);
1910 else if (sdvo_priv
->is_lvds
== true)
1911 intel_sdvo_get_lvds_modes(connector
);
1913 intel_sdvo_get_ddc_modes(connector
);
1915 if (list_empty(&connector
->probed_modes
))
1921 void intel_sdvo_destroy_enhance_property(struct drm_connector
*connector
)
1923 struct intel_output
*intel_output
= to_intel_output(connector
);
1924 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1925 struct drm_device
*dev
= connector
->dev
;
1927 if (sdvo_priv
->is_tv
) {
1928 if (sdvo_priv
->left_property
)
1929 drm_property_destroy(dev
, sdvo_priv
->left_property
);
1930 if (sdvo_priv
->right_property
)
1931 drm_property_destroy(dev
, sdvo_priv
->right_property
);
1932 if (sdvo_priv
->top_property
)
1933 drm_property_destroy(dev
, sdvo_priv
->top_property
);
1934 if (sdvo_priv
->bottom_property
)
1935 drm_property_destroy(dev
, sdvo_priv
->bottom_property
);
1936 if (sdvo_priv
->hpos_property
)
1937 drm_property_destroy(dev
, sdvo_priv
->hpos_property
);
1938 if (sdvo_priv
->vpos_property
)
1939 drm_property_destroy(dev
, sdvo_priv
->vpos_property
);
1941 if (sdvo_priv
->is_tv
) {
1942 if (sdvo_priv
->saturation_property
)
1943 drm_property_destroy(dev
,
1944 sdvo_priv
->saturation_property
);
1945 if (sdvo_priv
->contrast_property
)
1946 drm_property_destroy(dev
,
1947 sdvo_priv
->contrast_property
);
1948 if (sdvo_priv
->hue_property
)
1949 drm_property_destroy(dev
, sdvo_priv
->hue_property
);
1951 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
1952 if (sdvo_priv
->brightness_property
)
1953 drm_property_destroy(dev
,
1954 sdvo_priv
->brightness_property
);
1959 static void intel_sdvo_destroy(struct drm_connector
*connector
)
1961 struct intel_output
*intel_output
= to_intel_output(connector
);
1962 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1964 if (intel_output
->i2c_bus
)
1965 intel_i2c_destroy(intel_output
->i2c_bus
);
1966 if (intel_output
->ddc_bus
)
1967 intel_i2c_destroy(intel_output
->ddc_bus
);
1968 if (sdvo_priv
->analog_ddc_bus
)
1969 intel_i2c_destroy(sdvo_priv
->analog_ddc_bus
);
1971 if (sdvo_priv
->sdvo_lvds_fixed_mode
!= NULL
)
1972 drm_mode_destroy(connector
->dev
,
1973 sdvo_priv
->sdvo_lvds_fixed_mode
);
1975 if (sdvo_priv
->tv_format_property
)
1976 drm_property_destroy(connector
->dev
,
1977 sdvo_priv
->tv_format_property
);
1979 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
)
1980 intel_sdvo_destroy_enhance_property(connector
);
1982 drm_sysfs_connector_remove(connector
);
1983 drm_connector_cleanup(connector
);
1985 kfree(intel_output
);
1989 intel_sdvo_set_property(struct drm_connector
*connector
,
1990 struct drm_property
*property
,
1993 struct intel_output
*intel_output
= to_intel_output(connector
);
1994 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
1995 struct drm_encoder
*encoder
= &intel_output
->enc
;
1996 struct drm_crtc
*crtc
= encoder
->crtc
;
1998 bool changed
= false;
1999 uint8_t cmd
, status
;
2000 uint16_t temp_value
;
2002 ret
= drm_connector_property_set_value(connector
, property
, val
);
2006 if (property
== sdvo_priv
->tv_format_property
) {
2007 if (val
>= TV_FORMAT_NUM
) {
2011 if (sdvo_priv
->tv_format_name
==
2012 sdvo_priv
->tv_format_supported
[val
])
2015 sdvo_priv
->tv_format_name
= sdvo_priv
->tv_format_supported
[val
];
2019 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
2022 if (sdvo_priv
->left_property
== property
) {
2023 drm_connector_property_set_value(connector
,
2024 sdvo_priv
->right_property
, val
);
2025 if (sdvo_priv
->left_margin
== temp_value
)
2028 sdvo_priv
->left_margin
= temp_value
;
2029 sdvo_priv
->right_margin
= temp_value
;
2030 temp_value
= sdvo_priv
->max_hscan
-
2031 sdvo_priv
->left_margin
;
2032 cmd
= SDVO_CMD_SET_OVERSCAN_H
;
2033 } else if (sdvo_priv
->right_property
== property
) {
2034 drm_connector_property_set_value(connector
,
2035 sdvo_priv
->left_property
, val
);
2036 if (sdvo_priv
->right_margin
== temp_value
)
2039 sdvo_priv
->left_margin
= temp_value
;
2040 sdvo_priv
->right_margin
= temp_value
;
2041 temp_value
= sdvo_priv
->max_hscan
-
2042 sdvo_priv
->left_margin
;
2043 cmd
= SDVO_CMD_SET_OVERSCAN_H
;
2044 } else if (sdvo_priv
->top_property
== property
) {
2045 drm_connector_property_set_value(connector
,
2046 sdvo_priv
->bottom_property
, val
);
2047 if (sdvo_priv
->top_margin
== temp_value
)
2050 sdvo_priv
->top_margin
= temp_value
;
2051 sdvo_priv
->bottom_margin
= temp_value
;
2052 temp_value
= sdvo_priv
->max_vscan
-
2053 sdvo_priv
->top_margin
;
2054 cmd
= SDVO_CMD_SET_OVERSCAN_V
;
2055 } else if (sdvo_priv
->bottom_property
== property
) {
2056 drm_connector_property_set_value(connector
,
2057 sdvo_priv
->top_property
, val
);
2058 if (sdvo_priv
->bottom_margin
== temp_value
)
2060 sdvo_priv
->top_margin
= temp_value
;
2061 sdvo_priv
->bottom_margin
= temp_value
;
2062 temp_value
= sdvo_priv
->max_vscan
-
2063 sdvo_priv
->top_margin
;
2064 cmd
= SDVO_CMD_SET_OVERSCAN_V
;
2065 } else if (sdvo_priv
->hpos_property
== property
) {
2066 if (sdvo_priv
->cur_hpos
== temp_value
)
2069 cmd
= SDVO_CMD_SET_POSITION_H
;
2070 sdvo_priv
->cur_hpos
= temp_value
;
2071 } else if (sdvo_priv
->vpos_property
== property
) {
2072 if (sdvo_priv
->cur_vpos
== temp_value
)
2075 cmd
= SDVO_CMD_SET_POSITION_V
;
2076 sdvo_priv
->cur_vpos
= temp_value
;
2077 } else if (sdvo_priv
->saturation_property
== property
) {
2078 if (sdvo_priv
->cur_saturation
== temp_value
)
2081 cmd
= SDVO_CMD_SET_SATURATION
;
2082 sdvo_priv
->cur_saturation
= temp_value
;
2083 } else if (sdvo_priv
->contrast_property
== property
) {
2084 if (sdvo_priv
->cur_contrast
== temp_value
)
2087 cmd
= SDVO_CMD_SET_CONTRAST
;
2088 sdvo_priv
->cur_contrast
= temp_value
;
2089 } else if (sdvo_priv
->hue_property
== property
) {
2090 if (sdvo_priv
->cur_hue
== temp_value
)
2093 cmd
= SDVO_CMD_SET_HUE
;
2094 sdvo_priv
->cur_hue
= temp_value
;
2095 } else if (sdvo_priv
->brightness_property
== property
) {
2096 if (sdvo_priv
->cur_brightness
== temp_value
)
2099 cmd
= SDVO_CMD_SET_BRIGHTNESS
;
2100 sdvo_priv
->cur_brightness
= temp_value
;
2103 intel_sdvo_write_cmd(intel_output
, cmd
, &temp_value
, 2);
2104 status
= intel_sdvo_read_response(intel_output
,
2106 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2107 DRM_DEBUG_KMS("Incorrect SDVO command \n");
2113 if (changed
&& crtc
)
2114 drm_crtc_helper_set_mode(crtc
, &crtc
->mode
, crtc
->x
,
2120 static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs
= {
2121 .dpms
= intel_sdvo_dpms
,
2122 .mode_fixup
= intel_sdvo_mode_fixup
,
2123 .prepare
= intel_encoder_prepare
,
2124 .mode_set
= intel_sdvo_mode_set
,
2125 .commit
= intel_encoder_commit
,
2128 static const struct drm_connector_funcs intel_sdvo_connector_funcs
= {
2129 .dpms
= drm_helper_connector_dpms
,
2130 .save
= intel_sdvo_save
,
2131 .restore
= intel_sdvo_restore
,
2132 .detect
= intel_sdvo_detect
,
2133 .fill_modes
= drm_helper_probe_single_connector_modes
,
2134 .set_property
= intel_sdvo_set_property
,
2135 .destroy
= intel_sdvo_destroy
,
2138 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs
= {
2139 .get_modes
= intel_sdvo_get_modes
,
2140 .mode_valid
= intel_sdvo_mode_valid
,
2141 .best_encoder
= intel_best_encoder
,
2144 static void intel_sdvo_enc_destroy(struct drm_encoder
*encoder
)
2146 drm_encoder_cleanup(encoder
);
2149 static const struct drm_encoder_funcs intel_sdvo_enc_funcs
= {
2150 .destroy
= intel_sdvo_enc_destroy
,
2155 * Choose the appropriate DDC bus for control bus switch command for this
2156 * SDVO output based on the controlled output.
2158 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2159 * outputs, then LVDS outputs.
2162 intel_sdvo_select_ddc_bus(struct intel_sdvo_priv
*dev_priv
)
2165 unsigned int num_bits
;
2167 /* Make a mask of outputs less than or equal to our own priority in the
2170 switch (dev_priv
->controlled_output
) {
2171 case SDVO_OUTPUT_LVDS1
:
2172 mask
|= SDVO_OUTPUT_LVDS1
;
2173 case SDVO_OUTPUT_LVDS0
:
2174 mask
|= SDVO_OUTPUT_LVDS0
;
2175 case SDVO_OUTPUT_TMDS1
:
2176 mask
|= SDVO_OUTPUT_TMDS1
;
2177 case SDVO_OUTPUT_TMDS0
:
2178 mask
|= SDVO_OUTPUT_TMDS0
;
2179 case SDVO_OUTPUT_RGB1
:
2180 mask
|= SDVO_OUTPUT_RGB1
;
2181 case SDVO_OUTPUT_RGB0
:
2182 mask
|= SDVO_OUTPUT_RGB0
;
2186 /* Count bits to find what number we are in the priority list. */
2187 mask
&= dev_priv
->caps
.output_flags
;
2188 num_bits
= hweight16(mask
);
2190 /* if more than 3 outputs, default to DDC bus 3 for now */
2194 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2195 dev_priv
->ddc_bus
= 1 << num_bits
;
2199 intel_sdvo_get_digital_encoding_mode(struct intel_output
*output
)
2201 struct intel_sdvo_priv
*sdvo_priv
= output
->dev_priv
;
2204 intel_sdvo_set_target_output(output
, sdvo_priv
->controlled_output
);
2206 intel_sdvo_write_cmd(output
, SDVO_CMD_GET_ENCODE
, NULL
, 0);
2207 status
= intel_sdvo_read_response(output
, &sdvo_priv
->is_hdmi
, 1);
2208 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
2213 static struct intel_output
*
2214 intel_sdvo_chan_to_intel_output(struct intel_i2c_chan
*chan
)
2216 struct drm_device
*dev
= chan
->drm_dev
;
2217 struct drm_connector
*connector
;
2218 struct intel_output
*intel_output
= NULL
;
2220 list_for_each_entry(connector
,
2221 &dev
->mode_config
.connector_list
, head
) {
2222 if (to_intel_output(connector
)->ddc_bus
== &chan
->adapter
) {
2223 intel_output
= to_intel_output(connector
);
2227 return intel_output
;
2230 static int intel_sdvo_master_xfer(struct i2c_adapter
*i2c_adap
,
2231 struct i2c_msg msgs
[], int num
)
2233 struct intel_output
*intel_output
;
2234 struct intel_sdvo_priv
*sdvo_priv
;
2235 struct i2c_algo_bit_data
*algo_data
;
2236 const struct i2c_algorithm
*algo
;
2238 algo_data
= (struct i2c_algo_bit_data
*)i2c_adap
->algo_data
;
2240 intel_sdvo_chan_to_intel_output(
2241 (struct intel_i2c_chan
*)(algo_data
->data
));
2242 if (intel_output
== NULL
)
2245 sdvo_priv
= intel_output
->dev_priv
;
2246 algo
= intel_output
->i2c_bus
->algo
;
2248 intel_sdvo_set_control_bus_switch(intel_output
, sdvo_priv
->ddc_bus
);
2249 return algo
->master_xfer(i2c_adap
, msgs
, num
);
2252 static struct i2c_algorithm intel_sdvo_i2c_bit_algo
= {
2253 .master_xfer
= intel_sdvo_master_xfer
,
2257 intel_sdvo_get_slave_addr(struct drm_device
*dev
, int output_device
)
2259 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2260 struct sdvo_device_mapping
*my_mapping
, *other_mapping
;
2262 if (output_device
== SDVOB
) {
2263 my_mapping
= &dev_priv
->sdvo_mappings
[0];
2264 other_mapping
= &dev_priv
->sdvo_mappings
[1];
2266 my_mapping
= &dev_priv
->sdvo_mappings
[1];
2267 other_mapping
= &dev_priv
->sdvo_mappings
[0];
2270 /* If the BIOS described our SDVO device, take advantage of it. */
2271 if (my_mapping
->slave_addr
)
2272 return my_mapping
->slave_addr
;
2274 /* If the BIOS only described a different SDVO device, use the
2275 * address that it isn't using.
2277 if (other_mapping
->slave_addr
) {
2278 if (other_mapping
->slave_addr
== 0x70)
2284 /* No SDVO device info is found for another DVO port,
2285 * so use mapping assumption we had before BIOS parsing.
2287 if (output_device
== SDVOB
)
2293 static int intel_sdvo_bad_tv_callback(const struct dmi_system_id
*id
)
2295 DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id
->ident
);
2299 static struct dmi_system_id intel_sdvo_bad_tv
[] = {
2301 .callback
= intel_sdvo_bad_tv_callback
,
2302 .ident
= "IntelG45/ICH10R/DME1737",
2304 DMI_MATCH(DMI_SYS_VENDOR
, "IBM CORPORATION"),
2305 DMI_MATCH(DMI_PRODUCT_NAME
, "4800784"),
2309 { } /* terminating entry */
2313 intel_sdvo_output_setup(struct intel_output
*intel_output
, uint16_t flags
)
2315 struct drm_connector
*connector
= &intel_output
->base
;
2316 struct drm_encoder
*encoder
= &intel_output
->enc
;
2317 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
2318 bool ret
= true, registered
= false;
2320 sdvo_priv
->is_tv
= false;
2321 intel_output
->needs_tv_clock
= false;
2322 sdvo_priv
->is_lvds
= false;
2324 if (device_is_registered(&connector
->kdev
)) {
2325 drm_sysfs_connector_remove(connector
);
2330 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_TMDS1
)) {
2331 if (sdvo_priv
->caps
.output_flags
& SDVO_OUTPUT_TMDS0
)
2332 sdvo_priv
->controlled_output
= SDVO_OUTPUT_TMDS0
;
2334 sdvo_priv
->controlled_output
= SDVO_OUTPUT_TMDS1
;
2336 encoder
->encoder_type
= DRM_MODE_ENCODER_TMDS
;
2337 connector
->connector_type
= DRM_MODE_CONNECTOR_DVID
;
2339 if (intel_sdvo_get_supp_encode(intel_output
,
2340 &sdvo_priv
->encode
) &&
2341 intel_sdvo_get_digital_encoding_mode(intel_output
) &&
2342 sdvo_priv
->is_hdmi
) {
2343 /* enable hdmi encoding mode if supported */
2344 intel_sdvo_set_encode(intel_output
, SDVO_ENCODE_HDMI
);
2345 intel_sdvo_set_colorimetry(intel_output
,
2346 SDVO_COLORIMETRY_RGB256
);
2347 connector
->connector_type
= DRM_MODE_CONNECTOR_HDMIA
;
2348 intel_output
->clone_mask
=
2349 (1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2350 (1 << INTEL_ANALOG_CLONE_BIT
);
2352 } else if ((flags
& SDVO_OUTPUT_SVID0
) &&
2353 !dmi_check_system(intel_sdvo_bad_tv
)) {
2355 sdvo_priv
->controlled_output
= SDVO_OUTPUT_SVID0
;
2356 encoder
->encoder_type
= DRM_MODE_ENCODER_TVDAC
;
2357 connector
->connector_type
= DRM_MODE_CONNECTOR_SVIDEO
;
2358 sdvo_priv
->is_tv
= true;
2359 intel_output
->needs_tv_clock
= true;
2360 intel_output
->clone_mask
= 1 << INTEL_SDVO_TV_CLONE_BIT
;
2361 } else if (flags
& SDVO_OUTPUT_RGB0
) {
2363 sdvo_priv
->controlled_output
= SDVO_OUTPUT_RGB0
;
2364 encoder
->encoder_type
= DRM_MODE_ENCODER_DAC
;
2365 connector
->connector_type
= DRM_MODE_CONNECTOR_VGA
;
2366 intel_output
->clone_mask
= (1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2367 (1 << INTEL_ANALOG_CLONE_BIT
);
2368 } else if (flags
& SDVO_OUTPUT_RGB1
) {
2370 sdvo_priv
->controlled_output
= SDVO_OUTPUT_RGB1
;
2371 encoder
->encoder_type
= DRM_MODE_ENCODER_DAC
;
2372 connector
->connector_type
= DRM_MODE_CONNECTOR_VGA
;
2373 intel_output
->clone_mask
= (1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2374 (1 << INTEL_ANALOG_CLONE_BIT
);
2375 } else if (flags
& SDVO_OUTPUT_LVDS0
) {
2377 sdvo_priv
->controlled_output
= SDVO_OUTPUT_LVDS0
;
2378 encoder
->encoder_type
= DRM_MODE_ENCODER_LVDS
;
2379 connector
->connector_type
= DRM_MODE_CONNECTOR_LVDS
;
2380 sdvo_priv
->is_lvds
= true;
2381 intel_output
->clone_mask
= (1 << INTEL_ANALOG_CLONE_BIT
) |
2382 (1 << INTEL_SDVO_LVDS_CLONE_BIT
);
2383 } else if (flags
& SDVO_OUTPUT_LVDS1
) {
2385 sdvo_priv
->controlled_output
= SDVO_OUTPUT_LVDS1
;
2386 encoder
->encoder_type
= DRM_MODE_ENCODER_LVDS
;
2387 connector
->connector_type
= DRM_MODE_CONNECTOR_LVDS
;
2388 sdvo_priv
->is_lvds
= true;
2389 intel_output
->clone_mask
= (1 << INTEL_ANALOG_CLONE_BIT
) |
2390 (1 << INTEL_SDVO_LVDS_CLONE_BIT
);
2393 unsigned char bytes
[2];
2395 sdvo_priv
->controlled_output
= 0;
2396 memcpy(bytes
, &sdvo_priv
->caps
.output_flags
, 2);
2397 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2398 SDVO_NAME(sdvo_priv
),
2399 bytes
[0], bytes
[1]);
2402 intel_output
->crtc_mask
= (1 << 0) | (1 << 1);
2404 if (ret
&& registered
)
2405 ret
= drm_sysfs_connector_add(connector
) == 0 ? true : false;
2412 static void intel_sdvo_tv_create_property(struct drm_connector
*connector
)
2414 struct intel_output
*intel_output
= to_intel_output(connector
);
2415 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
2416 struct intel_sdvo_tv_format format
;
2417 uint32_t format_map
, i
;
2420 intel_sdvo_set_target_output(intel_output
,
2421 sdvo_priv
->controlled_output
);
2423 intel_sdvo_write_cmd(intel_output
,
2424 SDVO_CMD_GET_SUPPORTED_TV_FORMATS
, NULL
, 0);
2425 status
= intel_sdvo_read_response(intel_output
,
2426 &format
, sizeof(format
));
2427 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
2430 memcpy(&format_map
, &format
, sizeof(format
) > sizeof(format_map
) ?
2431 sizeof(format_map
) : sizeof(format
));
2433 if (format_map
== 0)
2436 sdvo_priv
->format_supported_num
= 0;
2437 for (i
= 0 ; i
< TV_FORMAT_NUM
; i
++)
2438 if (format_map
& (1 << i
)) {
2439 sdvo_priv
->tv_format_supported
2440 [sdvo_priv
->format_supported_num
++] =
2445 sdvo_priv
->tv_format_property
=
2446 drm_property_create(
2447 connector
->dev
, DRM_MODE_PROP_ENUM
,
2448 "mode", sdvo_priv
->format_supported_num
);
2450 for (i
= 0; i
< sdvo_priv
->format_supported_num
; i
++)
2451 drm_property_add_enum(
2452 sdvo_priv
->tv_format_property
, i
,
2453 i
, sdvo_priv
->tv_format_supported
[i
]);
2455 sdvo_priv
->tv_format_name
= sdvo_priv
->tv_format_supported
[0];
2456 drm_connector_attach_property(
2457 connector
, sdvo_priv
->tv_format_property
, 0);
2461 static void intel_sdvo_create_enhance_property(struct drm_connector
*connector
)
2463 struct intel_output
*intel_output
= to_intel_output(connector
);
2464 struct intel_sdvo_priv
*sdvo_priv
= intel_output
->dev_priv
;
2465 struct intel_sdvo_enhancements_reply sdvo_data
;
2466 struct drm_device
*dev
= connector
->dev
;
2468 uint16_t response
, data_value
[2];
2470 intel_sdvo_write_cmd(intel_output
, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
,
2472 status
= intel_sdvo_read_response(intel_output
, &sdvo_data
,
2474 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2475 DRM_DEBUG_KMS(" incorrect response is returned\n");
2478 response
= *((uint16_t *)&sdvo_data
);
2480 DRM_DEBUG_KMS("No enhancement is supported\n");
2483 if (sdvo_priv
->is_tv
) {
2484 /* when horizontal overscan is supported, Add the left/right
2487 if (sdvo_data
.overscan_h
) {
2488 intel_sdvo_write_cmd(intel_output
,
2489 SDVO_CMD_GET_MAX_OVERSCAN_H
, NULL
, 0);
2490 status
= intel_sdvo_read_response(intel_output
,
2492 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2493 DRM_DEBUG_KMS("Incorrect SDVO max "
2497 intel_sdvo_write_cmd(intel_output
,
2498 SDVO_CMD_GET_OVERSCAN_H
, NULL
, 0);
2499 status
= intel_sdvo_read_response(intel_output
,
2501 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2502 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2505 sdvo_priv
->max_hscan
= data_value
[0];
2506 sdvo_priv
->left_margin
= data_value
[0] - response
;
2507 sdvo_priv
->right_margin
= sdvo_priv
->left_margin
;
2508 sdvo_priv
->left_property
=
2509 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2511 sdvo_priv
->left_property
->values
[0] = 0;
2512 sdvo_priv
->left_property
->values
[1] = data_value
[0];
2513 drm_connector_attach_property(connector
,
2514 sdvo_priv
->left_property
,
2515 sdvo_priv
->left_margin
);
2516 sdvo_priv
->right_property
=
2517 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2519 sdvo_priv
->right_property
->values
[0] = 0;
2520 sdvo_priv
->right_property
->values
[1] = data_value
[0];
2521 drm_connector_attach_property(connector
,
2522 sdvo_priv
->right_property
,
2523 sdvo_priv
->right_margin
);
2524 DRM_DEBUG_KMS("h_overscan: max %d, "
2525 "default %d, current %d\n",
2526 data_value
[0], data_value
[1], response
);
2528 if (sdvo_data
.overscan_v
) {
2529 intel_sdvo_write_cmd(intel_output
,
2530 SDVO_CMD_GET_MAX_OVERSCAN_V
, NULL
, 0);
2531 status
= intel_sdvo_read_response(intel_output
,
2533 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2534 DRM_DEBUG_KMS("Incorrect SDVO max "
2538 intel_sdvo_write_cmd(intel_output
,
2539 SDVO_CMD_GET_OVERSCAN_V
, NULL
, 0);
2540 status
= intel_sdvo_read_response(intel_output
,
2542 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2543 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2546 sdvo_priv
->max_vscan
= data_value
[0];
2547 sdvo_priv
->top_margin
= data_value
[0] - response
;
2548 sdvo_priv
->bottom_margin
= sdvo_priv
->top_margin
;
2549 sdvo_priv
->top_property
=
2550 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2552 sdvo_priv
->top_property
->values
[0] = 0;
2553 sdvo_priv
->top_property
->values
[1] = data_value
[0];
2554 drm_connector_attach_property(connector
,
2555 sdvo_priv
->top_property
,
2556 sdvo_priv
->top_margin
);
2557 sdvo_priv
->bottom_property
=
2558 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2559 "bottom_margin", 2);
2560 sdvo_priv
->bottom_property
->values
[0] = 0;
2561 sdvo_priv
->bottom_property
->values
[1] = data_value
[0];
2562 drm_connector_attach_property(connector
,
2563 sdvo_priv
->bottom_property
,
2564 sdvo_priv
->bottom_margin
);
2565 DRM_DEBUG_KMS("v_overscan: max %d, "
2566 "default %d, current %d\n",
2567 data_value
[0], data_value
[1], response
);
2569 if (sdvo_data
.position_h
) {
2570 intel_sdvo_write_cmd(intel_output
,
2571 SDVO_CMD_GET_MAX_POSITION_H
, NULL
, 0);
2572 status
= intel_sdvo_read_response(intel_output
,
2574 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2575 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2578 intel_sdvo_write_cmd(intel_output
,
2579 SDVO_CMD_GET_POSITION_H
, NULL
, 0);
2580 status
= intel_sdvo_read_response(intel_output
,
2582 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2583 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2586 sdvo_priv
->max_hpos
= data_value
[0];
2587 sdvo_priv
->cur_hpos
= response
;
2588 sdvo_priv
->hpos_property
=
2589 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2591 sdvo_priv
->hpos_property
->values
[0] = 0;
2592 sdvo_priv
->hpos_property
->values
[1] = data_value
[0];
2593 drm_connector_attach_property(connector
,
2594 sdvo_priv
->hpos_property
,
2595 sdvo_priv
->cur_hpos
);
2596 DRM_DEBUG_KMS("h_position: max %d, "
2597 "default %d, current %d\n",
2598 data_value
[0], data_value
[1], response
);
2600 if (sdvo_data
.position_v
) {
2601 intel_sdvo_write_cmd(intel_output
,
2602 SDVO_CMD_GET_MAX_POSITION_V
, NULL
, 0);
2603 status
= intel_sdvo_read_response(intel_output
,
2605 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2606 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2609 intel_sdvo_write_cmd(intel_output
,
2610 SDVO_CMD_GET_POSITION_V
, NULL
, 0);
2611 status
= intel_sdvo_read_response(intel_output
,
2613 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2614 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2617 sdvo_priv
->max_vpos
= data_value
[0];
2618 sdvo_priv
->cur_vpos
= response
;
2619 sdvo_priv
->vpos_property
=
2620 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2622 sdvo_priv
->vpos_property
->values
[0] = 0;
2623 sdvo_priv
->vpos_property
->values
[1] = data_value
[0];
2624 drm_connector_attach_property(connector
,
2625 sdvo_priv
->vpos_property
,
2626 sdvo_priv
->cur_vpos
);
2627 DRM_DEBUG_KMS("v_position: max %d, "
2628 "default %d, current %d\n",
2629 data_value
[0], data_value
[1], response
);
2632 if (sdvo_priv
->is_tv
) {
2633 if (sdvo_data
.saturation
) {
2634 intel_sdvo_write_cmd(intel_output
,
2635 SDVO_CMD_GET_MAX_SATURATION
, NULL
, 0);
2636 status
= intel_sdvo_read_response(intel_output
,
2638 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2639 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2642 intel_sdvo_write_cmd(intel_output
,
2643 SDVO_CMD_GET_SATURATION
, NULL
, 0);
2644 status
= intel_sdvo_read_response(intel_output
,
2646 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2647 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2650 sdvo_priv
->max_saturation
= data_value
[0];
2651 sdvo_priv
->cur_saturation
= response
;
2652 sdvo_priv
->saturation_property
=
2653 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2655 sdvo_priv
->saturation_property
->values
[0] = 0;
2656 sdvo_priv
->saturation_property
->values
[1] =
2658 drm_connector_attach_property(connector
,
2659 sdvo_priv
->saturation_property
,
2660 sdvo_priv
->cur_saturation
);
2661 DRM_DEBUG_KMS("saturation: max %d, "
2662 "default %d, current %d\n",
2663 data_value
[0], data_value
[1], response
);
2665 if (sdvo_data
.contrast
) {
2666 intel_sdvo_write_cmd(intel_output
,
2667 SDVO_CMD_GET_MAX_CONTRAST
, NULL
, 0);
2668 status
= intel_sdvo_read_response(intel_output
,
2670 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2671 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2674 intel_sdvo_write_cmd(intel_output
,
2675 SDVO_CMD_GET_CONTRAST
, NULL
, 0);
2676 status
= intel_sdvo_read_response(intel_output
,
2678 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2679 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2682 sdvo_priv
->max_contrast
= data_value
[0];
2683 sdvo_priv
->cur_contrast
= response
;
2684 sdvo_priv
->contrast_property
=
2685 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2687 sdvo_priv
->contrast_property
->values
[0] = 0;
2688 sdvo_priv
->contrast_property
->values
[1] = data_value
[0];
2689 drm_connector_attach_property(connector
,
2690 sdvo_priv
->contrast_property
,
2691 sdvo_priv
->cur_contrast
);
2692 DRM_DEBUG_KMS("contrast: max %d, "
2693 "default %d, current %d\n",
2694 data_value
[0], data_value
[1], response
);
2696 if (sdvo_data
.hue
) {
2697 intel_sdvo_write_cmd(intel_output
,
2698 SDVO_CMD_GET_MAX_HUE
, NULL
, 0);
2699 status
= intel_sdvo_read_response(intel_output
,
2701 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2702 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2705 intel_sdvo_write_cmd(intel_output
,
2706 SDVO_CMD_GET_HUE
, NULL
, 0);
2707 status
= intel_sdvo_read_response(intel_output
,
2709 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2710 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2713 sdvo_priv
->max_hue
= data_value
[0];
2714 sdvo_priv
->cur_hue
= response
;
2715 sdvo_priv
->hue_property
=
2716 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2718 sdvo_priv
->hue_property
->values
[0] = 0;
2719 sdvo_priv
->hue_property
->values
[1] =
2721 drm_connector_attach_property(connector
,
2722 sdvo_priv
->hue_property
,
2723 sdvo_priv
->cur_hue
);
2724 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2725 data_value
[0], data_value
[1], response
);
2728 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
) {
2729 if (sdvo_data
.brightness
) {
2730 intel_sdvo_write_cmd(intel_output
,
2731 SDVO_CMD_GET_MAX_BRIGHTNESS
, NULL
, 0);
2732 status
= intel_sdvo_read_response(intel_output
,
2734 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2735 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2738 intel_sdvo_write_cmd(intel_output
,
2739 SDVO_CMD_GET_BRIGHTNESS
, NULL
, 0);
2740 status
= intel_sdvo_read_response(intel_output
,
2742 if (status
!= SDVO_CMD_STATUS_SUCCESS
) {
2743 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2746 sdvo_priv
->max_brightness
= data_value
[0];
2747 sdvo_priv
->cur_brightness
= response
;
2748 sdvo_priv
->brightness_property
=
2749 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
2751 sdvo_priv
->brightness_property
->values
[0] = 0;
2752 sdvo_priv
->brightness_property
->values
[1] =
2754 drm_connector_attach_property(connector
,
2755 sdvo_priv
->brightness_property
,
2756 sdvo_priv
->cur_brightness
);
2757 DRM_DEBUG_KMS("brightness: max %d, "
2758 "default %d, current %d\n",
2759 data_value
[0], data_value
[1], response
);
2765 bool intel_sdvo_init(struct drm_device
*dev
, int output_device
)
2767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2768 struct drm_connector
*connector
;
2769 struct intel_output
*intel_output
;
2770 struct intel_sdvo_priv
*sdvo_priv
;
2775 intel_output
= kcalloc(sizeof(struct intel_output
)+sizeof(struct intel_sdvo_priv
), 1, GFP_KERNEL
);
2776 if (!intel_output
) {
2780 sdvo_priv
= (struct intel_sdvo_priv
*)(intel_output
+ 1);
2781 sdvo_priv
->output_device
= output_device
;
2783 intel_output
->dev_priv
= sdvo_priv
;
2784 intel_output
->type
= INTEL_OUTPUT_SDVO
;
2786 /* setup the DDC bus. */
2787 if (output_device
== SDVOB
)
2788 intel_output
->i2c_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOCTRL_E for SDVOB");
2790 intel_output
->i2c_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOCTRL_E for SDVOC");
2792 if (!intel_output
->i2c_bus
)
2793 goto err_inteloutput
;
2795 sdvo_priv
->slave_addr
= intel_sdvo_get_slave_addr(dev
, output_device
);
2797 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
2798 intel_sdvo_i2c_bit_algo
.functionality
= intel_output
->i2c_bus
->algo
->functionality
;
2800 /* Read the regs to test if we can talk to the device */
2801 for (i
= 0; i
< 0x40; i
++) {
2802 if (!intel_sdvo_read_byte(intel_output
, i
, &ch
[i
])) {
2803 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
2804 output_device
== SDVOB
? 'B' : 'C');
2809 /* setup the DDC bus. */
2810 if (output_device
== SDVOB
) {
2811 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOB DDC BUS");
2812 sdvo_priv
->analog_ddc_bus
= intel_i2c_create(dev
, GPIOA
,
2813 "SDVOB/VGA DDC BUS");
2814 dev_priv
->hotplug_supported_mask
|= SDVOB_HOTPLUG_INT_STATUS
;
2816 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "SDVOC DDC BUS");
2817 sdvo_priv
->analog_ddc_bus
= intel_i2c_create(dev
, GPIOA
,
2818 "SDVOC/VGA DDC BUS");
2819 dev_priv
->hotplug_supported_mask
|= SDVOC_HOTPLUG_INT_STATUS
;
2822 if (intel_output
->ddc_bus
== NULL
)
2825 /* Wrap with our custom algo which switches to DDC mode */
2826 intel_output
->ddc_bus
->algo
= &intel_sdvo_i2c_bit_algo
;
2828 /* In defaut case sdvo lvds is false */
2829 intel_sdvo_get_capabilities(intel_output
, &sdvo_priv
->caps
);
2831 if (intel_sdvo_output_setup(intel_output
,
2832 sdvo_priv
->caps
.output_flags
) != true) {
2833 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
2834 output_device
== SDVOB
? 'B' : 'C');
2839 connector
= &intel_output
->base
;
2840 drm_connector_init(dev
, connector
, &intel_sdvo_connector_funcs
,
2841 connector
->connector_type
);
2843 drm_connector_helper_add(connector
, &intel_sdvo_connector_helper_funcs
);
2844 connector
->interlace_allowed
= 0;
2845 connector
->doublescan_allowed
= 0;
2846 connector
->display_info
.subpixel_order
= SubPixelHorizontalRGB
;
2848 drm_encoder_init(dev
, &intel_output
->enc
,
2849 &intel_sdvo_enc_funcs
, intel_output
->enc
.encoder_type
);
2851 drm_encoder_helper_add(&intel_output
->enc
, &intel_sdvo_helper_funcs
);
2853 drm_mode_connector_attach_encoder(&intel_output
->base
, &intel_output
->enc
);
2854 if (sdvo_priv
->is_tv
)
2855 intel_sdvo_tv_create_property(connector
);
2857 if (sdvo_priv
->is_tv
|| sdvo_priv
->is_lvds
)
2858 intel_sdvo_create_enhance_property(connector
);
2860 drm_sysfs_connector_add(connector
);
2862 intel_sdvo_select_ddc_bus(sdvo_priv
);
2864 /* Set the input timing to the screen. Assume always input 0. */
2865 intel_sdvo_set_target_input(intel_output
, true, false);
2867 intel_sdvo_get_input_pixel_clock_range(intel_output
,
2868 &sdvo_priv
->pixel_clock_min
,
2869 &sdvo_priv
->pixel_clock_max
);
2872 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
2873 "clock range %dMHz - %dMHz, "
2874 "input 1: %c, input 2: %c, "
2875 "output 1: %c, output 2: %c\n",
2876 SDVO_NAME(sdvo_priv
),
2877 sdvo_priv
->caps
.vendor_id
, sdvo_priv
->caps
.device_id
,
2878 sdvo_priv
->caps
.device_rev_id
,
2879 sdvo_priv
->pixel_clock_min
/ 1000,
2880 sdvo_priv
->pixel_clock_max
/ 1000,
2881 (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x1) ? 'Y' : 'N',
2882 (sdvo_priv
->caps
.sdvo_inputs_mask
& 0x2) ? 'Y' : 'N',
2883 /* check currently supported outputs */
2884 sdvo_priv
->caps
.output_flags
&
2885 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_RGB0
) ? 'Y' : 'N',
2886 sdvo_priv
->caps
.output_flags
&
2887 (SDVO_OUTPUT_TMDS1
| SDVO_OUTPUT_RGB1
) ? 'Y' : 'N');
2892 if (sdvo_priv
->analog_ddc_bus
!= NULL
)
2893 intel_i2c_destroy(sdvo_priv
->analog_ddc_bus
);
2894 if (intel_output
->ddc_bus
!= NULL
)
2895 intel_i2c_destroy(intel_output
->ddc_bus
);
2896 if (intel_output
->i2c_bus
!= NULL
)
2897 intel_i2c_destroy(intel_output
->i2c_bus
);
2899 kfree(intel_output
);