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>
29 #include <linux/delay.h>
30 #include <linux/export.h>
31 #include <linux/i2c.h>
32 #include <linux/slab.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_edid.h>
37 #include <drm/i915_drm.h>
40 #include "intel_atomic.h"
41 #include "intel_connector.h"
42 #include "intel_display_types.h"
43 #include "intel_fifo_underrun.h"
44 #include "intel_gmbus.h"
45 #include "intel_hdmi.h"
46 #include "intel_hotplug.h"
47 #include "intel_panel.h"
48 #include "intel_sdvo.h"
49 #include "intel_sdvo_regs.h"
51 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
52 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
53 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
54 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
56 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
59 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
60 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
61 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
62 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
63 #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
66 static const char * const tv_format_names
[] = {
67 "NTSC_M" , "NTSC_J" , "NTSC_443",
68 "PAL_B" , "PAL_D" , "PAL_G" ,
69 "PAL_H" , "PAL_I" , "PAL_M" ,
70 "PAL_N" , "PAL_NC" , "PAL_60" ,
71 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
72 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
76 #define TV_FORMAT_NUM ARRAY_SIZE(tv_format_names)
79 struct intel_encoder base
;
81 struct i2c_adapter
*i2c
;
84 struct i2c_adapter ddc
;
86 /* Register for the SDVO device: SDVOB or SDVOC */
89 /* Active outputs controlled by this SDVO output */
90 u16 controlled_output
;
93 * Capabilities of the SDVO device returned by
94 * intel_sdvo_get_capabilities()
96 struct intel_sdvo_caps caps
;
98 /* Pixel clock limitations reported by the SDVO device, in kHz */
99 int pixel_clock_min
, pixel_clock_max
;
102 * For multiple function SDVO device,
103 * this is for current attached outputs.
108 * Hotplug activation bits for this device
114 bool has_hdmi_monitor
;
117 /* DDC bus used by this SDVO encoder */
121 * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
126 struct intel_sdvo_connector
{
127 struct intel_connector base
;
129 /* Mark the type of connector */
132 /* This contains all current supported TV format */
133 u8 tv_format_supported
[TV_FORMAT_NUM
];
134 int format_supported_num
;
135 struct drm_property
*tv_format
;
137 /* add the property for the SDVO-TV */
138 struct drm_property
*left
;
139 struct drm_property
*right
;
140 struct drm_property
*top
;
141 struct drm_property
*bottom
;
142 struct drm_property
*hpos
;
143 struct drm_property
*vpos
;
144 struct drm_property
*contrast
;
145 struct drm_property
*saturation
;
146 struct drm_property
*hue
;
147 struct drm_property
*sharpness
;
148 struct drm_property
*flicker_filter
;
149 struct drm_property
*flicker_filter_adaptive
;
150 struct drm_property
*flicker_filter_2d
;
151 struct drm_property
*tv_chroma_filter
;
152 struct drm_property
*tv_luma_filter
;
153 struct drm_property
*dot_crawl
;
155 /* add the property for the SDVO-TV/LVDS */
156 struct drm_property
*brightness
;
158 /* this is to get the range of margin.*/
159 u32 max_hscan
, max_vscan
;
162 * This is set if we treat the device as HDMI, instead of DVI.
167 struct intel_sdvo_connector_state
{
168 /* base.base: tv.saturation/contrast/hue/brightness */
169 struct intel_digital_connector_state base
;
172 unsigned overscan_h
, overscan_v
, hpos
, vpos
, sharpness
;
173 unsigned flicker_filter
, flicker_filter_2d
, flicker_filter_adaptive
;
174 unsigned chroma_filter
, luma_filter
, dot_crawl
;
178 static struct intel_sdvo
*to_sdvo(struct intel_encoder
*encoder
)
180 return container_of(encoder
, struct intel_sdvo
, base
);
183 static struct intel_sdvo
*intel_attached_sdvo(struct intel_connector
*connector
)
185 return to_sdvo(intel_attached_encoder(connector
));
188 static struct intel_sdvo_connector
*
189 to_intel_sdvo_connector(struct drm_connector
*connector
)
191 return container_of(connector
, struct intel_sdvo_connector
, base
.base
);
194 #define to_intel_sdvo_connector_state(conn_state) \
195 container_of((conn_state), struct intel_sdvo_connector_state, base.base)
198 intel_sdvo_output_setup(struct intel_sdvo
*intel_sdvo
, u16 flags
);
200 intel_sdvo_tv_create_property(struct intel_sdvo
*intel_sdvo
,
201 struct intel_sdvo_connector
*intel_sdvo_connector
,
204 intel_sdvo_create_enhance_property(struct intel_sdvo
*intel_sdvo
,
205 struct intel_sdvo_connector
*intel_sdvo_connector
);
208 * Writes the SDVOB or SDVOC with the given value, but always writes both
209 * SDVOB and SDVOC to work around apparent hardware issues (according to
210 * comments in the BIOS).
212 static void intel_sdvo_write_sdvox(struct intel_sdvo
*intel_sdvo
, u32 val
)
214 struct drm_device
*dev
= intel_sdvo
->base
.base
.dev
;
215 struct drm_i915_private
*dev_priv
= to_i915(dev
);
216 u32 bval
= val
, cval
= val
;
219 if (HAS_PCH_SPLIT(dev_priv
)) {
220 I915_WRITE(intel_sdvo
->sdvo_reg
, val
);
221 POSTING_READ(intel_sdvo
->sdvo_reg
);
223 * HW workaround, need to write this twice for issue
224 * that may result in first write getting masked.
226 if (HAS_PCH_IBX(dev_priv
)) {
227 I915_WRITE(intel_sdvo
->sdvo_reg
, val
);
228 POSTING_READ(intel_sdvo
->sdvo_reg
);
233 if (intel_sdvo
->port
== PORT_B
)
234 cval
= I915_READ(GEN3_SDVOC
);
236 bval
= I915_READ(GEN3_SDVOB
);
239 * Write the registers twice for luck. Sometimes,
240 * writing them only once doesn't appear to 'stick'.
241 * The BIOS does this too. Yay, magic
243 for (i
= 0; i
< 2; i
++) {
244 I915_WRITE(GEN3_SDVOB
, bval
);
245 POSTING_READ(GEN3_SDVOB
);
247 I915_WRITE(GEN3_SDVOC
, cval
);
248 POSTING_READ(GEN3_SDVOC
);
252 static bool intel_sdvo_read_byte(struct intel_sdvo
*intel_sdvo
, u8 addr
, u8
*ch
)
254 struct i2c_msg msgs
[] = {
256 .addr
= intel_sdvo
->slave_addr
,
262 .addr
= intel_sdvo
->slave_addr
,
270 if ((ret
= i2c_transfer(intel_sdvo
->i2c
, msgs
, 2)) == 2)
273 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret
);
277 #define SDVO_CMD_NAME_ENTRY(cmd_) { .cmd = SDVO_CMD_ ## cmd_, .name = #cmd_ }
279 /** Mapping of command numbers to names, for debug output */
280 static const struct {
283 } __attribute__ ((packed
)) sdvo_cmd_names
[] = {
284 SDVO_CMD_NAME_ENTRY(RESET
),
285 SDVO_CMD_NAME_ENTRY(GET_DEVICE_CAPS
),
286 SDVO_CMD_NAME_ENTRY(GET_FIRMWARE_REV
),
287 SDVO_CMD_NAME_ENTRY(GET_TRAINED_INPUTS
),
288 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_OUTPUTS
),
289 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_OUTPUTS
),
290 SDVO_CMD_NAME_ENTRY(GET_IN_OUT_MAP
),
291 SDVO_CMD_NAME_ENTRY(SET_IN_OUT_MAP
),
292 SDVO_CMD_NAME_ENTRY(GET_ATTACHED_DISPLAYS
),
293 SDVO_CMD_NAME_ENTRY(GET_HOT_PLUG_SUPPORT
),
294 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_HOT_PLUG
),
295 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_HOT_PLUG
),
296 SDVO_CMD_NAME_ENTRY(GET_INTERRUPT_EVENT_SOURCE
),
297 SDVO_CMD_NAME_ENTRY(SET_TARGET_INPUT
),
298 SDVO_CMD_NAME_ENTRY(SET_TARGET_OUTPUT
),
299 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART1
),
300 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART2
),
301 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART1
),
302 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART2
),
303 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART1
),
304 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART2
),
305 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART1
),
306 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART2
),
307 SDVO_CMD_NAME_ENTRY(CREATE_PREFERRED_INPUT_TIMING
),
308 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART1
),
309 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART2
),
310 SDVO_CMD_NAME_ENTRY(GET_INPUT_PIXEL_CLOCK_RANGE
),
311 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_PIXEL_CLOCK_RANGE
),
312 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_CLOCK_RATE_MULTS
),
313 SDVO_CMD_NAME_ENTRY(GET_CLOCK_RATE_MULT
),
314 SDVO_CMD_NAME_ENTRY(SET_CLOCK_RATE_MULT
),
315 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_TV_FORMATS
),
316 SDVO_CMD_NAME_ENTRY(GET_TV_FORMAT
),
317 SDVO_CMD_NAME_ENTRY(SET_TV_FORMAT
),
318 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_POWER_STATES
),
319 SDVO_CMD_NAME_ENTRY(GET_POWER_STATE
),
320 SDVO_CMD_NAME_ENTRY(SET_ENCODER_POWER_STATE
),
321 SDVO_CMD_NAME_ENTRY(SET_DISPLAY_POWER_STATE
),
322 SDVO_CMD_NAME_ENTRY(SET_CONTROL_BUS_SWITCH
),
323 SDVO_CMD_NAME_ENTRY(GET_SDTV_RESOLUTION_SUPPORT
),
324 SDVO_CMD_NAME_ENTRY(GET_SCALED_HDTV_RESOLUTION_SUPPORT
),
325 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_ENHANCEMENTS
),
327 /* Add the op code for SDVO enhancements */
328 SDVO_CMD_NAME_ENTRY(GET_MAX_HPOS
),
329 SDVO_CMD_NAME_ENTRY(GET_HPOS
),
330 SDVO_CMD_NAME_ENTRY(SET_HPOS
),
331 SDVO_CMD_NAME_ENTRY(GET_MAX_VPOS
),
332 SDVO_CMD_NAME_ENTRY(GET_VPOS
),
333 SDVO_CMD_NAME_ENTRY(SET_VPOS
),
334 SDVO_CMD_NAME_ENTRY(GET_MAX_SATURATION
),
335 SDVO_CMD_NAME_ENTRY(GET_SATURATION
),
336 SDVO_CMD_NAME_ENTRY(SET_SATURATION
),
337 SDVO_CMD_NAME_ENTRY(GET_MAX_HUE
),
338 SDVO_CMD_NAME_ENTRY(GET_HUE
),
339 SDVO_CMD_NAME_ENTRY(SET_HUE
),
340 SDVO_CMD_NAME_ENTRY(GET_MAX_CONTRAST
),
341 SDVO_CMD_NAME_ENTRY(GET_CONTRAST
),
342 SDVO_CMD_NAME_ENTRY(SET_CONTRAST
),
343 SDVO_CMD_NAME_ENTRY(GET_MAX_BRIGHTNESS
),
344 SDVO_CMD_NAME_ENTRY(GET_BRIGHTNESS
),
345 SDVO_CMD_NAME_ENTRY(SET_BRIGHTNESS
),
346 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_H
),
347 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_H
),
348 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_H
),
349 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_V
),
350 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_V
),
351 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_V
),
352 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER
),
353 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER
),
354 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER
),
355 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_ADAPTIVE
),
356 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_ADAPTIVE
),
357 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_ADAPTIVE
),
358 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_2D
),
359 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_2D
),
360 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_2D
),
361 SDVO_CMD_NAME_ENTRY(GET_MAX_SHARPNESS
),
362 SDVO_CMD_NAME_ENTRY(GET_SHARPNESS
),
363 SDVO_CMD_NAME_ENTRY(SET_SHARPNESS
),
364 SDVO_CMD_NAME_ENTRY(GET_DOT_CRAWL
),
365 SDVO_CMD_NAME_ENTRY(SET_DOT_CRAWL
),
366 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_CHROMA_FILTER
),
367 SDVO_CMD_NAME_ENTRY(GET_TV_CHROMA_FILTER
),
368 SDVO_CMD_NAME_ENTRY(SET_TV_CHROMA_FILTER
),
369 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_LUMA_FILTER
),
370 SDVO_CMD_NAME_ENTRY(GET_TV_LUMA_FILTER
),
371 SDVO_CMD_NAME_ENTRY(SET_TV_LUMA_FILTER
),
374 SDVO_CMD_NAME_ENTRY(GET_SUPP_ENCODE
),
375 SDVO_CMD_NAME_ENTRY(GET_ENCODE
),
376 SDVO_CMD_NAME_ENTRY(SET_ENCODE
),
377 SDVO_CMD_NAME_ENTRY(SET_PIXEL_REPLI
),
378 SDVO_CMD_NAME_ENTRY(GET_PIXEL_REPLI
),
379 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY_CAP
),
380 SDVO_CMD_NAME_ENTRY(SET_COLORIMETRY
),
381 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY
),
382 SDVO_CMD_NAME_ENTRY(GET_AUDIO_ENCRYPT_PREFER
),
383 SDVO_CMD_NAME_ENTRY(SET_AUDIO_STAT
),
384 SDVO_CMD_NAME_ENTRY(GET_AUDIO_STAT
),
385 SDVO_CMD_NAME_ENTRY(GET_HBUF_INDEX
),
386 SDVO_CMD_NAME_ENTRY(SET_HBUF_INDEX
),
387 SDVO_CMD_NAME_ENTRY(GET_HBUF_INFO
),
388 SDVO_CMD_NAME_ENTRY(GET_HBUF_AV_SPLIT
),
389 SDVO_CMD_NAME_ENTRY(SET_HBUF_AV_SPLIT
),
390 SDVO_CMD_NAME_ENTRY(GET_HBUF_TXRATE
),
391 SDVO_CMD_NAME_ENTRY(SET_HBUF_TXRATE
),
392 SDVO_CMD_NAME_ENTRY(SET_HBUF_DATA
),
393 SDVO_CMD_NAME_ENTRY(GET_HBUF_DATA
),
396 #undef SDVO_CMD_NAME_ENTRY
398 static const char *sdvo_cmd_name(u8 cmd
)
402 for (i
= 0; i
< ARRAY_SIZE(sdvo_cmd_names
); i
++) {
403 if (cmd
== sdvo_cmd_names
[i
].cmd
)
404 return sdvo_cmd_names
[i
].name
;
410 #define SDVO_NAME(svdo) ((svdo)->port == PORT_B ? "SDVOB" : "SDVOC")
412 static void intel_sdvo_debug_write(struct intel_sdvo
*intel_sdvo
, u8 cmd
,
413 const void *args
, int args_len
)
415 const char *cmd_name
;
418 char buffer
[BUF_LEN
];
420 #define BUF_PRINT(args...) \
421 pos += snprintf(buffer + pos, max_t(int, BUF_LEN - pos, 0), args)
424 for (i
= 0; i
< args_len
; i
++) {
425 BUF_PRINT("%02X ", ((u8
*)args
)[i
]);
431 cmd_name
= sdvo_cmd_name(cmd
);
433 BUF_PRINT("(%s)", cmd_name
);
435 BUF_PRINT("(%02X)", cmd
);
436 BUG_ON(pos
>= BUF_LEN
- 1);
440 DRM_DEBUG_KMS("%s: W: %02X %s\n", SDVO_NAME(intel_sdvo
), cmd
, buffer
);
443 static const char * const cmd_status_names
[] = {
444 [SDVO_CMD_STATUS_POWER_ON
] = "Power on",
445 [SDVO_CMD_STATUS_SUCCESS
] = "Success",
446 [SDVO_CMD_STATUS_NOTSUPP
] = "Not supported",
447 [SDVO_CMD_STATUS_INVALID_ARG
] = "Invalid arg",
448 [SDVO_CMD_STATUS_PENDING
] = "Pending",
449 [SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED
] = "Target not specified",
450 [SDVO_CMD_STATUS_SCALING_NOT_SUPP
] = "Scaling not supported",
453 static const char *sdvo_cmd_status(u8 status
)
455 if (status
< ARRAY_SIZE(cmd_status_names
))
456 return cmd_status_names
[status
];
461 static bool __intel_sdvo_write_cmd(struct intel_sdvo
*intel_sdvo
, u8 cmd
,
462 const void *args
, int args_len
,
466 struct i2c_msg
*msgs
;
469 /* Would be simpler to allocate both in one go ? */
470 buf
= kzalloc(args_len
* 2 + 2, GFP_KERNEL
);
474 msgs
= kcalloc(args_len
+ 3, sizeof(*msgs
), GFP_KERNEL
);
480 intel_sdvo_debug_write(intel_sdvo
, cmd
, args
, args_len
);
482 for (i
= 0; i
< args_len
; i
++) {
483 msgs
[i
].addr
= intel_sdvo
->slave_addr
;
486 msgs
[i
].buf
= buf
+ 2 *i
;
487 buf
[2*i
+ 0] = SDVO_I2C_ARG_0
- i
;
488 buf
[2*i
+ 1] = ((u8
*)args
)[i
];
490 msgs
[i
].addr
= intel_sdvo
->slave_addr
;
493 msgs
[i
].buf
= buf
+ 2*i
;
494 buf
[2*i
+ 0] = SDVO_I2C_OPCODE
;
497 /* the following two are to read the response */
498 status
= SDVO_I2C_CMD_STATUS
;
499 msgs
[i
+1].addr
= intel_sdvo
->slave_addr
;
502 msgs
[i
+1].buf
= &status
;
504 msgs
[i
+2].addr
= intel_sdvo
->slave_addr
;
505 msgs
[i
+2].flags
= I2C_M_RD
;
507 msgs
[i
+2].buf
= &status
;
510 ret
= i2c_transfer(intel_sdvo
->i2c
, msgs
, i
+3);
512 ret
= __i2c_transfer(intel_sdvo
->i2c
, msgs
, i
+3);
514 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret
);
519 /* failure in I2C transfer */
520 DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret
, i
+3);
530 static bool intel_sdvo_write_cmd(struct intel_sdvo
*intel_sdvo
, u8 cmd
,
531 const void *args
, int args_len
)
533 return __intel_sdvo_write_cmd(intel_sdvo
, cmd
, args
, args_len
, true);
536 static bool intel_sdvo_read_response(struct intel_sdvo
*intel_sdvo
,
537 void *response
, int response_len
)
539 const char *cmd_status
;
540 u8 retry
= 15; /* 5 quick checks, followed by 10 long checks */
544 char buffer
[BUF_LEN
];
549 * The documentation states that all commands will be
550 * processed within 15µs, and that we need only poll
551 * the status byte a maximum of 3 times in order for the
552 * command to be complete.
554 * Check 5 times in case the hardware failed to read the docs.
556 * Also beware that the first response by many devices is to
557 * reply PENDING and stall for time. TVs are notorious for
558 * requiring longer than specified to complete their replies.
559 * Originally (in the DDX long ago), the delay was only ever 15ms
560 * with an additional delay of 30ms applied for TVs added later after
561 * many experiments. To accommodate both sets of delays, we do a
562 * sequence of slow checks if the device is falling behind and fails
563 * to reply within 5*15µs.
565 if (!intel_sdvo_read_byte(intel_sdvo
,
570 while ((status
== SDVO_CMD_STATUS_PENDING
||
571 status
== SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED
) && --retry
) {
577 if (!intel_sdvo_read_byte(intel_sdvo
,
583 #define BUF_PRINT(args...) \
584 pos += snprintf(buffer + pos, max_t(int, BUF_LEN - pos, 0), args)
586 cmd_status
= sdvo_cmd_status(status
);
588 BUF_PRINT("(%s)", cmd_status
);
590 BUF_PRINT("(??? %d)", status
);
592 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
595 /* Read the command response */
596 for (i
= 0; i
< response_len
; i
++) {
597 if (!intel_sdvo_read_byte(intel_sdvo
,
598 SDVO_I2C_RETURN_0
+ i
,
599 &((u8
*)response
)[i
]))
601 BUF_PRINT(" %02X", ((u8
*)response
)[i
]);
603 BUG_ON(pos
>= BUF_LEN
- 1);
607 DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo
), buffer
);
611 DRM_DEBUG_KMS("%s: R: ... failed %s\n",
612 SDVO_NAME(intel_sdvo
), buffer
);
616 static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode
*adjusted_mode
)
618 if (adjusted_mode
->crtc_clock
>= 100000)
620 else if (adjusted_mode
->crtc_clock
>= 50000)
626 static bool __intel_sdvo_set_control_bus_switch(struct intel_sdvo
*intel_sdvo
,
629 /* This must be the immediately preceding write before the i2c xfer */
630 return __intel_sdvo_write_cmd(intel_sdvo
,
631 SDVO_CMD_SET_CONTROL_BUS_SWITCH
,
635 static bool intel_sdvo_set_value(struct intel_sdvo
*intel_sdvo
, u8 cmd
, const void *data
, int len
)
637 if (!intel_sdvo_write_cmd(intel_sdvo
, cmd
, data
, len
))
640 return intel_sdvo_read_response(intel_sdvo
, NULL
, 0);
644 intel_sdvo_get_value(struct intel_sdvo
*intel_sdvo
, u8 cmd
, void *value
, int len
)
646 if (!intel_sdvo_write_cmd(intel_sdvo
, cmd
, NULL
, 0))
649 return intel_sdvo_read_response(intel_sdvo
, value
, len
);
652 static bool intel_sdvo_set_target_input(struct intel_sdvo
*intel_sdvo
)
654 struct intel_sdvo_set_target_input_args targets
= {0};
655 return intel_sdvo_set_value(intel_sdvo
,
656 SDVO_CMD_SET_TARGET_INPUT
,
657 &targets
, sizeof(targets
));
661 * Return whether each input is trained.
663 * This function is making an assumption about the layout of the response,
664 * which should be checked against the docs.
666 static bool intel_sdvo_get_trained_inputs(struct intel_sdvo
*intel_sdvo
, bool *input_1
, bool *input_2
)
668 struct intel_sdvo_get_trained_inputs_response response
;
670 BUILD_BUG_ON(sizeof(response
) != 1);
671 if (!intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_TRAINED_INPUTS
,
672 &response
, sizeof(response
)))
675 *input_1
= response
.input0_trained
;
676 *input_2
= response
.input1_trained
;
680 static bool intel_sdvo_set_active_outputs(struct intel_sdvo
*intel_sdvo
,
683 return intel_sdvo_set_value(intel_sdvo
,
684 SDVO_CMD_SET_ACTIVE_OUTPUTS
,
685 &outputs
, sizeof(outputs
));
688 static bool intel_sdvo_get_active_outputs(struct intel_sdvo
*intel_sdvo
,
691 return intel_sdvo_get_value(intel_sdvo
,
692 SDVO_CMD_GET_ACTIVE_OUTPUTS
,
693 outputs
, sizeof(*outputs
));
696 static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo
*intel_sdvo
,
699 u8 state
= SDVO_ENCODER_STATE_ON
;
702 case DRM_MODE_DPMS_ON
:
703 state
= SDVO_ENCODER_STATE_ON
;
705 case DRM_MODE_DPMS_STANDBY
:
706 state
= SDVO_ENCODER_STATE_STANDBY
;
708 case DRM_MODE_DPMS_SUSPEND
:
709 state
= SDVO_ENCODER_STATE_SUSPEND
;
711 case DRM_MODE_DPMS_OFF
:
712 state
= SDVO_ENCODER_STATE_OFF
;
716 return intel_sdvo_set_value(intel_sdvo
,
717 SDVO_CMD_SET_ENCODER_POWER_STATE
, &state
, sizeof(state
));
720 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo
*intel_sdvo
,
724 struct intel_sdvo_pixel_clock_range clocks
;
726 BUILD_BUG_ON(sizeof(clocks
) != 4);
727 if (!intel_sdvo_get_value(intel_sdvo
,
728 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
,
729 &clocks
, sizeof(clocks
)))
732 /* Convert the values from units of 10 kHz to kHz. */
733 *clock_min
= clocks
.min
* 10;
734 *clock_max
= clocks
.max
* 10;
738 static bool intel_sdvo_set_target_output(struct intel_sdvo
*intel_sdvo
,
741 return intel_sdvo_set_value(intel_sdvo
,
742 SDVO_CMD_SET_TARGET_OUTPUT
,
743 &outputs
, sizeof(outputs
));
746 static bool intel_sdvo_set_timing(struct intel_sdvo
*intel_sdvo
, u8 cmd
,
747 struct intel_sdvo_dtd
*dtd
)
749 return intel_sdvo_set_value(intel_sdvo
, cmd
, &dtd
->part1
, sizeof(dtd
->part1
)) &&
750 intel_sdvo_set_value(intel_sdvo
, cmd
+ 1, &dtd
->part2
, sizeof(dtd
->part2
));
753 static bool intel_sdvo_get_timing(struct intel_sdvo
*intel_sdvo
, u8 cmd
,
754 struct intel_sdvo_dtd
*dtd
)
756 return intel_sdvo_get_value(intel_sdvo
, cmd
, &dtd
->part1
, sizeof(dtd
->part1
)) &&
757 intel_sdvo_get_value(intel_sdvo
, cmd
+ 1, &dtd
->part2
, sizeof(dtd
->part2
));
760 static bool intel_sdvo_set_input_timing(struct intel_sdvo
*intel_sdvo
,
761 struct intel_sdvo_dtd
*dtd
)
763 return intel_sdvo_set_timing(intel_sdvo
,
764 SDVO_CMD_SET_INPUT_TIMINGS_PART1
, dtd
);
767 static bool intel_sdvo_set_output_timing(struct intel_sdvo
*intel_sdvo
,
768 struct intel_sdvo_dtd
*dtd
)
770 return intel_sdvo_set_timing(intel_sdvo
,
771 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
, dtd
);
774 static bool intel_sdvo_get_input_timing(struct intel_sdvo
*intel_sdvo
,
775 struct intel_sdvo_dtd
*dtd
)
777 return intel_sdvo_get_timing(intel_sdvo
,
778 SDVO_CMD_GET_INPUT_TIMINGS_PART1
, dtd
);
782 intel_sdvo_create_preferred_input_timing(struct intel_sdvo
*intel_sdvo
,
783 struct intel_sdvo_connector
*intel_sdvo_connector
,
788 struct intel_sdvo_preferred_input_timing_args args
;
790 memset(&args
, 0, sizeof(args
));
793 args
.height
= height
;
796 if (IS_LVDS(intel_sdvo_connector
)) {
797 const struct drm_display_mode
*fixed_mode
=
798 intel_sdvo_connector
->base
.panel
.fixed_mode
;
800 if (fixed_mode
->hdisplay
!= width
||
801 fixed_mode
->vdisplay
!= height
)
805 return intel_sdvo_set_value(intel_sdvo
,
806 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
,
807 &args
, sizeof(args
));
810 static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo
*intel_sdvo
,
811 struct intel_sdvo_dtd
*dtd
)
813 BUILD_BUG_ON(sizeof(dtd
->part1
) != 8);
814 BUILD_BUG_ON(sizeof(dtd
->part2
) != 8);
815 return intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
,
816 &dtd
->part1
, sizeof(dtd
->part1
)) &&
817 intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
,
818 &dtd
->part2
, sizeof(dtd
->part2
));
821 static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo
*intel_sdvo
, u8 val
)
823 return intel_sdvo_set_value(intel_sdvo
, SDVO_CMD_SET_CLOCK_RATE_MULT
, &val
, 1);
826 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd
*dtd
,
827 const struct drm_display_mode
*mode
)
830 u16 h_blank_len
, h_sync_len
, v_blank_len
, v_sync_len
;
831 u16 h_sync_offset
, v_sync_offset
;
834 memset(dtd
, 0, sizeof(*dtd
));
836 width
= mode
->hdisplay
;
837 height
= mode
->vdisplay
;
839 /* do some mode translations */
840 h_blank_len
= mode
->htotal
- mode
->hdisplay
;
841 h_sync_len
= mode
->hsync_end
- mode
->hsync_start
;
843 v_blank_len
= mode
->vtotal
- mode
->vdisplay
;
844 v_sync_len
= mode
->vsync_end
- mode
->vsync_start
;
846 h_sync_offset
= mode
->hsync_start
- mode
->hdisplay
;
847 v_sync_offset
= mode
->vsync_start
- mode
->vdisplay
;
849 mode_clock
= mode
->clock
;
851 dtd
->part1
.clock
= mode_clock
;
853 dtd
->part1
.h_active
= width
& 0xff;
854 dtd
->part1
.h_blank
= h_blank_len
& 0xff;
855 dtd
->part1
.h_high
= (((width
>> 8) & 0xf) << 4) |
856 ((h_blank_len
>> 8) & 0xf);
857 dtd
->part1
.v_active
= height
& 0xff;
858 dtd
->part1
.v_blank
= v_blank_len
& 0xff;
859 dtd
->part1
.v_high
= (((height
>> 8) & 0xf) << 4) |
860 ((v_blank_len
>> 8) & 0xf);
862 dtd
->part2
.h_sync_off
= h_sync_offset
& 0xff;
863 dtd
->part2
.h_sync_width
= h_sync_len
& 0xff;
864 dtd
->part2
.v_sync_off_width
= (v_sync_offset
& 0xf) << 4 |
866 dtd
->part2
.sync_off_width_high
= ((h_sync_offset
& 0x300) >> 2) |
867 ((h_sync_len
& 0x300) >> 4) | ((v_sync_offset
& 0x30) >> 2) |
868 ((v_sync_len
& 0x30) >> 4);
870 dtd
->part2
.dtd_flags
= 0x18;
871 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
872 dtd
->part2
.dtd_flags
|= DTD_FLAG_INTERLACE
;
873 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
874 dtd
->part2
.dtd_flags
|= DTD_FLAG_HSYNC_POSITIVE
;
875 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
876 dtd
->part2
.dtd_flags
|= DTD_FLAG_VSYNC_POSITIVE
;
878 dtd
->part2
.v_sync_off_high
= v_sync_offset
& 0xc0;
881 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode
*pmode
,
882 const struct intel_sdvo_dtd
*dtd
)
884 struct drm_display_mode mode
= {};
886 mode
.hdisplay
= dtd
->part1
.h_active
;
887 mode
.hdisplay
+= ((dtd
->part1
.h_high
>> 4) & 0x0f) << 8;
888 mode
.hsync_start
= mode
.hdisplay
+ dtd
->part2
.h_sync_off
;
889 mode
.hsync_start
+= (dtd
->part2
.sync_off_width_high
& 0xc0) << 2;
890 mode
.hsync_end
= mode
.hsync_start
+ dtd
->part2
.h_sync_width
;
891 mode
.hsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x30) << 4;
892 mode
.htotal
= mode
.hdisplay
+ dtd
->part1
.h_blank
;
893 mode
.htotal
+= (dtd
->part1
.h_high
& 0xf) << 8;
895 mode
.vdisplay
= dtd
->part1
.v_active
;
896 mode
.vdisplay
+= ((dtd
->part1
.v_high
>> 4) & 0x0f) << 8;
897 mode
.vsync_start
= mode
.vdisplay
;
898 mode
.vsync_start
+= (dtd
->part2
.v_sync_off_width
>> 4) & 0xf;
899 mode
.vsync_start
+= (dtd
->part2
.sync_off_width_high
& 0x0c) << 2;
900 mode
.vsync_start
+= dtd
->part2
.v_sync_off_high
& 0xc0;
901 mode
.vsync_end
= mode
.vsync_start
+
902 (dtd
->part2
.v_sync_off_width
& 0xf);
903 mode
.vsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x3) << 4;
904 mode
.vtotal
= mode
.vdisplay
+ dtd
->part1
.v_blank
;
905 mode
.vtotal
+= (dtd
->part1
.v_high
& 0xf) << 8;
907 mode
.clock
= dtd
->part1
.clock
* 10;
909 if (dtd
->part2
.dtd_flags
& DTD_FLAG_INTERLACE
)
910 mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
911 if (dtd
->part2
.dtd_flags
& DTD_FLAG_HSYNC_POSITIVE
)
912 mode
.flags
|= DRM_MODE_FLAG_PHSYNC
;
914 mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
915 if (dtd
->part2
.dtd_flags
& DTD_FLAG_VSYNC_POSITIVE
)
916 mode
.flags
|= DRM_MODE_FLAG_PVSYNC
;
918 mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
920 drm_mode_set_crtcinfo(&mode
, 0);
922 drm_mode_copy(pmode
, &mode
);
925 static bool intel_sdvo_check_supp_encode(struct intel_sdvo
*intel_sdvo
)
927 struct intel_sdvo_encode encode
;
929 BUILD_BUG_ON(sizeof(encode
) != 2);
930 return intel_sdvo_get_value(intel_sdvo
,
931 SDVO_CMD_GET_SUPP_ENCODE
,
932 &encode
, sizeof(encode
));
935 static bool intel_sdvo_set_encode(struct intel_sdvo
*intel_sdvo
,
938 return intel_sdvo_set_value(intel_sdvo
, SDVO_CMD_SET_ENCODE
, &mode
, 1);
941 static bool intel_sdvo_set_colorimetry(struct intel_sdvo
*intel_sdvo
,
944 return intel_sdvo_set_value(intel_sdvo
, SDVO_CMD_SET_COLORIMETRY
, &mode
, 1);
947 static bool intel_sdvo_set_audio_state(struct intel_sdvo
*intel_sdvo
,
950 return intel_sdvo_set_value(intel_sdvo
, SDVO_CMD_SET_AUDIO_STAT
,
954 static bool intel_sdvo_get_hbuf_size(struct intel_sdvo
*intel_sdvo
,
957 if (!intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_HBUF_INFO
,
961 /* Buffer size is 0 based, hooray! However zero means zero. */
969 static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo
*intel_sdvo
)
978 intel_sdvo_get_value(encoder
, SDVO_CMD_GET_HBUF_AV_SPLIT
, &av_split
, 1);
980 for (i
= 0; i
<= av_split
; i
++) {
981 set_buf_index
[0] = i
; set_buf_index
[1] = 0;
982 intel_sdvo_write_cmd(encoder
, SDVO_CMD_SET_HBUF_INDEX
,
984 intel_sdvo_write_cmd(encoder
, SDVO_CMD_GET_HBUF_INFO
, NULL
, 0);
985 intel_sdvo_read_response(encoder
, &buf_size
, 1);
988 for (j
= 0; j
<= buf_size
; j
+= 8) {
989 intel_sdvo_write_cmd(encoder
, SDVO_CMD_GET_HBUF_DATA
,
991 intel_sdvo_read_response(encoder
, pos
, 8);
998 static bool intel_sdvo_write_infoframe(struct intel_sdvo
*intel_sdvo
,
999 unsigned int if_index
, u8 tx_rate
,
1000 const u8
*data
, unsigned int length
)
1002 u8 set_buf_index
[2] = { if_index
, 0 };
1003 u8 hbuf_size
, tmp
[8];
1006 if (!intel_sdvo_set_value(intel_sdvo
,
1007 SDVO_CMD_SET_HBUF_INDEX
,
1011 if (!intel_sdvo_get_hbuf_size(intel_sdvo
, &hbuf_size
))
1014 DRM_DEBUG_KMS("writing sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1015 if_index
, length
, hbuf_size
);
1017 if (hbuf_size
< length
)
1020 for (i
= 0; i
< hbuf_size
; i
+= 8) {
1023 memcpy(tmp
, data
+ i
, min_t(unsigned, 8, length
- i
));
1025 if (!intel_sdvo_set_value(intel_sdvo
,
1026 SDVO_CMD_SET_HBUF_DATA
,
1031 return intel_sdvo_set_value(intel_sdvo
,
1032 SDVO_CMD_SET_HBUF_TXRATE
,
1036 static ssize_t
intel_sdvo_read_infoframe(struct intel_sdvo
*intel_sdvo
,
1037 unsigned int if_index
,
1038 u8
*data
, unsigned int length
)
1040 u8 set_buf_index
[2] = { if_index
, 0 };
1041 u8 hbuf_size
, tx_rate
, av_split
;
1044 if (!intel_sdvo_get_value(intel_sdvo
,
1045 SDVO_CMD_GET_HBUF_AV_SPLIT
,
1049 if (av_split
< if_index
)
1052 if (!intel_sdvo_set_value(intel_sdvo
,
1053 SDVO_CMD_SET_HBUF_INDEX
,
1057 if (!intel_sdvo_get_value(intel_sdvo
,
1058 SDVO_CMD_GET_HBUF_TXRATE
,
1062 if (tx_rate
== SDVO_HBUF_TX_DISABLED
)
1065 if (!intel_sdvo_get_hbuf_size(intel_sdvo
, &hbuf_size
))
1068 DRM_DEBUG_KMS("reading sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1069 if_index
, length
, hbuf_size
);
1071 hbuf_size
= min_t(unsigned int, length
, hbuf_size
);
1073 for (i
= 0; i
< hbuf_size
; i
+= 8) {
1074 if (!intel_sdvo_write_cmd(intel_sdvo
, SDVO_CMD_GET_HBUF_DATA
, NULL
, 0))
1076 if (!intel_sdvo_read_response(intel_sdvo
, &data
[i
],
1077 min_t(unsigned int, 8, hbuf_size
- i
)))
1084 static bool intel_sdvo_compute_avi_infoframe(struct intel_sdvo
*intel_sdvo
,
1085 struct intel_crtc_state
*crtc_state
,
1086 struct drm_connector_state
*conn_state
)
1088 struct hdmi_avi_infoframe
*frame
= &crtc_state
->infoframes
.avi
.avi
;
1089 const struct drm_display_mode
*adjusted_mode
=
1090 &crtc_state
->hw
.adjusted_mode
;
1093 if (!crtc_state
->has_hdmi_sink
)
1096 crtc_state
->infoframes
.enable
|=
1097 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI
);
1099 ret
= drm_hdmi_avi_infoframe_from_display_mode(frame
,
1100 conn_state
->connector
,
1105 drm_hdmi_avi_infoframe_quant_range(frame
,
1106 conn_state
->connector
,
1108 crtc_state
->limited_color_range
?
1109 HDMI_QUANTIZATION_RANGE_LIMITED
:
1110 HDMI_QUANTIZATION_RANGE_FULL
);
1112 ret
= hdmi_avi_infoframe_check(frame
);
1119 static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo
*intel_sdvo
,
1120 const struct intel_crtc_state
*crtc_state
)
1122 u8 sdvo_data
[HDMI_INFOFRAME_SIZE(AVI
)];
1123 const union hdmi_infoframe
*frame
= &crtc_state
->infoframes
.avi
;
1126 if ((crtc_state
->infoframes
.enable
&
1127 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI
)) == 0)
1130 if (WARN_ON(frame
->any
.type
!= HDMI_INFOFRAME_TYPE_AVI
))
1133 len
= hdmi_infoframe_pack_only(frame
, sdvo_data
, sizeof(sdvo_data
));
1134 if (WARN_ON(len
< 0))
1137 return intel_sdvo_write_infoframe(intel_sdvo
, SDVO_HBUF_INDEX_AVI_IF
,
1142 static void intel_sdvo_get_avi_infoframe(struct intel_sdvo
*intel_sdvo
,
1143 struct intel_crtc_state
*crtc_state
)
1145 u8 sdvo_data
[HDMI_INFOFRAME_SIZE(AVI
)];
1146 union hdmi_infoframe
*frame
= &crtc_state
->infoframes
.avi
;
1150 if (!crtc_state
->has_hdmi_sink
)
1153 len
= intel_sdvo_read_infoframe(intel_sdvo
, SDVO_HBUF_INDEX_AVI_IF
,
1154 sdvo_data
, sizeof(sdvo_data
));
1156 DRM_DEBUG_KMS("failed to read AVI infoframe\n");
1158 } else if (len
== 0) {
1162 crtc_state
->infoframes
.enable
|=
1163 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI
);
1165 ret
= hdmi_infoframe_unpack(frame
, sdvo_data
, len
);
1167 DRM_DEBUG_KMS("Failed to unpack AVI infoframe\n");
1171 if (frame
->any
.type
!= HDMI_INFOFRAME_TYPE_AVI
)
1172 DRM_DEBUG_KMS("Found the wrong infoframe type 0x%x (expected 0x%02x)\n",
1173 frame
->any
.type
, HDMI_INFOFRAME_TYPE_AVI
);
1176 static bool intel_sdvo_set_tv_format(struct intel_sdvo
*intel_sdvo
,
1177 const struct drm_connector_state
*conn_state
)
1179 struct intel_sdvo_tv_format format
;
1182 format_map
= 1 << conn_state
->tv
.mode
;
1183 memset(&format
, 0, sizeof(format
));
1184 memcpy(&format
, &format_map
, min(sizeof(format
), sizeof(format_map
)));
1186 BUILD_BUG_ON(sizeof(format
) != 6);
1187 return intel_sdvo_set_value(intel_sdvo
,
1188 SDVO_CMD_SET_TV_FORMAT
,
1189 &format
, sizeof(format
));
1193 intel_sdvo_set_output_timings_from_mode(struct intel_sdvo
*intel_sdvo
,
1194 const struct drm_display_mode
*mode
)
1196 struct intel_sdvo_dtd output_dtd
;
1198 if (!intel_sdvo_set_target_output(intel_sdvo
,
1199 intel_sdvo
->attached_output
))
1202 intel_sdvo_get_dtd_from_mode(&output_dtd
, mode
);
1203 if (!intel_sdvo_set_output_timing(intel_sdvo
, &output_dtd
))
1210 * Asks the sdvo controller for the preferred input mode given the output mode.
1211 * Unfortunately we have to set up the full output mode to do that.
1214 intel_sdvo_get_preferred_input_mode(struct intel_sdvo
*intel_sdvo
,
1215 struct intel_sdvo_connector
*intel_sdvo_connector
,
1216 const struct drm_display_mode
*mode
,
1217 struct drm_display_mode
*adjusted_mode
)
1219 struct intel_sdvo_dtd input_dtd
;
1221 /* Reset the input timing to the screen. Assume always input 0. */
1222 if (!intel_sdvo_set_target_input(intel_sdvo
))
1225 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo
,
1226 intel_sdvo_connector
,
1232 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo
,
1236 intel_sdvo_get_mode_from_dtd(adjusted_mode
, &input_dtd
);
1237 intel_sdvo
->dtd_sdvo_flags
= input_dtd
.part2
.sdvo_flags
;
1242 static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_state
*pipe_config
)
1244 unsigned dotclock
= pipe_config
->port_clock
;
1245 struct dpll
*clock
= &pipe_config
->dpll
;
1248 * SDVO TV has fixed PLL values depend on its clock range,
1249 * this mirrors vbios setting.
1251 if (dotclock
>= 100000 && dotclock
< 140500) {
1257 } else if (dotclock
>= 140500 && dotclock
<= 200000) {
1264 WARN(1, "SDVO TV clock out of range: %i\n", dotclock
);
1267 pipe_config
->clock_set
= true;
1270 static int intel_sdvo_compute_config(struct intel_encoder
*encoder
,
1271 struct intel_crtc_state
*pipe_config
,
1272 struct drm_connector_state
*conn_state
)
1274 struct intel_sdvo
*intel_sdvo
= to_sdvo(encoder
);
1275 struct intel_sdvo_connector_state
*intel_sdvo_state
=
1276 to_intel_sdvo_connector_state(conn_state
);
1277 struct intel_sdvo_connector
*intel_sdvo_connector
=
1278 to_intel_sdvo_connector(conn_state
->connector
);
1279 struct drm_display_mode
*adjusted_mode
= &pipe_config
->hw
.adjusted_mode
;
1280 struct drm_display_mode
*mode
= &pipe_config
->hw
.mode
;
1282 DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1283 pipe_config
->pipe_bpp
= 8*3;
1284 pipe_config
->output_format
= INTEL_OUTPUT_FORMAT_RGB
;
1286 if (HAS_PCH_SPLIT(to_i915(encoder
->base
.dev
)))
1287 pipe_config
->has_pch_encoder
= true;
1290 * We need to construct preferred input timings based on our
1291 * output timings. To do that, we have to set the output
1292 * timings, even though this isn't really the right place in
1293 * the sequence to do it. Oh well.
1295 if (IS_TV(intel_sdvo_connector
)) {
1296 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo
, mode
))
1299 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo
,
1300 intel_sdvo_connector
,
1303 pipe_config
->sdvo_tv_clock
= true;
1304 } else if (IS_LVDS(intel_sdvo_connector
)) {
1305 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo
,
1306 intel_sdvo_connector
->base
.panel
.fixed_mode
))
1309 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo
,
1310 intel_sdvo_connector
,
1315 if (adjusted_mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
1319 * Make the CRTC code factor in the SDVO pixel multiplier. The
1320 * SDVO device will factor out the multiplier during mode_set.
1322 pipe_config
->pixel_multiplier
=
1323 intel_sdvo_get_pixel_multiplier(adjusted_mode
);
1325 if (intel_sdvo_state
->base
.force_audio
!= HDMI_AUDIO_OFF_DVI
)
1326 pipe_config
->has_hdmi_sink
= intel_sdvo
->has_hdmi_monitor
;
1328 if (intel_sdvo_state
->base
.force_audio
== HDMI_AUDIO_ON
||
1329 (intel_sdvo_state
->base
.force_audio
== HDMI_AUDIO_AUTO
&& intel_sdvo
->has_hdmi_audio
))
1330 pipe_config
->has_audio
= true;
1332 if (intel_sdvo_state
->base
.broadcast_rgb
== INTEL_BROADCAST_RGB_AUTO
) {
1334 * See CEA-861-E - 5.1 Default Encoding Parameters
1336 * FIXME: This bit is only valid when using TMDS encoding and 8
1337 * bit per color mode.
1339 if (pipe_config
->has_hdmi_sink
&&
1340 drm_match_cea_mode(adjusted_mode
) > 1)
1341 pipe_config
->limited_color_range
= true;
1343 if (pipe_config
->has_hdmi_sink
&&
1344 intel_sdvo_state
->base
.broadcast_rgb
== INTEL_BROADCAST_RGB_LIMITED
)
1345 pipe_config
->limited_color_range
= true;
1348 /* Clock computation needs to happen after pixel multiplier. */
1349 if (IS_TV(intel_sdvo_connector
))
1350 i9xx_adjust_sdvo_tv_clock(pipe_config
);
1352 if (conn_state
->picture_aspect_ratio
)
1353 adjusted_mode
->picture_aspect_ratio
=
1354 conn_state
->picture_aspect_ratio
;
1356 if (!intel_sdvo_compute_avi_infoframe(intel_sdvo
,
1357 pipe_config
, conn_state
)) {
1358 DRM_DEBUG_KMS("bad AVI infoframe\n");
1365 #define UPDATE_PROPERTY(input, NAME) \
1368 intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_##NAME, &val, sizeof(val)); \
1371 static void intel_sdvo_update_props(struct intel_sdvo
*intel_sdvo
,
1372 const struct intel_sdvo_connector_state
*sdvo_state
)
1374 const struct drm_connector_state
*conn_state
= &sdvo_state
->base
.base
;
1375 struct intel_sdvo_connector
*intel_sdvo_conn
=
1376 to_intel_sdvo_connector(conn_state
->connector
);
1379 if (intel_sdvo_conn
->left
)
1380 UPDATE_PROPERTY(sdvo_state
->tv
.overscan_h
, OVERSCAN_H
);
1382 if (intel_sdvo_conn
->top
)
1383 UPDATE_PROPERTY(sdvo_state
->tv
.overscan_v
, OVERSCAN_V
);
1385 if (intel_sdvo_conn
->hpos
)
1386 UPDATE_PROPERTY(sdvo_state
->tv
.hpos
, HPOS
);
1388 if (intel_sdvo_conn
->vpos
)
1389 UPDATE_PROPERTY(sdvo_state
->tv
.vpos
, VPOS
);
1391 if (intel_sdvo_conn
->saturation
)
1392 UPDATE_PROPERTY(conn_state
->tv
.saturation
, SATURATION
);
1394 if (intel_sdvo_conn
->contrast
)
1395 UPDATE_PROPERTY(conn_state
->tv
.contrast
, CONTRAST
);
1397 if (intel_sdvo_conn
->hue
)
1398 UPDATE_PROPERTY(conn_state
->tv
.hue
, HUE
);
1400 if (intel_sdvo_conn
->brightness
)
1401 UPDATE_PROPERTY(conn_state
->tv
.brightness
, BRIGHTNESS
);
1403 if (intel_sdvo_conn
->sharpness
)
1404 UPDATE_PROPERTY(sdvo_state
->tv
.sharpness
, SHARPNESS
);
1406 if (intel_sdvo_conn
->flicker_filter
)
1407 UPDATE_PROPERTY(sdvo_state
->tv
.flicker_filter
, FLICKER_FILTER
);
1409 if (intel_sdvo_conn
->flicker_filter_2d
)
1410 UPDATE_PROPERTY(sdvo_state
->tv
.flicker_filter_2d
, FLICKER_FILTER_2D
);
1412 if (intel_sdvo_conn
->flicker_filter_adaptive
)
1413 UPDATE_PROPERTY(sdvo_state
->tv
.flicker_filter_adaptive
, FLICKER_FILTER_ADAPTIVE
);
1415 if (intel_sdvo_conn
->tv_chroma_filter
)
1416 UPDATE_PROPERTY(sdvo_state
->tv
.chroma_filter
, TV_CHROMA_FILTER
);
1418 if (intel_sdvo_conn
->tv_luma_filter
)
1419 UPDATE_PROPERTY(sdvo_state
->tv
.luma_filter
, TV_LUMA_FILTER
);
1421 if (intel_sdvo_conn
->dot_crawl
)
1422 UPDATE_PROPERTY(sdvo_state
->tv
.dot_crawl
, DOT_CRAWL
);
1424 #undef UPDATE_PROPERTY
1427 static void intel_sdvo_pre_enable(struct intel_encoder
*intel_encoder
,
1428 const struct intel_crtc_state
*crtc_state
,
1429 const struct drm_connector_state
*conn_state
)
1431 struct drm_i915_private
*dev_priv
= to_i915(intel_encoder
->base
.dev
);
1432 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1433 const struct drm_display_mode
*adjusted_mode
= &crtc_state
->hw
.adjusted_mode
;
1434 const struct intel_sdvo_connector_state
*sdvo_state
=
1435 to_intel_sdvo_connector_state(conn_state
);
1436 const struct intel_sdvo_connector
*intel_sdvo_connector
=
1437 to_intel_sdvo_connector(conn_state
->connector
);
1438 const struct drm_display_mode
*mode
= &crtc_state
->hw
.mode
;
1439 struct intel_sdvo
*intel_sdvo
= to_sdvo(intel_encoder
);
1441 struct intel_sdvo_in_out_map in_out
;
1442 struct intel_sdvo_dtd input_dtd
, output_dtd
;
1445 intel_sdvo_update_props(intel_sdvo
, sdvo_state
);
1448 * First, set the input mapping for the first input to our controlled
1449 * output. This is only correct if we're a single-input device, in
1450 * which case the first input is the output from the appropriate SDVO
1451 * channel on the motherboard. In a two-input device, the first input
1452 * will be SDVOB and the second SDVOC.
1454 in_out
.in0
= intel_sdvo
->attached_output
;
1457 intel_sdvo_set_value(intel_sdvo
,
1458 SDVO_CMD_SET_IN_OUT_MAP
,
1459 &in_out
, sizeof(in_out
));
1461 /* Set the output timings to the screen */
1462 if (!intel_sdvo_set_target_output(intel_sdvo
,
1463 intel_sdvo
->attached_output
))
1466 /* lvds has a special fixed output timing. */
1467 if (IS_LVDS(intel_sdvo_connector
))
1468 intel_sdvo_get_dtd_from_mode(&output_dtd
,
1469 intel_sdvo_connector
->base
.panel
.fixed_mode
);
1471 intel_sdvo_get_dtd_from_mode(&output_dtd
, mode
);
1472 if (!intel_sdvo_set_output_timing(intel_sdvo
, &output_dtd
))
1473 DRM_INFO("Setting output timings on %s failed\n",
1474 SDVO_NAME(intel_sdvo
));
1476 /* Set the input timing to the screen. Assume always input 0. */
1477 if (!intel_sdvo_set_target_input(intel_sdvo
))
1480 if (crtc_state
->has_hdmi_sink
) {
1481 intel_sdvo_set_encode(intel_sdvo
, SDVO_ENCODE_HDMI
);
1482 intel_sdvo_set_colorimetry(intel_sdvo
,
1483 SDVO_COLORIMETRY_RGB256
);
1484 intel_sdvo_set_avi_infoframe(intel_sdvo
, crtc_state
);
1486 intel_sdvo_set_encode(intel_sdvo
, SDVO_ENCODE_DVI
);
1488 if (IS_TV(intel_sdvo_connector
) &&
1489 !intel_sdvo_set_tv_format(intel_sdvo
, conn_state
))
1492 intel_sdvo_get_dtd_from_mode(&input_dtd
, adjusted_mode
);
1494 if (IS_TV(intel_sdvo_connector
) || IS_LVDS(intel_sdvo_connector
))
1495 input_dtd
.part2
.sdvo_flags
= intel_sdvo
->dtd_sdvo_flags
;
1496 if (!intel_sdvo_set_input_timing(intel_sdvo
, &input_dtd
))
1497 DRM_INFO("Setting input timings on %s failed\n",
1498 SDVO_NAME(intel_sdvo
));
1500 switch (crtc_state
->pixel_multiplier
) {
1502 WARN(1, "unknown pixel multiplier specified\n");
1504 case 1: rate
= SDVO_CLOCK_RATE_MULT_1X
; break;
1505 case 2: rate
= SDVO_CLOCK_RATE_MULT_2X
; break;
1506 case 4: rate
= SDVO_CLOCK_RATE_MULT_4X
; break;
1508 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo
, rate
))
1511 /* Set the SDVO control regs. */
1512 if (INTEL_GEN(dev_priv
) >= 4) {
1513 /* The real mode polarity is set by the SDVO commands, using
1514 * struct intel_sdvo_dtd. */
1515 sdvox
= SDVO_VSYNC_ACTIVE_HIGH
| SDVO_HSYNC_ACTIVE_HIGH
;
1516 if (!HAS_PCH_SPLIT(dev_priv
) && crtc_state
->limited_color_range
)
1517 sdvox
|= HDMI_COLOR_RANGE_16_235
;
1518 if (INTEL_GEN(dev_priv
) < 5)
1519 sdvox
|= SDVO_BORDER_ENABLE
;
1521 sdvox
= I915_READ(intel_sdvo
->sdvo_reg
);
1522 if (intel_sdvo
->port
== PORT_B
)
1523 sdvox
&= SDVOB_PRESERVE_MASK
;
1525 sdvox
&= SDVOC_PRESERVE_MASK
;
1526 sdvox
|= (9 << 19) | SDVO_BORDER_ENABLE
;
1529 if (HAS_PCH_CPT(dev_priv
))
1530 sdvox
|= SDVO_PIPE_SEL_CPT(crtc
->pipe
);
1532 sdvox
|= SDVO_PIPE_SEL(crtc
->pipe
);
1534 if (INTEL_GEN(dev_priv
) >= 4) {
1535 /* done in crtc_mode_set as the dpll_md reg must be written early */
1536 } else if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
) ||
1537 IS_G33(dev_priv
) || IS_PINEVIEW(dev_priv
)) {
1538 /* done in crtc_mode_set as it lives inside the dpll register */
1540 sdvox
|= (crtc_state
->pixel_multiplier
- 1)
1541 << SDVO_PORT_MULTIPLY_SHIFT
;
1544 if (input_dtd
.part2
.sdvo_flags
& SDVO_NEED_TO_STALL
&&
1545 INTEL_GEN(dev_priv
) < 5)
1546 sdvox
|= SDVO_STALL_SELECT
;
1547 intel_sdvo_write_sdvox(intel_sdvo
, sdvox
);
1550 static bool intel_sdvo_connector_get_hw_state(struct intel_connector
*connector
)
1552 struct intel_sdvo_connector
*intel_sdvo_connector
=
1553 to_intel_sdvo_connector(&connector
->base
);
1554 struct intel_sdvo
*intel_sdvo
= intel_attached_sdvo(connector
);
1555 u16 active_outputs
= 0;
1557 intel_sdvo_get_active_outputs(intel_sdvo
, &active_outputs
);
1559 return active_outputs
& intel_sdvo_connector
->output_flag
;
1562 bool intel_sdvo_port_enabled(struct drm_i915_private
*dev_priv
,
1563 i915_reg_t sdvo_reg
, enum pipe
*pipe
)
1567 val
= I915_READ(sdvo_reg
);
1569 /* asserts want to know the pipe even if the port is disabled */
1570 if (HAS_PCH_CPT(dev_priv
))
1571 *pipe
= (val
& SDVO_PIPE_SEL_MASK_CPT
) >> SDVO_PIPE_SEL_SHIFT_CPT
;
1572 else if (IS_CHERRYVIEW(dev_priv
))
1573 *pipe
= (val
& SDVO_PIPE_SEL_MASK_CHV
) >> SDVO_PIPE_SEL_SHIFT_CHV
;
1575 *pipe
= (val
& SDVO_PIPE_SEL_MASK
) >> SDVO_PIPE_SEL_SHIFT
;
1577 return val
& SDVO_ENABLE
;
1580 static bool intel_sdvo_get_hw_state(struct intel_encoder
*encoder
,
1583 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1584 struct intel_sdvo
*intel_sdvo
= to_sdvo(encoder
);
1585 u16 active_outputs
= 0;
1588 intel_sdvo_get_active_outputs(intel_sdvo
, &active_outputs
);
1590 ret
= intel_sdvo_port_enabled(dev_priv
, intel_sdvo
->sdvo_reg
, pipe
);
1592 return ret
|| active_outputs
;
1595 static void intel_sdvo_get_config(struct intel_encoder
*encoder
,
1596 struct intel_crtc_state
*pipe_config
)
1598 struct drm_device
*dev
= encoder
->base
.dev
;
1599 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1600 struct intel_sdvo
*intel_sdvo
= to_sdvo(encoder
);
1601 struct intel_sdvo_dtd dtd
;
1602 int encoder_pixel_multiplier
= 0;
1604 u32 flags
= 0, sdvox
;
1608 pipe_config
->output_types
|= BIT(INTEL_OUTPUT_SDVO
);
1610 sdvox
= I915_READ(intel_sdvo
->sdvo_reg
);
1612 ret
= intel_sdvo_get_input_timing(intel_sdvo
, &dtd
);
1615 * Some sdvo encoders are not spec compliant and don't
1616 * implement the mandatory get_timings function.
1618 DRM_DEBUG_DRIVER("failed to retrieve SDVO DTD\n");
1619 pipe_config
->quirks
|= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
;
1621 if (dtd
.part2
.dtd_flags
& DTD_FLAG_HSYNC_POSITIVE
)
1622 flags
|= DRM_MODE_FLAG_PHSYNC
;
1624 flags
|= DRM_MODE_FLAG_NHSYNC
;
1626 if (dtd
.part2
.dtd_flags
& DTD_FLAG_VSYNC_POSITIVE
)
1627 flags
|= DRM_MODE_FLAG_PVSYNC
;
1629 flags
|= DRM_MODE_FLAG_NVSYNC
;
1632 pipe_config
->hw
.adjusted_mode
.flags
|= flags
;
1635 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1636 * the sdvo port register, on all other platforms it is part of the dpll
1637 * state. Since the general pipe state readout happens before the
1638 * encoder->get_config we so already have a valid pixel multplier on all
1641 if (IS_I915G(dev_priv
) || IS_I915GM(dev_priv
)) {
1642 pipe_config
->pixel_multiplier
=
1643 ((sdvox
& SDVO_PORT_MULTIPLY_MASK
)
1644 >> SDVO_PORT_MULTIPLY_SHIFT
) + 1;
1647 dotclock
= pipe_config
->port_clock
;
1649 if (pipe_config
->pixel_multiplier
)
1650 dotclock
/= pipe_config
->pixel_multiplier
;
1652 pipe_config
->hw
.adjusted_mode
.crtc_clock
= dotclock
;
1654 /* Cross check the port pixel multiplier with the sdvo encoder state. */
1655 if (intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_CLOCK_RATE_MULT
,
1658 case SDVO_CLOCK_RATE_MULT_1X
:
1659 encoder_pixel_multiplier
= 1;
1661 case SDVO_CLOCK_RATE_MULT_2X
:
1662 encoder_pixel_multiplier
= 2;
1664 case SDVO_CLOCK_RATE_MULT_4X
:
1665 encoder_pixel_multiplier
= 4;
1670 WARN(encoder_pixel_multiplier
!= pipe_config
->pixel_multiplier
,
1671 "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1672 pipe_config
->pixel_multiplier
, encoder_pixel_multiplier
);
1674 if (sdvox
& HDMI_COLOR_RANGE_16_235
)
1675 pipe_config
->limited_color_range
= true;
1677 if (intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_AUDIO_STAT
,
1679 u8 mask
= SDVO_AUDIO_ELD_VALID
| SDVO_AUDIO_PRESENCE_DETECT
;
1681 if ((val
& mask
) == mask
)
1682 pipe_config
->has_audio
= true;
1685 if (intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_ENCODE
,
1687 if (val
== SDVO_ENCODE_HDMI
)
1688 pipe_config
->has_hdmi_sink
= true;
1691 intel_sdvo_get_avi_infoframe(intel_sdvo
, pipe_config
);
1694 static void intel_sdvo_disable_audio(struct intel_sdvo
*intel_sdvo
)
1696 intel_sdvo_set_audio_state(intel_sdvo
, 0);
1699 static void intel_sdvo_enable_audio(struct intel_sdvo
*intel_sdvo
,
1700 const struct intel_crtc_state
*crtc_state
,
1701 const struct drm_connector_state
*conn_state
)
1703 const struct drm_display_mode
*adjusted_mode
=
1704 &crtc_state
->hw
.adjusted_mode
;
1705 struct drm_connector
*connector
= conn_state
->connector
;
1706 u8
*eld
= connector
->eld
;
1708 eld
[6] = drm_av_sync_delay(connector
, adjusted_mode
) / 2;
1710 intel_sdvo_set_audio_state(intel_sdvo
, 0);
1712 intel_sdvo_write_infoframe(intel_sdvo
, SDVO_HBUF_INDEX_ELD
,
1713 SDVO_HBUF_TX_DISABLED
,
1714 eld
, drm_eld_size(eld
));
1716 intel_sdvo_set_audio_state(intel_sdvo
, SDVO_AUDIO_ELD_VALID
|
1717 SDVO_AUDIO_PRESENCE_DETECT
);
1720 static void intel_disable_sdvo(struct intel_encoder
*encoder
,
1721 const struct intel_crtc_state
*old_crtc_state
,
1722 const struct drm_connector_state
*conn_state
)
1724 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1725 struct intel_sdvo
*intel_sdvo
= to_sdvo(encoder
);
1726 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
1729 if (old_crtc_state
->has_audio
)
1730 intel_sdvo_disable_audio(intel_sdvo
);
1732 intel_sdvo_set_active_outputs(intel_sdvo
, 0);
1734 intel_sdvo_set_encoder_power_state(intel_sdvo
,
1737 temp
= I915_READ(intel_sdvo
->sdvo_reg
);
1739 temp
&= ~SDVO_ENABLE
;
1740 intel_sdvo_write_sdvox(intel_sdvo
, temp
);
1743 * HW workaround for IBX, we need to move the port
1744 * to transcoder A after disabling it to allow the
1745 * matching DP port to be enabled on transcoder A.
1747 if (HAS_PCH_IBX(dev_priv
) && crtc
->pipe
== PIPE_B
) {
1749 * We get CPU/PCH FIFO underruns on the other pipe when
1750 * doing the workaround. Sweep them under the rug.
1752 intel_set_cpu_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
1753 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, false);
1755 temp
&= ~SDVO_PIPE_SEL_MASK
;
1756 temp
|= SDVO_ENABLE
| SDVO_PIPE_SEL(PIPE_A
);
1757 intel_sdvo_write_sdvox(intel_sdvo
, temp
);
1759 temp
&= ~SDVO_ENABLE
;
1760 intel_sdvo_write_sdvox(intel_sdvo
, temp
);
1762 intel_wait_for_vblank_if_active(dev_priv
, PIPE_A
);
1763 intel_set_cpu_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
1764 intel_set_pch_fifo_underrun_reporting(dev_priv
, PIPE_A
, true);
1768 static void pch_disable_sdvo(struct intel_encoder
*encoder
,
1769 const struct intel_crtc_state
*old_crtc_state
,
1770 const struct drm_connector_state
*old_conn_state
)
1774 static void pch_post_disable_sdvo(struct intel_encoder
*encoder
,
1775 const struct intel_crtc_state
*old_crtc_state
,
1776 const struct drm_connector_state
*old_conn_state
)
1778 intel_disable_sdvo(encoder
, old_crtc_state
, old_conn_state
);
1781 static void intel_enable_sdvo(struct intel_encoder
*encoder
,
1782 const struct intel_crtc_state
*pipe_config
,
1783 const struct drm_connector_state
*conn_state
)
1785 struct drm_device
*dev
= encoder
->base
.dev
;
1786 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1787 struct intel_sdvo
*intel_sdvo
= to_sdvo(encoder
);
1788 struct intel_crtc
*intel_crtc
= to_intel_crtc(pipe_config
->uapi
.crtc
);
1790 bool input1
, input2
;
1794 temp
= I915_READ(intel_sdvo
->sdvo_reg
);
1795 temp
|= SDVO_ENABLE
;
1796 intel_sdvo_write_sdvox(intel_sdvo
, temp
);
1798 for (i
= 0; i
< 2; i
++)
1799 intel_wait_for_vblank(dev_priv
, intel_crtc
->pipe
);
1801 success
= intel_sdvo_get_trained_inputs(intel_sdvo
, &input1
, &input2
);
1803 * Warn if the device reported failure to sync.
1805 * A lot of SDVO devices fail to notify of sync, but it's
1806 * a given it the status is a success, we succeeded.
1808 if (success
&& !input1
) {
1809 DRM_DEBUG_KMS("First %s output reported failure to "
1810 "sync\n", SDVO_NAME(intel_sdvo
));
1814 intel_sdvo_set_encoder_power_state(intel_sdvo
,
1816 intel_sdvo_set_active_outputs(intel_sdvo
, intel_sdvo
->attached_output
);
1818 if (pipe_config
->has_audio
)
1819 intel_sdvo_enable_audio(intel_sdvo
, pipe_config
, conn_state
);
1822 static enum drm_mode_status
1823 intel_sdvo_mode_valid(struct drm_connector
*connector
,
1824 struct drm_display_mode
*mode
)
1826 struct intel_sdvo
*intel_sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
1827 struct intel_sdvo_connector
*intel_sdvo_connector
=
1828 to_intel_sdvo_connector(connector
);
1829 int max_dotclk
= to_i915(connector
->dev
)->max_dotclk_freq
;
1831 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
1832 return MODE_NO_DBLESCAN
;
1834 if (intel_sdvo
->pixel_clock_min
> mode
->clock
)
1835 return MODE_CLOCK_LOW
;
1837 if (intel_sdvo
->pixel_clock_max
< mode
->clock
)
1838 return MODE_CLOCK_HIGH
;
1840 if (mode
->clock
> max_dotclk
)
1841 return MODE_CLOCK_HIGH
;
1843 if (IS_LVDS(intel_sdvo_connector
)) {
1844 const struct drm_display_mode
*fixed_mode
=
1845 intel_sdvo_connector
->base
.panel
.fixed_mode
;
1847 if (mode
->hdisplay
> fixed_mode
->hdisplay
)
1850 if (mode
->vdisplay
> fixed_mode
->vdisplay
)
1857 static bool intel_sdvo_get_capabilities(struct intel_sdvo
*intel_sdvo
, struct intel_sdvo_caps
*caps
)
1859 BUILD_BUG_ON(sizeof(*caps
) != 8);
1860 if (!intel_sdvo_get_value(intel_sdvo
,
1861 SDVO_CMD_GET_DEVICE_CAPS
,
1862 caps
, sizeof(*caps
)))
1865 DRM_DEBUG_KMS("SDVO capabilities:\n"
1868 " device_rev_id: %d\n"
1869 " sdvo_version_major: %d\n"
1870 " sdvo_version_minor: %d\n"
1871 " sdvo_inputs_mask: %d\n"
1872 " smooth_scaling: %d\n"
1873 " sharp_scaling: %d\n"
1875 " down_scaling: %d\n"
1876 " stall_support: %d\n"
1877 " output_flags: %d\n",
1880 caps
->device_rev_id
,
1881 caps
->sdvo_version_major
,
1882 caps
->sdvo_version_minor
,
1883 caps
->sdvo_inputs_mask
,
1884 caps
->smooth_scaling
,
1885 caps
->sharp_scaling
,
1888 caps
->stall_support
,
1889 caps
->output_flags
);
1894 static u16
intel_sdvo_get_hotplug_support(struct intel_sdvo
*intel_sdvo
)
1896 struct drm_i915_private
*dev_priv
= to_i915(intel_sdvo
->base
.base
.dev
);
1899 if (!I915_HAS_HOTPLUG(dev_priv
))
1903 * HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1906 if (IS_I945G(dev_priv
) || IS_I945GM(dev_priv
))
1909 if (!intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
,
1910 &hotplug
, sizeof(hotplug
)))
1916 static void intel_sdvo_enable_hotplug(struct intel_encoder
*encoder
)
1918 struct intel_sdvo
*intel_sdvo
= to_sdvo(encoder
);
1920 intel_sdvo_write_cmd(intel_sdvo
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
,
1921 &intel_sdvo
->hotplug_active
, 2);
1924 static enum intel_hotplug_state
1925 intel_sdvo_hotplug(struct intel_encoder
*encoder
,
1926 struct intel_connector
*connector
,
1929 intel_sdvo_enable_hotplug(encoder
);
1931 return intel_encoder_hotplug(encoder
, connector
, irq_received
);
1935 intel_sdvo_multifunc_encoder(struct intel_sdvo
*intel_sdvo
)
1937 /* Is there more than one type of output? */
1938 return hweight16(intel_sdvo
->caps
.output_flags
) > 1;
1941 static struct edid
*
1942 intel_sdvo_get_edid(struct drm_connector
*connector
)
1944 struct intel_sdvo
*sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
1945 return drm_get_edid(connector
, &sdvo
->ddc
);
1948 /* Mac mini hack -- use the same DDC as the analog connector */
1949 static struct edid
*
1950 intel_sdvo_get_analog_edid(struct drm_connector
*connector
)
1952 struct drm_i915_private
*dev_priv
= to_i915(connector
->dev
);
1954 return drm_get_edid(connector
,
1955 intel_gmbus_get_adapter(dev_priv
,
1956 dev_priv
->vbt
.crt_ddc_pin
));
1959 static enum drm_connector_status
1960 intel_sdvo_tmds_sink_detect(struct drm_connector
*connector
)
1962 struct intel_sdvo
*intel_sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
1963 struct intel_sdvo_connector
*intel_sdvo_connector
=
1964 to_intel_sdvo_connector(connector
);
1965 enum drm_connector_status status
;
1968 edid
= intel_sdvo_get_edid(connector
);
1970 if (edid
== NULL
&& intel_sdvo_multifunc_encoder(intel_sdvo
)) {
1971 u8 ddc
, saved_ddc
= intel_sdvo
->ddc_bus
;
1974 * Don't use the 1 as the argument of DDC bus switch to get
1975 * the EDID. It is used for SDVO SPD ROM.
1977 for (ddc
= intel_sdvo
->ddc_bus
>> 1; ddc
> 1; ddc
>>= 1) {
1978 intel_sdvo
->ddc_bus
= ddc
;
1979 edid
= intel_sdvo_get_edid(connector
);
1984 * If we found the EDID on the other bus,
1985 * assume that is the correct DDC bus.
1988 intel_sdvo
->ddc_bus
= saved_ddc
;
1992 * When there is no edid and no monitor is connected with VGA
1993 * port, try to use the CRT ddc to read the EDID for DVI-connector.
1996 edid
= intel_sdvo_get_analog_edid(connector
);
1998 status
= connector_status_unknown
;
2000 /* DDC bus is shared, match EDID to connector type */
2001 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
) {
2002 status
= connector_status_connected
;
2003 if (intel_sdvo_connector
->is_hdmi
) {
2004 intel_sdvo
->has_hdmi_monitor
= drm_detect_hdmi_monitor(edid
);
2005 intel_sdvo
->has_hdmi_audio
= drm_detect_monitor_audio(edid
);
2008 status
= connector_status_disconnected
;
2016 intel_sdvo_connector_matches_edid(struct intel_sdvo_connector
*sdvo
,
2019 bool monitor_is_digital
= !!(edid
->input
& DRM_EDID_INPUT_DIGITAL
);
2020 bool connector_is_digital
= !!IS_DIGITAL(sdvo
);
2022 DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
2023 connector_is_digital
, monitor_is_digital
);
2024 return connector_is_digital
== monitor_is_digital
;
2027 static enum drm_connector_status
2028 intel_sdvo_detect(struct drm_connector
*connector
, bool force
)
2031 struct intel_sdvo
*intel_sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
2032 struct intel_sdvo_connector
*intel_sdvo_connector
= to_intel_sdvo_connector(connector
);
2033 enum drm_connector_status ret
;
2035 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2036 connector
->base
.id
, connector
->name
);
2038 if (!intel_sdvo_get_value(intel_sdvo
,
2039 SDVO_CMD_GET_ATTACHED_DISPLAYS
,
2041 return connector_status_unknown
;
2043 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
2044 response
& 0xff, response
>> 8,
2045 intel_sdvo_connector
->output_flag
);
2048 return connector_status_disconnected
;
2050 intel_sdvo
->attached_output
= response
;
2052 intel_sdvo
->has_hdmi_monitor
= false;
2053 intel_sdvo
->has_hdmi_audio
= false;
2055 if ((intel_sdvo_connector
->output_flag
& response
) == 0)
2056 ret
= connector_status_disconnected
;
2057 else if (IS_TMDS(intel_sdvo_connector
))
2058 ret
= intel_sdvo_tmds_sink_detect(connector
);
2062 /* if we have an edid check it matches the connection */
2063 edid
= intel_sdvo_get_edid(connector
);
2065 edid
= intel_sdvo_get_analog_edid(connector
);
2067 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector
,
2069 ret
= connector_status_connected
;
2071 ret
= connector_status_disconnected
;
2075 ret
= connector_status_connected
;
2081 static void intel_sdvo_get_ddc_modes(struct drm_connector
*connector
)
2085 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2086 connector
->base
.id
, connector
->name
);
2088 /* set the bus switch and get the modes */
2089 edid
= intel_sdvo_get_edid(connector
);
2092 * Mac mini hack. On this device, the DVI-I connector shares one DDC
2093 * link between analog and digital outputs. So, if the regular SDVO
2094 * DDC fails, check to see if the analog output is disconnected, in
2095 * which case we'll look there for the digital DDC data.
2098 edid
= intel_sdvo_get_analog_edid(connector
);
2101 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector
),
2103 drm_connector_update_edid_property(connector
, edid
);
2104 drm_add_edid_modes(connector
, edid
);
2112 * Set of SDVO TV modes.
2113 * Note! This is in reply order (see loop in get_tv_modes).
2114 * XXX: all 60Hz refresh?
2116 static const struct drm_display_mode sdvo_tv_modes
[] = {
2117 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER
, 5815, 320, 321, 384,
2118 416, 0, 200, 201, 232, 233, 0,
2119 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2120 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER
, 6814, 320, 321, 384,
2121 416, 0, 240, 241, 272, 273, 0,
2122 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2123 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER
, 9910, 400, 401, 464,
2124 496, 0, 300, 301, 332, 333, 0,
2125 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2126 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER
, 16913, 640, 641, 704,
2127 736, 0, 350, 351, 382, 383, 0,
2128 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2129 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER
, 19121, 640, 641, 704,
2130 736, 0, 400, 401, 432, 433, 0,
2131 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2132 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 22654, 640, 641, 704,
2133 736, 0, 480, 481, 512, 513, 0,
2134 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2135 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER
, 24624, 704, 705, 768,
2136 800, 0, 480, 481, 512, 513, 0,
2137 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2138 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER
, 29232, 704, 705, 768,
2139 800, 0, 576, 577, 608, 609, 0,
2140 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2141 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER
, 18751, 720, 721, 784,
2142 816, 0, 350, 351, 382, 383, 0,
2143 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2144 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 21199, 720, 721, 784,
2145 816, 0, 400, 401, 432, 433, 0,
2146 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2147 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 25116, 720, 721, 784,
2148 816, 0, 480, 481, 512, 513, 0,
2149 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2150 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER
, 28054, 720, 721, 784,
2151 816, 0, 540, 541, 572, 573, 0,
2152 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2153 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 29816, 720, 721, 784,
2154 816, 0, 576, 577, 608, 609, 0,
2155 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2156 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER
, 31570, 768, 769, 832,
2157 864, 0, 576, 577, 608, 609, 0,
2158 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2159 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 34030, 800, 801, 864,
2160 896, 0, 600, 601, 632, 633, 0,
2161 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2162 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER
, 36581, 832, 833, 896,
2163 928, 0, 624, 625, 656, 657, 0,
2164 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2165 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER
, 48707, 920, 921, 984,
2166 1016, 0, 766, 767, 798, 799, 0,
2167 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2168 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 53827, 1024, 1025, 1088,
2169 1120, 0, 768, 769, 800, 801, 0,
2170 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2171 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 87265, 1280, 1281, 1344,
2172 1376, 0, 1024, 1025, 1056, 1057, 0,
2173 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2176 static void intel_sdvo_get_tv_modes(struct drm_connector
*connector
)
2178 struct intel_sdvo
*intel_sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
2179 const struct drm_connector_state
*conn_state
= connector
->state
;
2180 struct intel_sdvo_sdtv_resolution_request tv_res
;
2181 u32 reply
= 0, format_map
= 0;
2184 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2185 connector
->base
.id
, connector
->name
);
2188 * Read the list of supported input resolutions for the selected TV
2191 format_map
= 1 << conn_state
->tv
.mode
;
2192 memcpy(&tv_res
, &format_map
,
2193 min(sizeof(format_map
), sizeof(struct intel_sdvo_sdtv_resolution_request
)));
2195 if (!intel_sdvo_set_target_output(intel_sdvo
, intel_sdvo
->attached_output
))
2198 BUILD_BUG_ON(sizeof(tv_res
) != 3);
2199 if (!intel_sdvo_write_cmd(intel_sdvo
,
2200 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
,
2201 &tv_res
, sizeof(tv_res
)))
2203 if (!intel_sdvo_read_response(intel_sdvo
, &reply
, 3))
2206 for (i
= 0; i
< ARRAY_SIZE(sdvo_tv_modes
); i
++)
2207 if (reply
& (1 << i
)) {
2208 struct drm_display_mode
*nmode
;
2209 nmode
= drm_mode_duplicate(connector
->dev
,
2212 drm_mode_probed_add(connector
, nmode
);
2216 static void intel_sdvo_get_lvds_modes(struct drm_connector
*connector
)
2218 struct intel_sdvo
*intel_sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
2219 struct drm_i915_private
*dev_priv
= to_i915(connector
->dev
);
2220 struct drm_display_mode
*newmode
;
2222 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2223 connector
->base
.id
, connector
->name
);
2226 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
2227 * SDVO->LVDS transcoders can't cope with the EDID mode.
2229 if (dev_priv
->vbt
.sdvo_lvds_vbt_mode
!= NULL
) {
2230 newmode
= drm_mode_duplicate(connector
->dev
,
2231 dev_priv
->vbt
.sdvo_lvds_vbt_mode
);
2232 if (newmode
!= NULL
) {
2233 /* Guarantee the mode is preferred */
2234 newmode
->type
= (DRM_MODE_TYPE_PREFERRED
|
2235 DRM_MODE_TYPE_DRIVER
);
2236 drm_mode_probed_add(connector
, newmode
);
2241 * Attempt to get the mode list from DDC.
2242 * Assume that the preferred modes are
2243 * arranged in priority order.
2245 intel_ddc_get_modes(connector
, &intel_sdvo
->ddc
);
2248 static int intel_sdvo_get_modes(struct drm_connector
*connector
)
2250 struct intel_sdvo_connector
*intel_sdvo_connector
= to_intel_sdvo_connector(connector
);
2252 if (IS_TV(intel_sdvo_connector
))
2253 intel_sdvo_get_tv_modes(connector
);
2254 else if (IS_LVDS(intel_sdvo_connector
))
2255 intel_sdvo_get_lvds_modes(connector
);
2257 intel_sdvo_get_ddc_modes(connector
);
2259 return !list_empty(&connector
->probed_modes
);
2263 intel_sdvo_connector_atomic_get_property(struct drm_connector
*connector
,
2264 const struct drm_connector_state
*state
,
2265 struct drm_property
*property
,
2268 struct intel_sdvo_connector
*intel_sdvo_connector
= to_intel_sdvo_connector(connector
);
2269 const struct intel_sdvo_connector_state
*sdvo_state
= to_intel_sdvo_connector_state((void *)state
);
2271 if (property
== intel_sdvo_connector
->tv_format
) {
2274 for (i
= 0; i
< intel_sdvo_connector
->format_supported_num
; i
++)
2275 if (state
->tv
.mode
== intel_sdvo_connector
->tv_format_supported
[i
]) {
2283 } else if (property
== intel_sdvo_connector
->top
||
2284 property
== intel_sdvo_connector
->bottom
)
2285 *val
= intel_sdvo_connector
->max_vscan
- sdvo_state
->tv
.overscan_v
;
2286 else if (property
== intel_sdvo_connector
->left
||
2287 property
== intel_sdvo_connector
->right
)
2288 *val
= intel_sdvo_connector
->max_hscan
- sdvo_state
->tv
.overscan_h
;
2289 else if (property
== intel_sdvo_connector
->hpos
)
2290 *val
= sdvo_state
->tv
.hpos
;
2291 else if (property
== intel_sdvo_connector
->vpos
)
2292 *val
= sdvo_state
->tv
.vpos
;
2293 else if (property
== intel_sdvo_connector
->saturation
)
2294 *val
= state
->tv
.saturation
;
2295 else if (property
== intel_sdvo_connector
->contrast
)
2296 *val
= state
->tv
.contrast
;
2297 else if (property
== intel_sdvo_connector
->hue
)
2298 *val
= state
->tv
.hue
;
2299 else if (property
== intel_sdvo_connector
->brightness
)
2300 *val
= state
->tv
.brightness
;
2301 else if (property
== intel_sdvo_connector
->sharpness
)
2302 *val
= sdvo_state
->tv
.sharpness
;
2303 else if (property
== intel_sdvo_connector
->flicker_filter
)
2304 *val
= sdvo_state
->tv
.flicker_filter
;
2305 else if (property
== intel_sdvo_connector
->flicker_filter_2d
)
2306 *val
= sdvo_state
->tv
.flicker_filter_2d
;
2307 else if (property
== intel_sdvo_connector
->flicker_filter_adaptive
)
2308 *val
= sdvo_state
->tv
.flicker_filter_adaptive
;
2309 else if (property
== intel_sdvo_connector
->tv_chroma_filter
)
2310 *val
= sdvo_state
->tv
.chroma_filter
;
2311 else if (property
== intel_sdvo_connector
->tv_luma_filter
)
2312 *val
= sdvo_state
->tv
.luma_filter
;
2313 else if (property
== intel_sdvo_connector
->dot_crawl
)
2314 *val
= sdvo_state
->tv
.dot_crawl
;
2316 return intel_digital_connector_atomic_get_property(connector
, state
, property
, val
);
2322 intel_sdvo_connector_atomic_set_property(struct drm_connector
*connector
,
2323 struct drm_connector_state
*state
,
2324 struct drm_property
*property
,
2327 struct intel_sdvo_connector
*intel_sdvo_connector
= to_intel_sdvo_connector(connector
);
2328 struct intel_sdvo_connector_state
*sdvo_state
= to_intel_sdvo_connector_state(state
);
2330 if (property
== intel_sdvo_connector
->tv_format
) {
2331 state
->tv
.mode
= intel_sdvo_connector
->tv_format_supported
[val
];
2334 struct drm_crtc_state
*crtc_state
=
2335 drm_atomic_get_new_crtc_state(state
->state
, state
->crtc
);
2337 crtc_state
->connectors_changed
= true;
2339 } else if (property
== intel_sdvo_connector
->top
||
2340 property
== intel_sdvo_connector
->bottom
)
2341 /* Cannot set these independent from each other */
2342 sdvo_state
->tv
.overscan_v
= intel_sdvo_connector
->max_vscan
- val
;
2343 else if (property
== intel_sdvo_connector
->left
||
2344 property
== intel_sdvo_connector
->right
)
2345 /* Cannot set these independent from each other */
2346 sdvo_state
->tv
.overscan_h
= intel_sdvo_connector
->max_hscan
- val
;
2347 else if (property
== intel_sdvo_connector
->hpos
)
2348 sdvo_state
->tv
.hpos
= val
;
2349 else if (property
== intel_sdvo_connector
->vpos
)
2350 sdvo_state
->tv
.vpos
= val
;
2351 else if (property
== intel_sdvo_connector
->saturation
)
2352 state
->tv
.saturation
= val
;
2353 else if (property
== intel_sdvo_connector
->contrast
)
2354 state
->tv
.contrast
= val
;
2355 else if (property
== intel_sdvo_connector
->hue
)
2356 state
->tv
.hue
= val
;
2357 else if (property
== intel_sdvo_connector
->brightness
)
2358 state
->tv
.brightness
= val
;
2359 else if (property
== intel_sdvo_connector
->sharpness
)
2360 sdvo_state
->tv
.sharpness
= val
;
2361 else if (property
== intel_sdvo_connector
->flicker_filter
)
2362 sdvo_state
->tv
.flicker_filter
= val
;
2363 else if (property
== intel_sdvo_connector
->flicker_filter_2d
)
2364 sdvo_state
->tv
.flicker_filter_2d
= val
;
2365 else if (property
== intel_sdvo_connector
->flicker_filter_adaptive
)
2366 sdvo_state
->tv
.flicker_filter_adaptive
= val
;
2367 else if (property
== intel_sdvo_connector
->tv_chroma_filter
)
2368 sdvo_state
->tv
.chroma_filter
= val
;
2369 else if (property
== intel_sdvo_connector
->tv_luma_filter
)
2370 sdvo_state
->tv
.luma_filter
= val
;
2371 else if (property
== intel_sdvo_connector
->dot_crawl
)
2372 sdvo_state
->tv
.dot_crawl
= val
;
2374 return intel_digital_connector_atomic_set_property(connector
, state
, property
, val
);
2380 intel_sdvo_connector_register(struct drm_connector
*connector
)
2382 struct intel_sdvo
*sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
2385 ret
= intel_connector_register(connector
);
2389 return sysfs_create_link(&connector
->kdev
->kobj
,
2390 &sdvo
->ddc
.dev
.kobj
,
2391 sdvo
->ddc
.dev
.kobj
.name
);
2395 intel_sdvo_connector_unregister(struct drm_connector
*connector
)
2397 struct intel_sdvo
*sdvo
= intel_attached_sdvo(to_intel_connector(connector
));
2399 sysfs_remove_link(&connector
->kdev
->kobj
,
2400 sdvo
->ddc
.dev
.kobj
.name
);
2401 intel_connector_unregister(connector
);
2404 static struct drm_connector_state
*
2405 intel_sdvo_connector_duplicate_state(struct drm_connector
*connector
)
2407 struct intel_sdvo_connector_state
*state
;
2409 state
= kmemdup(connector
->state
, sizeof(*state
), GFP_KERNEL
);
2413 __drm_atomic_helper_connector_duplicate_state(connector
, &state
->base
.base
);
2414 return &state
->base
.base
;
2417 static const struct drm_connector_funcs intel_sdvo_connector_funcs
= {
2418 .detect
= intel_sdvo_detect
,
2419 .fill_modes
= drm_helper_probe_single_connector_modes
,
2420 .atomic_get_property
= intel_sdvo_connector_atomic_get_property
,
2421 .atomic_set_property
= intel_sdvo_connector_atomic_set_property
,
2422 .late_register
= intel_sdvo_connector_register
,
2423 .early_unregister
= intel_sdvo_connector_unregister
,
2424 .destroy
= intel_connector_destroy
,
2425 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
2426 .atomic_duplicate_state
= intel_sdvo_connector_duplicate_state
,
2429 static int intel_sdvo_atomic_check(struct drm_connector
*conn
,
2430 struct drm_atomic_state
*state
)
2432 struct drm_connector_state
*new_conn_state
=
2433 drm_atomic_get_new_connector_state(state
, conn
);
2434 struct drm_connector_state
*old_conn_state
=
2435 drm_atomic_get_old_connector_state(state
, conn
);
2436 struct intel_sdvo_connector_state
*old_state
=
2437 to_intel_sdvo_connector_state(old_conn_state
);
2438 struct intel_sdvo_connector_state
*new_state
=
2439 to_intel_sdvo_connector_state(new_conn_state
);
2441 if (new_conn_state
->crtc
&&
2442 (memcmp(&old_state
->tv
, &new_state
->tv
, sizeof(old_state
->tv
)) ||
2443 memcmp(&old_conn_state
->tv
, &new_conn_state
->tv
, sizeof(old_conn_state
->tv
)))) {
2444 struct drm_crtc_state
*crtc_state
=
2445 drm_atomic_get_new_crtc_state(state
,
2446 new_conn_state
->crtc
);
2448 crtc_state
->connectors_changed
= true;
2451 return intel_digital_connector_atomic_check(conn
, state
);
2454 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs
= {
2455 .get_modes
= intel_sdvo_get_modes
,
2456 .mode_valid
= intel_sdvo_mode_valid
,
2457 .atomic_check
= intel_sdvo_atomic_check
,
2460 static void intel_sdvo_enc_destroy(struct drm_encoder
*encoder
)
2462 struct intel_sdvo
*intel_sdvo
= to_sdvo(to_intel_encoder(encoder
));
2464 i2c_del_adapter(&intel_sdvo
->ddc
);
2465 intel_encoder_destroy(encoder
);
2468 static const struct drm_encoder_funcs intel_sdvo_enc_funcs
= {
2469 .destroy
= intel_sdvo_enc_destroy
,
2473 intel_sdvo_guess_ddc_bus(struct intel_sdvo
*sdvo
)
2476 unsigned int num_bits
;
2479 * Make a mask of outputs less than or equal to our own priority in the
2482 switch (sdvo
->controlled_output
) {
2483 case SDVO_OUTPUT_LVDS1
:
2484 mask
|= SDVO_OUTPUT_LVDS1
;
2486 case SDVO_OUTPUT_LVDS0
:
2487 mask
|= SDVO_OUTPUT_LVDS0
;
2489 case SDVO_OUTPUT_TMDS1
:
2490 mask
|= SDVO_OUTPUT_TMDS1
;
2492 case SDVO_OUTPUT_TMDS0
:
2493 mask
|= SDVO_OUTPUT_TMDS0
;
2495 case SDVO_OUTPUT_RGB1
:
2496 mask
|= SDVO_OUTPUT_RGB1
;
2498 case SDVO_OUTPUT_RGB0
:
2499 mask
|= SDVO_OUTPUT_RGB0
;
2503 /* Count bits to find what number we are in the priority list. */
2504 mask
&= sdvo
->caps
.output_flags
;
2505 num_bits
= hweight16(mask
);
2506 /* If more than 3 outputs, default to DDC bus 3 for now. */
2510 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2511 sdvo
->ddc_bus
= 1 << num_bits
;
2515 * Choose the appropriate DDC bus for control bus switch command for this
2516 * SDVO output based on the controlled output.
2518 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2519 * outputs, then LVDS outputs.
2522 intel_sdvo_select_ddc_bus(struct drm_i915_private
*dev_priv
,
2523 struct intel_sdvo
*sdvo
)
2525 struct sdvo_device_mapping
*mapping
;
2527 if (sdvo
->port
== PORT_B
)
2528 mapping
= &dev_priv
->vbt
.sdvo_mappings
[0];
2530 mapping
= &dev_priv
->vbt
.sdvo_mappings
[1];
2532 if (mapping
->initialized
)
2533 sdvo
->ddc_bus
= 1 << ((mapping
->ddc_pin
& 0xf0) >> 4);
2535 intel_sdvo_guess_ddc_bus(sdvo
);
2539 intel_sdvo_select_i2c_bus(struct drm_i915_private
*dev_priv
,
2540 struct intel_sdvo
*sdvo
)
2542 struct sdvo_device_mapping
*mapping
;
2545 if (sdvo
->port
== PORT_B
)
2546 mapping
= &dev_priv
->vbt
.sdvo_mappings
[0];
2548 mapping
= &dev_priv
->vbt
.sdvo_mappings
[1];
2550 if (mapping
->initialized
&&
2551 intel_gmbus_is_valid_pin(dev_priv
, mapping
->i2c_pin
))
2552 pin
= mapping
->i2c_pin
;
2554 pin
= GMBUS_PIN_DPB
;
2556 sdvo
->i2c
= intel_gmbus_get_adapter(dev_priv
, pin
);
2559 * With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
2560 * our code totally fails once we start using gmbus. Hence fall back to
2561 * bit banging for now.
2563 intel_gmbus_force_bit(sdvo
->i2c
, true);
2566 /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
2568 intel_sdvo_unselect_i2c_bus(struct intel_sdvo
*sdvo
)
2570 intel_gmbus_force_bit(sdvo
->i2c
, false);
2574 intel_sdvo_is_hdmi_connector(struct intel_sdvo
*intel_sdvo
, int device
)
2576 return intel_sdvo_check_supp_encode(intel_sdvo
);
2580 intel_sdvo_get_slave_addr(struct drm_i915_private
*dev_priv
,
2581 struct intel_sdvo
*sdvo
)
2583 struct sdvo_device_mapping
*my_mapping
, *other_mapping
;
2585 if (sdvo
->port
== PORT_B
) {
2586 my_mapping
= &dev_priv
->vbt
.sdvo_mappings
[0];
2587 other_mapping
= &dev_priv
->vbt
.sdvo_mappings
[1];
2589 my_mapping
= &dev_priv
->vbt
.sdvo_mappings
[1];
2590 other_mapping
= &dev_priv
->vbt
.sdvo_mappings
[0];
2593 /* If the BIOS described our SDVO device, take advantage of it. */
2594 if (my_mapping
->slave_addr
)
2595 return my_mapping
->slave_addr
;
2598 * If the BIOS only described a different SDVO device, use the
2599 * address that it isn't using.
2601 if (other_mapping
->slave_addr
) {
2602 if (other_mapping
->slave_addr
== 0x70)
2609 * No SDVO device info is found for another DVO port,
2610 * so use mapping assumption we had before BIOS parsing.
2612 if (sdvo
->port
== PORT_B
)
2619 intel_sdvo_connector_init(struct intel_sdvo_connector
*connector
,
2620 struct intel_sdvo
*encoder
)
2622 struct drm_connector
*drm_connector
;
2625 drm_connector
= &connector
->base
.base
;
2626 ret
= drm_connector_init(encoder
->base
.base
.dev
,
2628 &intel_sdvo_connector_funcs
,
2629 connector
->base
.base
.connector_type
);
2633 drm_connector_helper_add(drm_connector
,
2634 &intel_sdvo_connector_helper_funcs
);
2636 connector
->base
.base
.interlace_allowed
= 1;
2637 connector
->base
.base
.doublescan_allowed
= 0;
2638 connector
->base
.base
.display_info
.subpixel_order
= SubPixelHorizontalRGB
;
2639 connector
->base
.get_hw_state
= intel_sdvo_connector_get_hw_state
;
2641 intel_connector_attach_encoder(&connector
->base
, &encoder
->base
);
2647 intel_sdvo_add_hdmi_properties(struct intel_sdvo
*intel_sdvo
,
2648 struct intel_sdvo_connector
*connector
)
2650 struct drm_i915_private
*dev_priv
= to_i915(connector
->base
.base
.dev
);
2652 intel_attach_force_audio_property(&connector
->base
.base
);
2653 if (INTEL_GEN(dev_priv
) >= 4 && IS_MOBILE(dev_priv
)) {
2654 intel_attach_broadcast_rgb_property(&connector
->base
.base
);
2656 intel_attach_aspect_ratio_property(&connector
->base
.base
);
2659 static struct intel_sdvo_connector
*intel_sdvo_connector_alloc(void)
2661 struct intel_sdvo_connector
*sdvo_connector
;
2662 struct intel_sdvo_connector_state
*conn_state
;
2664 sdvo_connector
= kzalloc(sizeof(*sdvo_connector
), GFP_KERNEL
);
2665 if (!sdvo_connector
)
2668 conn_state
= kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
2670 kfree(sdvo_connector
);
2674 __drm_atomic_helper_connector_reset(&sdvo_connector
->base
.base
,
2675 &conn_state
->base
.base
);
2677 return sdvo_connector
;
2681 intel_sdvo_dvi_init(struct intel_sdvo
*intel_sdvo
, int device
)
2683 struct drm_encoder
*encoder
= &intel_sdvo
->base
.base
;
2684 struct drm_connector
*connector
;
2685 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
2686 struct intel_connector
*intel_connector
;
2687 struct intel_sdvo_connector
*intel_sdvo_connector
;
2689 DRM_DEBUG_KMS("initialising DVI device %d\n", device
);
2691 intel_sdvo_connector
= intel_sdvo_connector_alloc();
2692 if (!intel_sdvo_connector
)
2696 intel_sdvo
->controlled_output
|= SDVO_OUTPUT_TMDS0
;
2697 intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_TMDS0
;
2698 } else if (device
== 1) {
2699 intel_sdvo
->controlled_output
|= SDVO_OUTPUT_TMDS1
;
2700 intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_TMDS1
;
2703 intel_connector
= &intel_sdvo_connector
->base
;
2704 connector
= &intel_connector
->base
;
2705 if (intel_sdvo_get_hotplug_support(intel_sdvo
) &
2706 intel_sdvo_connector
->output_flag
) {
2707 intel_sdvo
->hotplug_active
|= intel_sdvo_connector
->output_flag
;
2709 * Some SDVO devices have one-shot hotplug interrupts.
2710 * Ensure that they get re-enabled when an interrupt happens.
2712 intel_encoder
->hotplug
= intel_sdvo_hotplug
;
2713 intel_sdvo_enable_hotplug(intel_encoder
);
2715 intel_connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
| DRM_CONNECTOR_POLL_DISCONNECT
;
2717 encoder
->encoder_type
= DRM_MODE_ENCODER_TMDS
;
2718 connector
->connector_type
= DRM_MODE_CONNECTOR_DVID
;
2720 if (intel_sdvo_is_hdmi_connector(intel_sdvo
, device
)) {
2721 connector
->connector_type
= DRM_MODE_CONNECTOR_HDMIA
;
2722 intel_sdvo_connector
->is_hdmi
= true;
2725 if (intel_sdvo_connector_init(intel_sdvo_connector
, intel_sdvo
) < 0) {
2726 kfree(intel_sdvo_connector
);
2730 if (intel_sdvo_connector
->is_hdmi
)
2731 intel_sdvo_add_hdmi_properties(intel_sdvo
, intel_sdvo_connector
);
2737 intel_sdvo_tv_init(struct intel_sdvo
*intel_sdvo
, int type
)
2739 struct drm_encoder
*encoder
= &intel_sdvo
->base
.base
;
2740 struct drm_connector
*connector
;
2741 struct intel_connector
*intel_connector
;
2742 struct intel_sdvo_connector
*intel_sdvo_connector
;
2744 DRM_DEBUG_KMS("initialising TV type %d\n", type
);
2746 intel_sdvo_connector
= intel_sdvo_connector_alloc();
2747 if (!intel_sdvo_connector
)
2750 intel_connector
= &intel_sdvo_connector
->base
;
2751 connector
= &intel_connector
->base
;
2752 encoder
->encoder_type
= DRM_MODE_ENCODER_TVDAC
;
2753 connector
->connector_type
= DRM_MODE_CONNECTOR_SVIDEO
;
2755 intel_sdvo
->controlled_output
|= type
;
2756 intel_sdvo_connector
->output_flag
= type
;
2758 if (intel_sdvo_connector_init(intel_sdvo_connector
, intel_sdvo
) < 0) {
2759 kfree(intel_sdvo_connector
);
2763 if (!intel_sdvo_tv_create_property(intel_sdvo
, intel_sdvo_connector
, type
))
2766 if (!intel_sdvo_create_enhance_property(intel_sdvo
, intel_sdvo_connector
))
2772 intel_connector_destroy(connector
);
2777 intel_sdvo_analog_init(struct intel_sdvo
*intel_sdvo
, int device
)
2779 struct drm_encoder
*encoder
= &intel_sdvo
->base
.base
;
2780 struct drm_connector
*connector
;
2781 struct intel_connector
*intel_connector
;
2782 struct intel_sdvo_connector
*intel_sdvo_connector
;
2784 DRM_DEBUG_KMS("initialising analog device %d\n", device
);
2786 intel_sdvo_connector
= intel_sdvo_connector_alloc();
2787 if (!intel_sdvo_connector
)
2790 intel_connector
= &intel_sdvo_connector
->base
;
2791 connector
= &intel_connector
->base
;
2792 intel_connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
2793 encoder
->encoder_type
= DRM_MODE_ENCODER_DAC
;
2794 connector
->connector_type
= DRM_MODE_CONNECTOR_VGA
;
2797 intel_sdvo
->controlled_output
|= SDVO_OUTPUT_RGB0
;
2798 intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_RGB0
;
2799 } else if (device
== 1) {
2800 intel_sdvo
->controlled_output
|= SDVO_OUTPUT_RGB1
;
2801 intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_RGB1
;
2804 if (intel_sdvo_connector_init(intel_sdvo_connector
, intel_sdvo
) < 0) {
2805 kfree(intel_sdvo_connector
);
2813 intel_sdvo_lvds_init(struct intel_sdvo
*intel_sdvo
, int device
)
2815 struct drm_encoder
*encoder
= &intel_sdvo
->base
.base
;
2816 struct drm_connector
*connector
;
2817 struct intel_connector
*intel_connector
;
2818 struct intel_sdvo_connector
*intel_sdvo_connector
;
2819 struct drm_display_mode
*mode
;
2821 DRM_DEBUG_KMS("initialising LVDS device %d\n", device
);
2823 intel_sdvo_connector
= intel_sdvo_connector_alloc();
2824 if (!intel_sdvo_connector
)
2827 intel_connector
= &intel_sdvo_connector
->base
;
2828 connector
= &intel_connector
->base
;
2829 encoder
->encoder_type
= DRM_MODE_ENCODER_LVDS
;
2830 connector
->connector_type
= DRM_MODE_CONNECTOR_LVDS
;
2833 intel_sdvo
->controlled_output
|= SDVO_OUTPUT_LVDS0
;
2834 intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_LVDS0
;
2835 } else if (device
== 1) {
2836 intel_sdvo
->controlled_output
|= SDVO_OUTPUT_LVDS1
;
2837 intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_LVDS1
;
2840 if (intel_sdvo_connector_init(intel_sdvo_connector
, intel_sdvo
) < 0) {
2841 kfree(intel_sdvo_connector
);
2845 if (!intel_sdvo_create_enhance_property(intel_sdvo
, intel_sdvo_connector
))
2848 intel_sdvo_get_lvds_modes(connector
);
2850 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
2851 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
2852 struct drm_display_mode
*fixed_mode
=
2853 drm_mode_duplicate(connector
->dev
, mode
);
2855 intel_panel_init(&intel_connector
->panel
,
2861 if (!intel_connector
->panel
.fixed_mode
)
2867 intel_connector_destroy(connector
);
2872 intel_sdvo_output_setup(struct intel_sdvo
*intel_sdvo
, u16 flags
)
2874 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2876 if (flags
& SDVO_OUTPUT_TMDS0
)
2877 if (!intel_sdvo_dvi_init(intel_sdvo
, 0))
2880 if ((flags
& SDVO_TMDS_MASK
) == SDVO_TMDS_MASK
)
2881 if (!intel_sdvo_dvi_init(intel_sdvo
, 1))
2884 /* TV has no XXX1 function block */
2885 if (flags
& SDVO_OUTPUT_SVID0
)
2886 if (!intel_sdvo_tv_init(intel_sdvo
, SDVO_OUTPUT_SVID0
))
2889 if (flags
& SDVO_OUTPUT_CVBS0
)
2890 if (!intel_sdvo_tv_init(intel_sdvo
, SDVO_OUTPUT_CVBS0
))
2893 if (flags
& SDVO_OUTPUT_YPRPB0
)
2894 if (!intel_sdvo_tv_init(intel_sdvo
, SDVO_OUTPUT_YPRPB0
))
2897 if (flags
& SDVO_OUTPUT_RGB0
)
2898 if (!intel_sdvo_analog_init(intel_sdvo
, 0))
2901 if ((flags
& SDVO_RGB_MASK
) == SDVO_RGB_MASK
)
2902 if (!intel_sdvo_analog_init(intel_sdvo
, 1))
2905 if (flags
& SDVO_OUTPUT_LVDS0
)
2906 if (!intel_sdvo_lvds_init(intel_sdvo
, 0))
2909 if ((flags
& SDVO_LVDS_MASK
) == SDVO_LVDS_MASK
)
2910 if (!intel_sdvo_lvds_init(intel_sdvo
, 1))
2913 if ((flags
& SDVO_OUTPUT_MASK
) == 0) {
2914 unsigned char bytes
[2];
2916 intel_sdvo
->controlled_output
= 0;
2917 memcpy(bytes
, &intel_sdvo
->caps
.output_flags
, 2);
2918 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2919 SDVO_NAME(intel_sdvo
),
2920 bytes
[0], bytes
[1]);
2923 intel_sdvo
->base
.pipe_mask
= ~0;
2928 static void intel_sdvo_output_cleanup(struct intel_sdvo
*intel_sdvo
)
2930 struct drm_device
*dev
= intel_sdvo
->base
.base
.dev
;
2931 struct drm_connector
*connector
, *tmp
;
2933 list_for_each_entry_safe(connector
, tmp
,
2934 &dev
->mode_config
.connector_list
, head
) {
2935 if (intel_attached_encoder(to_intel_connector(connector
)) == &intel_sdvo
->base
) {
2936 drm_connector_unregister(connector
);
2937 intel_connector_destroy(connector
);
2942 static bool intel_sdvo_tv_create_property(struct intel_sdvo
*intel_sdvo
,
2943 struct intel_sdvo_connector
*intel_sdvo_connector
,
2946 struct drm_device
*dev
= intel_sdvo
->base
.base
.dev
;
2947 struct intel_sdvo_tv_format format
;
2950 if (!intel_sdvo_set_target_output(intel_sdvo
, type
))
2953 BUILD_BUG_ON(sizeof(format
) != 6);
2954 if (!intel_sdvo_get_value(intel_sdvo
,
2955 SDVO_CMD_GET_SUPPORTED_TV_FORMATS
,
2956 &format
, sizeof(format
)))
2959 memcpy(&format_map
, &format
, min(sizeof(format_map
), sizeof(format
)));
2961 if (format_map
== 0)
2964 intel_sdvo_connector
->format_supported_num
= 0;
2965 for (i
= 0 ; i
< TV_FORMAT_NUM
; i
++)
2966 if (format_map
& (1 << i
))
2967 intel_sdvo_connector
->tv_format_supported
[intel_sdvo_connector
->format_supported_num
++] = i
;
2970 intel_sdvo_connector
->tv_format
=
2971 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
2972 "mode", intel_sdvo_connector
->format_supported_num
);
2973 if (!intel_sdvo_connector
->tv_format
)
2976 for (i
= 0; i
< intel_sdvo_connector
->format_supported_num
; i
++)
2977 drm_property_add_enum(intel_sdvo_connector
->tv_format
, i
,
2978 tv_format_names
[intel_sdvo_connector
->tv_format_supported
[i
]]);
2980 intel_sdvo_connector
->base
.base
.state
->tv
.mode
= intel_sdvo_connector
->tv_format_supported
[0];
2981 drm_object_attach_property(&intel_sdvo_connector
->base
.base
.base
,
2982 intel_sdvo_connector
->tv_format
, 0);
2987 #define _ENHANCEMENT(state_assignment, name, NAME) do { \
2988 if (enhancements.name) { \
2989 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
2990 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
2992 intel_sdvo_connector->name = \
2993 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
2994 if (!intel_sdvo_connector->name) return false; \
2995 state_assignment = response; \
2996 drm_object_attach_property(&connector->base, \
2997 intel_sdvo_connector->name, 0); \
2998 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
2999 data_value[0], data_value[1], response); \
3003 #define ENHANCEMENT(state, name, NAME) _ENHANCEMENT((state)->name, name, NAME)
3006 intel_sdvo_create_enhance_property_tv(struct intel_sdvo
*intel_sdvo
,
3007 struct intel_sdvo_connector
*intel_sdvo_connector
,
3008 struct intel_sdvo_enhancements_reply enhancements
)
3010 struct drm_device
*dev
= intel_sdvo
->base
.base
.dev
;
3011 struct drm_connector
*connector
= &intel_sdvo_connector
->base
.base
;
3012 struct drm_connector_state
*conn_state
= connector
->state
;
3013 struct intel_sdvo_connector_state
*sdvo_state
=
3014 to_intel_sdvo_connector_state(conn_state
);
3015 u16 response
, data_value
[2];
3017 /* when horizontal overscan is supported, Add the left/right property */
3018 if (enhancements
.overscan_h
) {
3019 if (!intel_sdvo_get_value(intel_sdvo
,
3020 SDVO_CMD_GET_MAX_OVERSCAN_H
,
3024 if (!intel_sdvo_get_value(intel_sdvo
,
3025 SDVO_CMD_GET_OVERSCAN_H
,
3029 sdvo_state
->tv
.overscan_h
= response
;
3031 intel_sdvo_connector
->max_hscan
= data_value
[0];
3032 intel_sdvo_connector
->left
=
3033 drm_property_create_range(dev
, 0, "left_margin", 0, data_value
[0]);
3034 if (!intel_sdvo_connector
->left
)
3037 drm_object_attach_property(&connector
->base
,
3038 intel_sdvo_connector
->left
, 0);
3040 intel_sdvo_connector
->right
=
3041 drm_property_create_range(dev
, 0, "right_margin", 0, data_value
[0]);
3042 if (!intel_sdvo_connector
->right
)
3045 drm_object_attach_property(&connector
->base
,
3046 intel_sdvo_connector
->right
, 0);
3047 DRM_DEBUG_KMS("h_overscan: max %d, "
3048 "default %d, current %d\n",
3049 data_value
[0], data_value
[1], response
);
3052 if (enhancements
.overscan_v
) {
3053 if (!intel_sdvo_get_value(intel_sdvo
,
3054 SDVO_CMD_GET_MAX_OVERSCAN_V
,
3058 if (!intel_sdvo_get_value(intel_sdvo
,
3059 SDVO_CMD_GET_OVERSCAN_V
,
3063 sdvo_state
->tv
.overscan_v
= response
;
3065 intel_sdvo_connector
->max_vscan
= data_value
[0];
3066 intel_sdvo_connector
->top
=
3067 drm_property_create_range(dev
, 0,
3068 "top_margin", 0, data_value
[0]);
3069 if (!intel_sdvo_connector
->top
)
3072 drm_object_attach_property(&connector
->base
,
3073 intel_sdvo_connector
->top
, 0);
3075 intel_sdvo_connector
->bottom
=
3076 drm_property_create_range(dev
, 0,
3077 "bottom_margin", 0, data_value
[0]);
3078 if (!intel_sdvo_connector
->bottom
)
3081 drm_object_attach_property(&connector
->base
,
3082 intel_sdvo_connector
->bottom
, 0);
3083 DRM_DEBUG_KMS("v_overscan: max %d, "
3084 "default %d, current %d\n",
3085 data_value
[0], data_value
[1], response
);
3088 ENHANCEMENT(&sdvo_state
->tv
, hpos
, HPOS
);
3089 ENHANCEMENT(&sdvo_state
->tv
, vpos
, VPOS
);
3090 ENHANCEMENT(&conn_state
->tv
, saturation
, SATURATION
);
3091 ENHANCEMENT(&conn_state
->tv
, contrast
, CONTRAST
);
3092 ENHANCEMENT(&conn_state
->tv
, hue
, HUE
);
3093 ENHANCEMENT(&conn_state
->tv
, brightness
, BRIGHTNESS
);
3094 ENHANCEMENT(&sdvo_state
->tv
, sharpness
, SHARPNESS
);
3095 ENHANCEMENT(&sdvo_state
->tv
, flicker_filter
, FLICKER_FILTER
);
3096 ENHANCEMENT(&sdvo_state
->tv
, flicker_filter_adaptive
, FLICKER_FILTER_ADAPTIVE
);
3097 ENHANCEMENT(&sdvo_state
->tv
, flicker_filter_2d
, FLICKER_FILTER_2D
);
3098 _ENHANCEMENT(sdvo_state
->tv
.chroma_filter
, tv_chroma_filter
, TV_CHROMA_FILTER
);
3099 _ENHANCEMENT(sdvo_state
->tv
.luma_filter
, tv_luma_filter
, TV_LUMA_FILTER
);
3101 if (enhancements
.dot_crawl
) {
3102 if (!intel_sdvo_get_value(intel_sdvo
, SDVO_CMD_GET_DOT_CRAWL
, &response
, 2))
3105 sdvo_state
->tv
.dot_crawl
= response
& 0x1;
3106 intel_sdvo_connector
->dot_crawl
=
3107 drm_property_create_range(dev
, 0, "dot_crawl", 0, 1);
3108 if (!intel_sdvo_connector
->dot_crawl
)
3111 drm_object_attach_property(&connector
->base
,
3112 intel_sdvo_connector
->dot_crawl
, 0);
3113 DRM_DEBUG_KMS("dot crawl: current %d\n", response
);
3120 intel_sdvo_create_enhance_property_lvds(struct intel_sdvo
*intel_sdvo
,
3121 struct intel_sdvo_connector
*intel_sdvo_connector
,
3122 struct intel_sdvo_enhancements_reply enhancements
)
3124 struct drm_device
*dev
= intel_sdvo
->base
.base
.dev
;
3125 struct drm_connector
*connector
= &intel_sdvo_connector
->base
.base
;
3126 u16 response
, data_value
[2];
3128 ENHANCEMENT(&connector
->state
->tv
, brightness
, BRIGHTNESS
);
3135 static bool intel_sdvo_create_enhance_property(struct intel_sdvo
*intel_sdvo
,
3136 struct intel_sdvo_connector
*intel_sdvo_connector
)
3139 struct intel_sdvo_enhancements_reply reply
;
3143 BUILD_BUG_ON(sizeof(enhancements
) != 2);
3145 if (!intel_sdvo_get_value(intel_sdvo
,
3146 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
,
3147 &enhancements
, sizeof(enhancements
)) ||
3148 enhancements
.response
== 0) {
3149 DRM_DEBUG_KMS("No enhancement is supported\n");
3153 if (IS_TV(intel_sdvo_connector
))
3154 return intel_sdvo_create_enhance_property_tv(intel_sdvo
, intel_sdvo_connector
, enhancements
.reply
);
3155 else if (IS_LVDS(intel_sdvo_connector
))
3156 return intel_sdvo_create_enhance_property_lvds(intel_sdvo
, intel_sdvo_connector
, enhancements
.reply
);
3161 static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter
*adapter
,
3162 struct i2c_msg
*msgs
,
3165 struct intel_sdvo
*sdvo
= adapter
->algo_data
;
3167 if (!__intel_sdvo_set_control_bus_switch(sdvo
, sdvo
->ddc_bus
))
3170 return sdvo
->i2c
->algo
->master_xfer(sdvo
->i2c
, msgs
, num
);
3173 static u32
intel_sdvo_ddc_proxy_func(struct i2c_adapter
*adapter
)
3175 struct intel_sdvo
*sdvo
= adapter
->algo_data
;
3176 return sdvo
->i2c
->algo
->functionality(sdvo
->i2c
);
3179 static const struct i2c_algorithm intel_sdvo_ddc_proxy
= {
3180 .master_xfer
= intel_sdvo_ddc_proxy_xfer
,
3181 .functionality
= intel_sdvo_ddc_proxy_func
3184 static void proxy_lock_bus(struct i2c_adapter
*adapter
,
3187 struct intel_sdvo
*sdvo
= adapter
->algo_data
;
3188 sdvo
->i2c
->lock_ops
->lock_bus(sdvo
->i2c
, flags
);
3191 static int proxy_trylock_bus(struct i2c_adapter
*adapter
,
3194 struct intel_sdvo
*sdvo
= adapter
->algo_data
;
3195 return sdvo
->i2c
->lock_ops
->trylock_bus(sdvo
->i2c
, flags
);
3198 static void proxy_unlock_bus(struct i2c_adapter
*adapter
,
3201 struct intel_sdvo
*sdvo
= adapter
->algo_data
;
3202 sdvo
->i2c
->lock_ops
->unlock_bus(sdvo
->i2c
, flags
);
3205 static const struct i2c_lock_operations proxy_lock_ops
= {
3206 .lock_bus
= proxy_lock_bus
,
3207 .trylock_bus
= proxy_trylock_bus
,
3208 .unlock_bus
= proxy_unlock_bus
,
3212 intel_sdvo_init_ddc_proxy(struct intel_sdvo
*sdvo
,
3213 struct drm_i915_private
*dev_priv
)
3215 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
3217 sdvo
->ddc
.owner
= THIS_MODULE
;
3218 sdvo
->ddc
.class = I2C_CLASS_DDC
;
3219 snprintf(sdvo
->ddc
.name
, I2C_NAME_SIZE
, "SDVO DDC proxy");
3220 sdvo
->ddc
.dev
.parent
= &pdev
->dev
;
3221 sdvo
->ddc
.algo_data
= sdvo
;
3222 sdvo
->ddc
.algo
= &intel_sdvo_ddc_proxy
;
3223 sdvo
->ddc
.lock_ops
= &proxy_lock_ops
;
3225 return i2c_add_adapter(&sdvo
->ddc
) == 0;
3228 static void assert_sdvo_port_valid(const struct drm_i915_private
*dev_priv
,
3231 if (HAS_PCH_SPLIT(dev_priv
))
3232 WARN_ON(port
!= PORT_B
);
3234 WARN_ON(port
!= PORT_B
&& port
!= PORT_C
);
3237 bool intel_sdvo_init(struct drm_i915_private
*dev_priv
,
3238 i915_reg_t sdvo_reg
, enum port port
)
3240 struct intel_encoder
*intel_encoder
;
3241 struct intel_sdvo
*intel_sdvo
;
3244 assert_sdvo_port_valid(dev_priv
, port
);
3246 intel_sdvo
= kzalloc(sizeof(*intel_sdvo
), GFP_KERNEL
);
3250 intel_sdvo
->sdvo_reg
= sdvo_reg
;
3251 intel_sdvo
->port
= port
;
3252 intel_sdvo
->slave_addr
=
3253 intel_sdvo_get_slave_addr(dev_priv
, intel_sdvo
) >> 1;
3254 intel_sdvo_select_i2c_bus(dev_priv
, intel_sdvo
);
3255 if (!intel_sdvo_init_ddc_proxy(intel_sdvo
, dev_priv
))
3258 /* encoder type will be decided later */
3259 intel_encoder
= &intel_sdvo
->base
;
3260 intel_encoder
->type
= INTEL_OUTPUT_SDVO
;
3261 intel_encoder
->power_domain
= POWER_DOMAIN_PORT_OTHER
;
3262 intel_encoder
->port
= port
;
3263 drm_encoder_init(&dev_priv
->drm
, &intel_encoder
->base
,
3264 &intel_sdvo_enc_funcs
, 0,
3265 "SDVO %c", port_name(port
));
3267 /* Read the regs to test if we can talk to the device */
3268 for (i
= 0; i
< 0x40; i
++) {
3271 if (!intel_sdvo_read_byte(intel_sdvo
, i
, &byte
)) {
3272 DRM_DEBUG_KMS("No SDVO device found on %s\n",
3273 SDVO_NAME(intel_sdvo
));
3278 intel_encoder
->compute_config
= intel_sdvo_compute_config
;
3279 if (HAS_PCH_SPLIT(dev_priv
)) {
3280 intel_encoder
->disable
= pch_disable_sdvo
;
3281 intel_encoder
->post_disable
= pch_post_disable_sdvo
;
3283 intel_encoder
->disable
= intel_disable_sdvo
;
3285 intel_encoder
->pre_enable
= intel_sdvo_pre_enable
;
3286 intel_encoder
->enable
= intel_enable_sdvo
;
3287 intel_encoder
->get_hw_state
= intel_sdvo_get_hw_state
;
3288 intel_encoder
->get_config
= intel_sdvo_get_config
;
3290 /* In default case sdvo lvds is false */
3291 if (!intel_sdvo_get_capabilities(intel_sdvo
, &intel_sdvo
->caps
))
3294 if (intel_sdvo_output_setup(intel_sdvo
,
3295 intel_sdvo
->caps
.output_flags
) != true) {
3296 DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
3297 SDVO_NAME(intel_sdvo
));
3298 /* Output_setup can leave behind connectors! */
3303 * Only enable the hotplug irq if we need it, to work around noisy
3306 if (intel_sdvo
->hotplug_active
) {
3307 if (intel_sdvo
->port
== PORT_B
)
3308 intel_encoder
->hpd_pin
= HPD_SDVO_B
;
3310 intel_encoder
->hpd_pin
= HPD_SDVO_C
;
3314 * Cloning SDVO with anything is often impossible, since the SDVO
3315 * encoder can request a special input timing mode. And even if that's
3316 * not the case we have evidence that cloning a plain unscaled mode with
3317 * VGA doesn't really work. Furthermore the cloning flags are way too
3318 * simplistic anyway to express such constraints, so just give up on
3319 * cloning for SDVO encoders.
3321 intel_sdvo
->base
.cloneable
= 0;
3323 intel_sdvo_select_ddc_bus(dev_priv
, intel_sdvo
);
3325 /* Set the input timing to the screen. Assume always input 0. */
3326 if (!intel_sdvo_set_target_input(intel_sdvo
))
3329 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo
,
3330 &intel_sdvo
->pixel_clock_min
,
3331 &intel_sdvo
->pixel_clock_max
))
3334 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
3335 "clock range %dMHz - %dMHz, "
3336 "input 1: %c, input 2: %c, "
3337 "output 1: %c, output 2: %c\n",
3338 SDVO_NAME(intel_sdvo
),
3339 intel_sdvo
->caps
.vendor_id
, intel_sdvo
->caps
.device_id
,
3340 intel_sdvo
->caps
.device_rev_id
,
3341 intel_sdvo
->pixel_clock_min
/ 1000,
3342 intel_sdvo
->pixel_clock_max
/ 1000,
3343 (intel_sdvo
->caps
.sdvo_inputs_mask
& 0x1) ? 'Y' : 'N',
3344 (intel_sdvo
->caps
.sdvo_inputs_mask
& 0x2) ? 'Y' : 'N',
3345 /* check currently supported outputs */
3346 intel_sdvo
->caps
.output_flags
&
3347 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_RGB0
) ? 'Y' : 'N',
3348 intel_sdvo
->caps
.output_flags
&
3349 (SDVO_OUTPUT_TMDS1
| SDVO_OUTPUT_RGB1
) ? 'Y' : 'N');
3353 intel_sdvo_output_cleanup(intel_sdvo
);
3356 drm_encoder_cleanup(&intel_encoder
->base
);
3357 i2c_del_adapter(&intel_sdvo
->ddc
);
3359 intel_sdvo_unselect_i2c_bus(intel_sdvo
);