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_connector.h"
41 #include "intel_drv.h"
42 #include "intel_hdmi.h"
43 #include "intel_panel.h"
44 #include "intel_sdvo.h"
45 #include "intel_sdvo_regs.h"
47 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
48 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
49 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
50 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
52 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
55 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
56 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
57 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
58 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
59 #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
62 static const char * const tv_format_names[] = {
63 "NTSC_M" , "NTSC_J" , "NTSC_443",
64 "PAL_B" , "PAL_D" , "PAL_G" ,
65 "PAL_H" , "PAL_I" , "PAL_M" ,
66 "PAL_N" , "PAL_NC" , "PAL_60" ,
67 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
68 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
72 #define TV_FORMAT_NUM ARRAY_SIZE(tv_format_names)
75 struct intel_encoder base;
77 struct i2c_adapter *i2c;
80 struct i2c_adapter ddc;
82 /* Register for the SDVO device: SDVOB or SDVOC */
85 /* Active outputs controlled by this SDVO output */
86 u16 controlled_output;
89 * Capabilities of the SDVO device returned by
90 * intel_sdvo_get_capabilities()
92 struct intel_sdvo_caps caps;
94 /* Pixel clock limitations reported by the SDVO device, in kHz */
95 int pixel_clock_min, pixel_clock_max;
98 * For multiple function SDVO device,
99 * this is for current attached outputs.
104 * Hotplug activation bits for this device
110 bool has_hdmi_monitor;
113 /* DDC bus used by this SDVO encoder */
117 * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
122 struct intel_sdvo_connector {
123 struct intel_connector base;
125 /* Mark the type of connector */
128 /* This contains all current supported TV format */
129 u8 tv_format_supported[TV_FORMAT_NUM];
130 int format_supported_num;
131 struct drm_property *tv_format;
133 /* add the property for the SDVO-TV */
134 struct drm_property *left;
135 struct drm_property *right;
136 struct drm_property *top;
137 struct drm_property *bottom;
138 struct drm_property *hpos;
139 struct drm_property *vpos;
140 struct drm_property *contrast;
141 struct drm_property *saturation;
142 struct drm_property *hue;
143 struct drm_property *sharpness;
144 struct drm_property *flicker_filter;
145 struct drm_property *flicker_filter_adaptive;
146 struct drm_property *flicker_filter_2d;
147 struct drm_property *tv_chroma_filter;
148 struct drm_property *tv_luma_filter;
149 struct drm_property *dot_crawl;
151 /* add the property for the SDVO-TV/LVDS */
152 struct drm_property *brightness;
154 /* this is to get the range of margin.*/
155 u32 max_hscan, max_vscan;
158 * This is set if we treat the device as HDMI, instead of DVI.
163 struct intel_sdvo_connector_state {
164 /* base.base: tv.saturation/contrast/hue/brightness */
165 struct intel_digital_connector_state base;
168 unsigned overscan_h, overscan_v, hpos, vpos, sharpness;
169 unsigned flicker_filter, flicker_filter_2d, flicker_filter_adaptive;
170 unsigned chroma_filter, luma_filter, dot_crawl;
174 static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
176 return container_of(encoder, struct intel_sdvo, base);
179 static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector)
181 return to_sdvo(intel_attached_encoder(connector));
184 static struct intel_sdvo_connector *
185 to_intel_sdvo_connector(struct drm_connector *connector)
187 return container_of(connector, struct intel_sdvo_connector, base.base);
190 #define to_intel_sdvo_connector_state(conn_state) \
191 container_of((conn_state), struct intel_sdvo_connector_state, base.base)
194 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, u16 flags);
196 intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
197 struct intel_sdvo_connector *intel_sdvo_connector,
200 intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
201 struct intel_sdvo_connector *intel_sdvo_connector);
204 * Writes the SDVOB or SDVOC with the given value, but always writes both
205 * SDVOB and SDVOC to work around apparent hardware issues (according to
206 * comments in the BIOS).
208 static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
210 struct drm_device *dev = intel_sdvo->base.base.dev;
211 struct drm_i915_private *dev_priv = to_i915(dev);
212 u32 bval = val, cval = val;
215 if (HAS_PCH_SPLIT(dev_priv)) {
216 I915_WRITE(intel_sdvo->sdvo_reg, val);
217 POSTING_READ(intel_sdvo->sdvo_reg);
219 * HW workaround, need to write this twice for issue
220 * that may result in first write getting masked.
222 if (HAS_PCH_IBX(dev_priv)) {
223 I915_WRITE(intel_sdvo->sdvo_reg, val);
224 POSTING_READ(intel_sdvo->sdvo_reg);
229 if (intel_sdvo->port == PORT_B)
230 cval = I915_READ(GEN3_SDVOC);
232 bval = I915_READ(GEN3_SDVOB);
235 * Write the registers twice for luck. Sometimes,
236 * writing them only once doesn't appear to 'stick'.
237 * The BIOS does this too. Yay, magic
239 for (i = 0; i < 2; i++) {
240 I915_WRITE(GEN3_SDVOB, bval);
241 POSTING_READ(GEN3_SDVOB);
243 I915_WRITE(GEN3_SDVOC, cval);
244 POSTING_READ(GEN3_SDVOC);
248 static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
250 struct i2c_msg msgs[] = {
252 .addr = intel_sdvo->slave_addr,
258 .addr = intel_sdvo->slave_addr,
266 if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
269 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
273 #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
274 /** Mapping of command numbers to names, for debug output */
275 static const struct _sdvo_cmd_name {
278 } __attribute__ ((packed)) sdvo_cmd_names[] = {
279 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
280 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
281 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
282 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
283 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
284 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
323 /* Add the op code for SDVO enhancements */
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS),
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER),
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D),
355 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D),
356 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D),
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS),
359 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS),
360 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL),
361 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL),
362 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER),
363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER),
364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER),
365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER),
366 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER),
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER),
370 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
371 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
372 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
373 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
374 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
375 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
376 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
377 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
378 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
379 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
380 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
381 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
382 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
383 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
384 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
385 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
386 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
387 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
388 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
389 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
392 #define SDVO_NAME(svdo) ((svdo)->port == PORT_B ? "SDVOB" : "SDVOC")
394 static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
395 const void *args, int args_len)
399 char buffer[BUF_LEN];
401 #define BUF_PRINT(args...) \
402 pos += snprintf(buffer + pos, max_t(int, BUF_LEN - pos, 0), args)
405 for (i = 0; i < args_len; i++) {
406 BUF_PRINT("%02X ", ((u8 *)args)[i]);
411 for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
412 if (cmd == sdvo_cmd_names[i].cmd) {
413 BUF_PRINT("(%s)", sdvo_cmd_names[i].name);
417 if (i == ARRAY_SIZE(sdvo_cmd_names)) {
418 BUF_PRINT("(%02X)", cmd);
420 BUG_ON(pos >= BUF_LEN - 1);
424 DRM_DEBUG_KMS("%s: W: %02X %s\n", SDVO_NAME(intel_sdvo), cmd, buffer);
427 static const char * const cmd_status_names[] = {
433 "Target not specified",
434 "Scaling not supported"
437 static bool __intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
438 const void *args, int args_len,
442 struct i2c_msg *msgs;
445 /* Would be simpler to allocate both in one go ? */
446 buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
450 msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
456 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
458 for (i = 0; i < args_len; i++) {
459 msgs[i].addr = intel_sdvo->slave_addr;
462 msgs[i].buf = buf + 2 *i;
463 buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
464 buf[2*i + 1] = ((u8*)args)[i];
466 msgs[i].addr = intel_sdvo->slave_addr;
469 msgs[i].buf = buf + 2*i;
470 buf[2*i + 0] = SDVO_I2C_OPCODE;
473 /* the following two are to read the response */
474 status = SDVO_I2C_CMD_STATUS;
475 msgs[i+1].addr = intel_sdvo->slave_addr;
478 msgs[i+1].buf = &status;
480 msgs[i+2].addr = intel_sdvo->slave_addr;
481 msgs[i+2].flags = I2C_M_RD;
483 msgs[i+2].buf = &status;
486 ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
488 ret = __i2c_transfer(intel_sdvo->i2c, msgs, i+3);
490 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
495 /* failure in I2C transfer */
496 DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
506 static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
507 const void *args, int args_len)
509 return __intel_sdvo_write_cmd(intel_sdvo, cmd, args, args_len, true);
512 static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
513 void *response, int response_len)
515 u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
519 char buffer[BUF_LEN];
523 * The documentation states that all commands will be
524 * processed within 15µs, and that we need only poll
525 * the status byte a maximum of 3 times in order for the
526 * command to be complete.
528 * Check 5 times in case the hardware failed to read the docs.
530 * Also beware that the first response by many devices is to
531 * reply PENDING and stall for time. TVs are notorious for
532 * requiring longer than specified to complete their replies.
533 * Originally (in the DDX long ago), the delay was only ever 15ms
534 * with an additional delay of 30ms applied for TVs added later after
535 * many experiments. To accommodate both sets of delays, we do a
536 * sequence of slow checks if the device is falling behind and fails
537 * to reply within 5*15µs.
539 if (!intel_sdvo_read_byte(intel_sdvo,
544 while ((status == SDVO_CMD_STATUS_PENDING ||
545 status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
551 if (!intel_sdvo_read_byte(intel_sdvo,
557 #define BUF_PRINT(args...) \
558 pos += snprintf(buffer + pos, max_t(int, BUF_LEN - pos, 0), args)
560 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
561 BUF_PRINT("(%s)", cmd_status_names[status]);
563 BUF_PRINT("(??? %d)", status);
565 if (status != SDVO_CMD_STATUS_SUCCESS)
568 /* Read the command response */
569 for (i = 0; i < response_len; i++) {
570 if (!intel_sdvo_read_byte(intel_sdvo,
571 SDVO_I2C_RETURN_0 + i,
572 &((u8 *)response)[i]))
574 BUF_PRINT(" %02X", ((u8 *)response)[i]);
576 BUG_ON(pos >= BUF_LEN - 1);
580 DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo), buffer);
584 DRM_DEBUG_KMS("%s: R: ... failed\n", SDVO_NAME(intel_sdvo));
588 static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode *adjusted_mode)
590 if (adjusted_mode->crtc_clock >= 100000)
592 else if (adjusted_mode->crtc_clock >= 50000)
598 static bool __intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
601 /* This must be the immediately preceding write before the i2c xfer */
602 return __intel_sdvo_write_cmd(intel_sdvo,
603 SDVO_CMD_SET_CONTROL_BUS_SWITCH,
607 static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
609 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
612 return intel_sdvo_read_response(intel_sdvo, NULL, 0);
616 intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
618 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
621 return intel_sdvo_read_response(intel_sdvo, value, len);
624 static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
626 struct intel_sdvo_set_target_input_args targets = {0};
627 return intel_sdvo_set_value(intel_sdvo,
628 SDVO_CMD_SET_TARGET_INPUT,
629 &targets, sizeof(targets));
633 * Return whether each input is trained.
635 * This function is making an assumption about the layout of the response,
636 * which should be checked against the docs.
638 static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
640 struct intel_sdvo_get_trained_inputs_response response;
642 BUILD_BUG_ON(sizeof(response) != 1);
643 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
644 &response, sizeof(response)))
647 *input_1 = response.input0_trained;
648 *input_2 = response.input1_trained;
652 static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
655 return intel_sdvo_set_value(intel_sdvo,
656 SDVO_CMD_SET_ACTIVE_OUTPUTS,
657 &outputs, sizeof(outputs));
660 static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
663 return intel_sdvo_get_value(intel_sdvo,
664 SDVO_CMD_GET_ACTIVE_OUTPUTS,
665 outputs, sizeof(*outputs));
668 static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
671 u8 state = SDVO_ENCODER_STATE_ON;
674 case DRM_MODE_DPMS_ON:
675 state = SDVO_ENCODER_STATE_ON;
677 case DRM_MODE_DPMS_STANDBY:
678 state = SDVO_ENCODER_STATE_STANDBY;
680 case DRM_MODE_DPMS_SUSPEND:
681 state = SDVO_ENCODER_STATE_SUSPEND;
683 case DRM_MODE_DPMS_OFF:
684 state = SDVO_ENCODER_STATE_OFF;
688 return intel_sdvo_set_value(intel_sdvo,
689 SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
692 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
696 struct intel_sdvo_pixel_clock_range clocks;
698 BUILD_BUG_ON(sizeof(clocks) != 4);
699 if (!intel_sdvo_get_value(intel_sdvo,
700 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
701 &clocks, sizeof(clocks)))
704 /* Convert the values from units of 10 kHz to kHz. */
705 *clock_min = clocks.min * 10;
706 *clock_max = clocks.max * 10;
710 static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
713 return intel_sdvo_set_value(intel_sdvo,
714 SDVO_CMD_SET_TARGET_OUTPUT,
715 &outputs, sizeof(outputs));
718 static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
719 struct intel_sdvo_dtd *dtd)
721 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
722 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
725 static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
726 struct intel_sdvo_dtd *dtd)
728 return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
729 intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
732 static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
733 struct intel_sdvo_dtd *dtd)
735 return intel_sdvo_set_timing(intel_sdvo,
736 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
739 static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
740 struct intel_sdvo_dtd *dtd)
742 return intel_sdvo_set_timing(intel_sdvo,
743 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
746 static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
747 struct intel_sdvo_dtd *dtd)
749 return intel_sdvo_get_timing(intel_sdvo,
750 SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
754 intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
755 struct intel_sdvo_connector *intel_sdvo_connector,
760 struct intel_sdvo_preferred_input_timing_args args;
762 memset(&args, 0, sizeof(args));
765 args.height = height;
768 if (IS_LVDS(intel_sdvo_connector)) {
769 const struct drm_display_mode *fixed_mode =
770 intel_sdvo_connector->base.panel.fixed_mode;
772 if (fixed_mode->hdisplay != width ||
773 fixed_mode->vdisplay != height)
777 return intel_sdvo_set_value(intel_sdvo,
778 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
779 &args, sizeof(args));
782 static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
783 struct intel_sdvo_dtd *dtd)
785 BUILD_BUG_ON(sizeof(dtd->part1) != 8);
786 BUILD_BUG_ON(sizeof(dtd->part2) != 8);
787 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
788 &dtd->part1, sizeof(dtd->part1)) &&
789 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
790 &dtd->part2, sizeof(dtd->part2));
793 static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
795 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
798 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
799 const struct drm_display_mode *mode)
802 u16 h_blank_len, h_sync_len, v_blank_len, v_sync_len;
803 u16 h_sync_offset, v_sync_offset;
806 memset(dtd, 0, sizeof(*dtd));
808 width = mode->hdisplay;
809 height = mode->vdisplay;
811 /* do some mode translations */
812 h_blank_len = mode->htotal - mode->hdisplay;
813 h_sync_len = mode->hsync_end - mode->hsync_start;
815 v_blank_len = mode->vtotal - mode->vdisplay;
816 v_sync_len = mode->vsync_end - mode->vsync_start;
818 h_sync_offset = mode->hsync_start - mode->hdisplay;
819 v_sync_offset = mode->vsync_start - mode->vdisplay;
821 mode_clock = mode->clock;
823 dtd->part1.clock = mode_clock;
825 dtd->part1.h_active = width & 0xff;
826 dtd->part1.h_blank = h_blank_len & 0xff;
827 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
828 ((h_blank_len >> 8) & 0xf);
829 dtd->part1.v_active = height & 0xff;
830 dtd->part1.v_blank = v_blank_len & 0xff;
831 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
832 ((v_blank_len >> 8) & 0xf);
834 dtd->part2.h_sync_off = h_sync_offset & 0xff;
835 dtd->part2.h_sync_width = h_sync_len & 0xff;
836 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
838 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
839 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
840 ((v_sync_len & 0x30) >> 4);
842 dtd->part2.dtd_flags = 0x18;
843 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
844 dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
845 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
846 dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
847 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
848 dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
850 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
853 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode *pmode,
854 const struct intel_sdvo_dtd *dtd)
856 struct drm_display_mode mode = {};
858 mode.hdisplay = dtd->part1.h_active;
859 mode.hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
860 mode.hsync_start = mode.hdisplay + dtd->part2.h_sync_off;
861 mode.hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
862 mode.hsync_end = mode.hsync_start + dtd->part2.h_sync_width;
863 mode.hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
864 mode.htotal = mode.hdisplay + dtd->part1.h_blank;
865 mode.htotal += (dtd->part1.h_high & 0xf) << 8;
867 mode.vdisplay = dtd->part1.v_active;
868 mode.vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
869 mode.vsync_start = mode.vdisplay;
870 mode.vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
871 mode.vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
872 mode.vsync_start += dtd->part2.v_sync_off_high & 0xc0;
873 mode.vsync_end = mode.vsync_start +
874 (dtd->part2.v_sync_off_width & 0xf);
875 mode.vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
876 mode.vtotal = mode.vdisplay + dtd->part1.v_blank;
877 mode.vtotal += (dtd->part1.v_high & 0xf) << 8;
879 mode.clock = dtd->part1.clock * 10;
881 if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
882 mode.flags |= DRM_MODE_FLAG_INTERLACE;
883 if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
884 mode.flags |= DRM_MODE_FLAG_PHSYNC;
886 mode.flags |= DRM_MODE_FLAG_NHSYNC;
887 if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
888 mode.flags |= DRM_MODE_FLAG_PVSYNC;
890 mode.flags |= DRM_MODE_FLAG_NVSYNC;
892 drm_mode_set_crtcinfo(&mode, 0);
894 drm_mode_copy(pmode, &mode);
897 static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
899 struct intel_sdvo_encode encode;
901 BUILD_BUG_ON(sizeof(encode) != 2);
902 return intel_sdvo_get_value(intel_sdvo,
903 SDVO_CMD_GET_SUPP_ENCODE,
904 &encode, sizeof(encode));
907 static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
910 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
913 static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
916 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
920 static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
929 intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
931 for (i = 0; i <= av_split; i++) {
932 set_buf_index[0] = i; set_buf_index[1] = 0;
933 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
935 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
936 intel_sdvo_read_response(encoder, &buf_size, 1);
939 for (j = 0; j <= buf_size; j += 8) {
940 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
942 intel_sdvo_read_response(encoder, pos, 8);
949 static bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
950 unsigned int if_index, u8 tx_rate,
951 const u8 *data, unsigned int length)
953 u8 set_buf_index[2] = { if_index, 0 };
954 u8 hbuf_size, tmp[8];
957 if (!intel_sdvo_set_value(intel_sdvo,
958 SDVO_CMD_SET_HBUF_INDEX,
962 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
966 /* Buffer size is 0 based, hooray! */
969 DRM_DEBUG_KMS("writing sdvo hbuf: %i, hbuf_size %i, hbuf_size: %i\n",
970 if_index, length, hbuf_size);
972 for (i = 0; i < hbuf_size; i += 8) {
975 memcpy(tmp, data + i, min_t(unsigned, 8, length - i));
977 if (!intel_sdvo_set_value(intel_sdvo,
978 SDVO_CMD_SET_HBUF_DATA,
983 return intel_sdvo_set_value(intel_sdvo,
984 SDVO_CMD_SET_HBUF_TXRATE,
988 static ssize_t intel_sdvo_read_infoframe(struct intel_sdvo *intel_sdvo,
989 unsigned int if_index,
990 u8 *data, unsigned int length)
992 u8 set_buf_index[2] = { if_index, 0 };
993 u8 hbuf_size, tx_rate, av_split;
996 if (!intel_sdvo_get_value(intel_sdvo,
997 SDVO_CMD_GET_HBUF_AV_SPLIT,
1001 if (av_split < if_index)
1004 if (!intel_sdvo_get_value(intel_sdvo,
1005 SDVO_CMD_GET_HBUF_TXRATE,
1009 if (tx_rate == SDVO_HBUF_TX_DISABLED)
1012 if (!intel_sdvo_set_value(intel_sdvo,
1013 SDVO_CMD_SET_HBUF_INDEX,
1017 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
1021 /* Buffer size is 0 based, hooray! */
1024 DRM_DEBUG_KMS("reading sdvo hbuf: %i, hbuf_size %i, hbuf_size: %i\n",
1025 if_index, length, hbuf_size);
1027 hbuf_size = min_t(unsigned int, length, hbuf_size);
1029 for (i = 0; i < hbuf_size; i += 8) {
1030 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HBUF_DATA, NULL, 0))
1032 if (!intel_sdvo_read_response(intel_sdvo, &data[i],
1033 min_t(unsigned int, 8, hbuf_size - i)))
1040 static bool intel_sdvo_compute_avi_infoframe(struct intel_sdvo *intel_sdvo,
1041 struct intel_crtc_state *crtc_state,
1042 struct drm_connector_state *conn_state)
1044 struct hdmi_avi_infoframe *frame = &crtc_state->infoframes.avi.avi;
1045 const struct drm_display_mode *adjusted_mode =
1046 &crtc_state->base.adjusted_mode;
1049 if (!crtc_state->has_hdmi_sink)
1052 crtc_state->infoframes.enable |=
1053 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1055 ret = drm_hdmi_avi_infoframe_from_display_mode(frame,
1056 conn_state->connector,
1061 drm_hdmi_avi_infoframe_quant_range(frame,
1062 conn_state->connector,
1064 crtc_state->limited_color_range ?
1065 HDMI_QUANTIZATION_RANGE_LIMITED :
1066 HDMI_QUANTIZATION_RANGE_FULL);
1068 ret = hdmi_avi_infoframe_check(frame);
1075 static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1076 const struct intel_crtc_state *crtc_state)
1078 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1079 const union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1082 if ((crtc_state->infoframes.enable &
1083 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI)) == 0)
1086 if (WARN_ON(frame->any.type != HDMI_INFOFRAME_TYPE_AVI))
1089 len = hdmi_infoframe_pack_only(frame, sdvo_data, sizeof(sdvo_data));
1090 if (WARN_ON(len < 0))
1093 return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1095 sdvo_data, sizeof(sdvo_data));
1098 static void intel_sdvo_get_avi_infoframe(struct intel_sdvo *intel_sdvo,
1099 struct intel_crtc_state *crtc_state)
1101 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1102 union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1106 if (!crtc_state->has_hdmi_sink)
1109 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1110 sdvo_data, sizeof(sdvo_data));
1112 DRM_DEBUG_KMS("failed to read AVI infoframe\n");
1114 } else if (len == 0) {
1118 crtc_state->infoframes.enable |=
1119 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1121 ret = hdmi_infoframe_unpack(frame, sdvo_data, sizeof(sdvo_data));
1123 DRM_DEBUG_KMS("Failed to unpack AVI infoframe\n");
1127 if (frame->any.type != HDMI_INFOFRAME_TYPE_AVI)
1128 DRM_DEBUG_KMS("Found the wrong infoframe type 0x%x (expected 0x%02x)\n",
1129 frame->any.type, HDMI_INFOFRAME_TYPE_AVI);
1132 static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo,
1133 const struct drm_connector_state *conn_state)
1135 struct intel_sdvo_tv_format format;
1138 format_map = 1 << conn_state->tv.mode;
1139 memset(&format, 0, sizeof(format));
1140 memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1142 BUILD_BUG_ON(sizeof(format) != 6);
1143 return intel_sdvo_set_value(intel_sdvo,
1144 SDVO_CMD_SET_TV_FORMAT,
1145 &format, sizeof(format));
1149 intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1150 const struct drm_display_mode *mode)
1152 struct intel_sdvo_dtd output_dtd;
1154 if (!intel_sdvo_set_target_output(intel_sdvo,
1155 intel_sdvo->attached_output))
1158 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1159 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1166 * Asks the sdvo controller for the preferred input mode given the output mode.
1167 * Unfortunately we have to set up the full output mode to do that.
1170 intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
1171 struct intel_sdvo_connector *intel_sdvo_connector,
1172 const struct drm_display_mode *mode,
1173 struct drm_display_mode *adjusted_mode)
1175 struct intel_sdvo_dtd input_dtd;
1177 /* Reset the input timing to the screen. Assume always input 0. */
1178 if (!intel_sdvo_set_target_input(intel_sdvo))
1181 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1182 intel_sdvo_connector,
1188 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1192 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1193 intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1198 static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_state *pipe_config)
1200 unsigned dotclock = pipe_config->port_clock;
1201 struct dpll *clock = &pipe_config->dpll;
1204 * SDVO TV has fixed PLL values depend on its clock range,
1205 * this mirrors vbios setting.
1207 if (dotclock >= 100000 && dotclock < 140500) {
1213 } else if (dotclock >= 140500 && dotclock <= 200000) {
1220 WARN(1, "SDVO TV clock out of range: %i\n", dotclock);
1223 pipe_config->clock_set = true;
1226 static int intel_sdvo_compute_config(struct intel_encoder *encoder,
1227 struct intel_crtc_state *pipe_config,
1228 struct drm_connector_state *conn_state)
1230 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1231 struct intel_sdvo_connector_state *intel_sdvo_state =
1232 to_intel_sdvo_connector_state(conn_state);
1233 struct intel_sdvo_connector *intel_sdvo_connector =
1234 to_intel_sdvo_connector(conn_state->connector);
1235 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1236 struct drm_display_mode *mode = &pipe_config->base.mode;
1238 DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1239 pipe_config->pipe_bpp = 8*3;
1240 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
1242 if (HAS_PCH_SPLIT(to_i915(encoder->base.dev)))
1243 pipe_config->has_pch_encoder = true;
1246 * We need to construct preferred input timings based on our
1247 * output timings. To do that, we have to set the output
1248 * timings, even though this isn't really the right place in
1249 * the sequence to do it. Oh well.
1251 if (IS_TV(intel_sdvo_connector)) {
1252 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1255 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1256 intel_sdvo_connector,
1259 pipe_config->sdvo_tv_clock = true;
1260 } else if (IS_LVDS(intel_sdvo_connector)) {
1261 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1262 intel_sdvo_connector->base.panel.fixed_mode))
1265 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1266 intel_sdvo_connector,
1271 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
1275 * Make the CRTC code factor in the SDVO pixel multiplier. The
1276 * SDVO device will factor out the multiplier during mode_set.
1278 pipe_config->pixel_multiplier =
1279 intel_sdvo_get_pixel_multiplier(adjusted_mode);
1281 if (intel_sdvo_state->base.force_audio != HDMI_AUDIO_OFF_DVI)
1282 pipe_config->has_hdmi_sink = intel_sdvo->has_hdmi_monitor;
1284 if (intel_sdvo_state->base.force_audio == HDMI_AUDIO_ON ||
1285 (intel_sdvo_state->base.force_audio == HDMI_AUDIO_AUTO && intel_sdvo->has_hdmi_audio))
1286 pipe_config->has_audio = true;
1288 if (intel_sdvo_state->base.broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
1290 * See CEA-861-E - 5.1 Default Encoding Parameters
1292 * FIXME: This bit is only valid when using TMDS encoding and 8
1293 * bit per color mode.
1295 if (pipe_config->has_hdmi_sink &&
1296 drm_match_cea_mode(adjusted_mode) > 1)
1297 pipe_config->limited_color_range = true;
1299 if (pipe_config->has_hdmi_sink &&
1300 intel_sdvo_state->base.broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED)
1301 pipe_config->limited_color_range = true;
1304 /* Clock computation needs to happen after pixel multiplier. */
1305 if (IS_TV(intel_sdvo_connector))
1306 i9xx_adjust_sdvo_tv_clock(pipe_config);
1308 /* Set user selected PAR to incoming mode's member */
1309 if (intel_sdvo_connector->is_hdmi)
1310 adjusted_mode->picture_aspect_ratio = conn_state->picture_aspect_ratio;
1312 if (!intel_sdvo_compute_avi_infoframe(intel_sdvo,
1313 pipe_config, conn_state)) {
1314 DRM_DEBUG_KMS("bad AVI infoframe\n");
1321 #define UPDATE_PROPERTY(input, NAME) \
1324 intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_##NAME, &val, sizeof(val)); \
1327 static void intel_sdvo_update_props(struct intel_sdvo *intel_sdvo,
1328 const struct intel_sdvo_connector_state *sdvo_state)
1330 const struct drm_connector_state *conn_state = &sdvo_state->base.base;
1331 struct intel_sdvo_connector *intel_sdvo_conn =
1332 to_intel_sdvo_connector(conn_state->connector);
1335 if (intel_sdvo_conn->left)
1336 UPDATE_PROPERTY(sdvo_state->tv.overscan_h, OVERSCAN_H);
1338 if (intel_sdvo_conn->top)
1339 UPDATE_PROPERTY(sdvo_state->tv.overscan_v, OVERSCAN_V);
1341 if (intel_sdvo_conn->hpos)
1342 UPDATE_PROPERTY(sdvo_state->tv.hpos, HPOS);
1344 if (intel_sdvo_conn->vpos)
1345 UPDATE_PROPERTY(sdvo_state->tv.vpos, VPOS);
1347 if (intel_sdvo_conn->saturation)
1348 UPDATE_PROPERTY(conn_state->tv.saturation, SATURATION);
1350 if (intel_sdvo_conn->contrast)
1351 UPDATE_PROPERTY(conn_state->tv.contrast, CONTRAST);
1353 if (intel_sdvo_conn->hue)
1354 UPDATE_PROPERTY(conn_state->tv.hue, HUE);
1356 if (intel_sdvo_conn->brightness)
1357 UPDATE_PROPERTY(conn_state->tv.brightness, BRIGHTNESS);
1359 if (intel_sdvo_conn->sharpness)
1360 UPDATE_PROPERTY(sdvo_state->tv.sharpness, SHARPNESS);
1362 if (intel_sdvo_conn->flicker_filter)
1363 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter, FLICKER_FILTER);
1365 if (intel_sdvo_conn->flicker_filter_2d)
1366 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_2d, FLICKER_FILTER_2D);
1368 if (intel_sdvo_conn->flicker_filter_adaptive)
1369 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
1371 if (intel_sdvo_conn->tv_chroma_filter)
1372 UPDATE_PROPERTY(sdvo_state->tv.chroma_filter, TV_CHROMA_FILTER);
1374 if (intel_sdvo_conn->tv_luma_filter)
1375 UPDATE_PROPERTY(sdvo_state->tv.luma_filter, TV_LUMA_FILTER);
1377 if (intel_sdvo_conn->dot_crawl)
1378 UPDATE_PROPERTY(sdvo_state->tv.dot_crawl, DOT_CRAWL);
1380 #undef UPDATE_PROPERTY
1383 static void intel_sdvo_pre_enable(struct intel_encoder *intel_encoder,
1384 const struct intel_crtc_state *crtc_state,
1385 const struct drm_connector_state *conn_state)
1387 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
1388 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1389 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
1390 const struct intel_sdvo_connector_state *sdvo_state =
1391 to_intel_sdvo_connector_state(conn_state);
1392 const struct intel_sdvo_connector *intel_sdvo_connector =
1393 to_intel_sdvo_connector(conn_state->connector);
1394 const struct drm_display_mode *mode = &crtc_state->base.mode;
1395 struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
1397 struct intel_sdvo_in_out_map in_out;
1398 struct intel_sdvo_dtd input_dtd, output_dtd;
1401 intel_sdvo_update_props(intel_sdvo, sdvo_state);
1404 * First, set the input mapping for the first input to our controlled
1405 * output. This is only correct if we're a single-input device, in
1406 * which case the first input is the output from the appropriate SDVO
1407 * channel on the motherboard. In a two-input device, the first input
1408 * will be SDVOB and the second SDVOC.
1410 in_out.in0 = intel_sdvo->attached_output;
1413 intel_sdvo_set_value(intel_sdvo,
1414 SDVO_CMD_SET_IN_OUT_MAP,
1415 &in_out, sizeof(in_out));
1417 /* Set the output timings to the screen */
1418 if (!intel_sdvo_set_target_output(intel_sdvo,
1419 intel_sdvo->attached_output))
1422 /* lvds has a special fixed output timing. */
1423 if (IS_LVDS(intel_sdvo_connector))
1424 intel_sdvo_get_dtd_from_mode(&output_dtd,
1425 intel_sdvo_connector->base.panel.fixed_mode);
1427 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1428 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1429 DRM_INFO("Setting output timings on %s failed\n",
1430 SDVO_NAME(intel_sdvo));
1432 /* Set the input timing to the screen. Assume always input 0. */
1433 if (!intel_sdvo_set_target_input(intel_sdvo))
1436 if (crtc_state->has_hdmi_sink) {
1437 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
1438 intel_sdvo_set_colorimetry(intel_sdvo,
1439 SDVO_COLORIMETRY_RGB256);
1440 intel_sdvo_set_avi_infoframe(intel_sdvo, crtc_state);
1442 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
1444 if (IS_TV(intel_sdvo_connector) &&
1445 !intel_sdvo_set_tv_format(intel_sdvo, conn_state))
1448 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1450 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector))
1451 input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1452 if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1453 DRM_INFO("Setting input timings on %s failed\n",
1454 SDVO_NAME(intel_sdvo));
1456 switch (crtc_state->pixel_multiplier) {
1458 WARN(1, "unknown pixel multiplier specified\n");
1460 case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1461 case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1462 case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1464 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1467 /* Set the SDVO control regs. */
1468 if (INTEL_GEN(dev_priv) >= 4) {
1469 /* The real mode polarity is set by the SDVO commands, using
1470 * struct intel_sdvo_dtd. */
1471 sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
1472 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
1473 sdvox |= HDMI_COLOR_RANGE_16_235;
1474 if (INTEL_GEN(dev_priv) < 5)
1475 sdvox |= SDVO_BORDER_ENABLE;
1477 sdvox = I915_READ(intel_sdvo->sdvo_reg);
1478 if (intel_sdvo->port == PORT_B)
1479 sdvox &= SDVOB_PRESERVE_MASK;
1481 sdvox &= SDVOC_PRESERVE_MASK;
1482 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1485 if (HAS_PCH_CPT(dev_priv))
1486 sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
1488 sdvox |= SDVO_PIPE_SEL(crtc->pipe);
1490 if (crtc_state->has_audio) {
1491 WARN_ON_ONCE(INTEL_GEN(dev_priv) < 4);
1492 sdvox |= SDVO_AUDIO_ENABLE;
1495 if (INTEL_GEN(dev_priv) >= 4) {
1496 /* done in crtc_mode_set as the dpll_md reg must be written early */
1497 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
1498 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
1499 /* done in crtc_mode_set as it lives inside the dpll register */
1501 sdvox |= (crtc_state->pixel_multiplier - 1)
1502 << SDVO_PORT_MULTIPLY_SHIFT;
1505 if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
1506 INTEL_GEN(dev_priv) < 5)
1507 sdvox |= SDVO_STALL_SELECT;
1508 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1511 static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1513 struct intel_sdvo_connector *intel_sdvo_connector =
1514 to_intel_sdvo_connector(&connector->base);
1515 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
1516 u16 active_outputs = 0;
1518 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1520 return active_outputs & intel_sdvo_connector->output_flag;
1523 bool intel_sdvo_port_enabled(struct drm_i915_private *dev_priv,
1524 i915_reg_t sdvo_reg, enum pipe *pipe)
1528 val = I915_READ(sdvo_reg);
1530 /* asserts want to know the pipe even if the port is disabled */
1531 if (HAS_PCH_CPT(dev_priv))
1532 *pipe = (val & SDVO_PIPE_SEL_MASK_CPT) >> SDVO_PIPE_SEL_SHIFT_CPT;
1533 else if (IS_CHERRYVIEW(dev_priv))
1534 *pipe = (val & SDVO_PIPE_SEL_MASK_CHV) >> SDVO_PIPE_SEL_SHIFT_CHV;
1536 *pipe = (val & SDVO_PIPE_SEL_MASK) >> SDVO_PIPE_SEL_SHIFT;
1538 return val & SDVO_ENABLE;
1541 static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1544 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1545 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1546 u16 active_outputs = 0;
1549 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1551 ret = intel_sdvo_port_enabled(dev_priv, intel_sdvo->sdvo_reg, pipe);
1553 return ret || active_outputs;
1556 static void intel_sdvo_get_config(struct intel_encoder *encoder,
1557 struct intel_crtc_state *pipe_config)
1559 struct drm_device *dev = encoder->base.dev;
1560 struct drm_i915_private *dev_priv = to_i915(dev);
1561 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1562 struct intel_sdvo_dtd dtd;
1563 int encoder_pixel_multiplier = 0;
1565 u32 flags = 0, sdvox;
1569 pipe_config->output_types |= BIT(INTEL_OUTPUT_SDVO);
1571 sdvox = I915_READ(intel_sdvo->sdvo_reg);
1573 ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
1576 * Some sdvo encoders are not spec compliant and don't
1577 * implement the mandatory get_timings function.
1579 DRM_DEBUG_DRIVER("failed to retrieve SDVO DTD\n");
1580 pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
1582 if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1583 flags |= DRM_MODE_FLAG_PHSYNC;
1585 flags |= DRM_MODE_FLAG_NHSYNC;
1587 if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1588 flags |= DRM_MODE_FLAG_PVSYNC;
1590 flags |= DRM_MODE_FLAG_NVSYNC;
1593 pipe_config->base.adjusted_mode.flags |= flags;
1596 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1597 * the sdvo port register, on all other platforms it is part of the dpll
1598 * state. Since the general pipe state readout happens before the
1599 * encoder->get_config we so already have a valid pixel multplier on all
1602 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
1603 pipe_config->pixel_multiplier =
1604 ((sdvox & SDVO_PORT_MULTIPLY_MASK)
1605 >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
1608 dotclock = pipe_config->port_clock;
1610 if (pipe_config->pixel_multiplier)
1611 dotclock /= pipe_config->pixel_multiplier;
1613 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
1615 /* Cross check the port pixel multiplier with the sdvo encoder state. */
1616 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
1619 case SDVO_CLOCK_RATE_MULT_1X:
1620 encoder_pixel_multiplier = 1;
1622 case SDVO_CLOCK_RATE_MULT_2X:
1623 encoder_pixel_multiplier = 2;
1625 case SDVO_CLOCK_RATE_MULT_4X:
1626 encoder_pixel_multiplier = 4;
1631 WARN(encoder_pixel_multiplier != pipe_config->pixel_multiplier,
1632 "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1633 pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1635 if (sdvox & HDMI_COLOR_RANGE_16_235)
1636 pipe_config->limited_color_range = true;
1638 if (sdvox & SDVO_AUDIO_ENABLE)
1639 pipe_config->has_audio = true;
1641 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE,
1643 if (val == SDVO_ENCODE_HDMI)
1644 pipe_config->has_hdmi_sink = true;
1647 intel_sdvo_get_avi_infoframe(intel_sdvo, pipe_config);
1650 static void intel_disable_sdvo(struct intel_encoder *encoder,
1651 const struct intel_crtc_state *old_crtc_state,
1652 const struct drm_connector_state *conn_state)
1654 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1655 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1656 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1659 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1661 intel_sdvo_set_encoder_power_state(intel_sdvo,
1664 temp = I915_READ(intel_sdvo->sdvo_reg);
1666 temp &= ~SDVO_ENABLE;
1667 intel_sdvo_write_sdvox(intel_sdvo, temp);
1670 * HW workaround for IBX, we need to move the port
1671 * to transcoder A after disabling it to allow the
1672 * matching DP port to be enabled on transcoder A.
1674 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1676 * We get CPU/PCH FIFO underruns on the other pipe when
1677 * doing the workaround. Sweep them under the rug.
1679 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1680 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1682 temp &= ~SDVO_PIPE_SEL_MASK;
1683 temp |= SDVO_ENABLE | SDVO_PIPE_SEL(PIPE_A);
1684 intel_sdvo_write_sdvox(intel_sdvo, temp);
1686 temp &= ~SDVO_ENABLE;
1687 intel_sdvo_write_sdvox(intel_sdvo, temp);
1689 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1690 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1691 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1695 static void pch_disable_sdvo(struct intel_encoder *encoder,
1696 const struct intel_crtc_state *old_crtc_state,
1697 const struct drm_connector_state *old_conn_state)
1701 static void pch_post_disable_sdvo(struct intel_encoder *encoder,
1702 const struct intel_crtc_state *old_crtc_state,
1703 const struct drm_connector_state *old_conn_state)
1705 intel_disable_sdvo(encoder, old_crtc_state, old_conn_state);
1708 static void intel_enable_sdvo(struct intel_encoder *encoder,
1709 const struct intel_crtc_state *pipe_config,
1710 const struct drm_connector_state *conn_state)
1712 struct drm_device *dev = encoder->base.dev;
1713 struct drm_i915_private *dev_priv = to_i915(dev);
1714 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1715 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
1717 bool input1, input2;
1721 temp = I915_READ(intel_sdvo->sdvo_reg);
1722 temp |= SDVO_ENABLE;
1723 intel_sdvo_write_sdvox(intel_sdvo, temp);
1725 for (i = 0; i < 2; i++)
1726 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
1728 success = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1730 * Warn if the device reported failure to sync.
1732 * A lot of SDVO devices fail to notify of sync, but it's
1733 * a given it the status is a success, we succeeded.
1735 if (success && !input1) {
1736 DRM_DEBUG_KMS("First %s output reported failure to "
1737 "sync\n", SDVO_NAME(intel_sdvo));
1741 intel_sdvo_set_encoder_power_state(intel_sdvo,
1743 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1746 static enum drm_mode_status
1747 intel_sdvo_mode_valid(struct drm_connector *connector,
1748 struct drm_display_mode *mode)
1750 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1751 struct intel_sdvo_connector *intel_sdvo_connector =
1752 to_intel_sdvo_connector(connector);
1753 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1755 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1756 return MODE_NO_DBLESCAN;
1758 if (intel_sdvo->pixel_clock_min > mode->clock)
1759 return MODE_CLOCK_LOW;
1761 if (intel_sdvo->pixel_clock_max < mode->clock)
1762 return MODE_CLOCK_HIGH;
1764 if (mode->clock > max_dotclk)
1765 return MODE_CLOCK_HIGH;
1767 if (IS_LVDS(intel_sdvo_connector)) {
1768 const struct drm_display_mode *fixed_mode =
1769 intel_sdvo_connector->base.panel.fixed_mode;
1771 if (mode->hdisplay > fixed_mode->hdisplay)
1774 if (mode->vdisplay > fixed_mode->vdisplay)
1781 static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1783 BUILD_BUG_ON(sizeof(*caps) != 8);
1784 if (!intel_sdvo_get_value(intel_sdvo,
1785 SDVO_CMD_GET_DEVICE_CAPS,
1786 caps, sizeof(*caps)))
1789 DRM_DEBUG_KMS("SDVO capabilities:\n"
1792 " device_rev_id: %d\n"
1793 " sdvo_version_major: %d\n"
1794 " sdvo_version_minor: %d\n"
1795 " sdvo_inputs_mask: %d\n"
1796 " smooth_scaling: %d\n"
1797 " sharp_scaling: %d\n"
1799 " down_scaling: %d\n"
1800 " stall_support: %d\n"
1801 " output_flags: %d\n",
1804 caps->device_rev_id,
1805 caps->sdvo_version_major,
1806 caps->sdvo_version_minor,
1807 caps->sdvo_inputs_mask,
1808 caps->smooth_scaling,
1809 caps->sharp_scaling,
1812 caps->stall_support,
1813 caps->output_flags);
1818 static u16 intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1820 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1823 if (!I915_HAS_HOTPLUG(dev_priv))
1827 * HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1830 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
1833 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1834 &hotplug, sizeof(hotplug)))
1840 static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1842 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1844 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
1845 &intel_sdvo->hotplug_active, 2);
1848 static bool intel_sdvo_hotplug(struct intel_encoder *encoder,
1849 struct intel_connector *connector)
1851 intel_sdvo_enable_hotplug(encoder);
1853 return intel_encoder_hotplug(encoder, connector);
1857 intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
1859 /* Is there more than one type of output? */
1860 return hweight16(intel_sdvo->caps.output_flags) > 1;
1863 static struct edid *
1864 intel_sdvo_get_edid(struct drm_connector *connector)
1866 struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
1867 return drm_get_edid(connector, &sdvo->ddc);
1870 /* Mac mini hack -- use the same DDC as the analog connector */
1871 static struct edid *
1872 intel_sdvo_get_analog_edid(struct drm_connector *connector)
1874 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1876 return drm_get_edid(connector,
1877 intel_gmbus_get_adapter(dev_priv,
1878 dev_priv->vbt.crt_ddc_pin));
1881 static enum drm_connector_status
1882 intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
1884 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1885 struct intel_sdvo_connector *intel_sdvo_connector =
1886 to_intel_sdvo_connector(connector);
1887 enum drm_connector_status status;
1890 edid = intel_sdvo_get_edid(connector);
1892 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
1893 u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
1896 * Don't use the 1 as the argument of DDC bus switch to get
1897 * the EDID. It is used for SDVO SPD ROM.
1899 for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
1900 intel_sdvo->ddc_bus = ddc;
1901 edid = intel_sdvo_get_edid(connector);
1906 * If we found the EDID on the other bus,
1907 * assume that is the correct DDC bus.
1910 intel_sdvo->ddc_bus = saved_ddc;
1914 * When there is no edid and no monitor is connected with VGA
1915 * port, try to use the CRT ddc to read the EDID for DVI-connector.
1918 edid = intel_sdvo_get_analog_edid(connector);
1920 status = connector_status_unknown;
1922 /* DDC bus is shared, match EDID to connector type */
1923 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
1924 status = connector_status_connected;
1925 if (intel_sdvo_connector->is_hdmi) {
1926 intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
1927 intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
1930 status = connector_status_disconnected;
1938 intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
1941 bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
1942 bool connector_is_digital = !!IS_DIGITAL(sdvo);
1944 DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
1945 connector_is_digital, monitor_is_digital);
1946 return connector_is_digital == monitor_is_digital;
1949 static enum drm_connector_status
1950 intel_sdvo_detect(struct drm_connector *connector, bool force)
1953 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1954 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1955 enum drm_connector_status ret;
1957 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1958 connector->base.id, connector->name);
1960 if (!intel_sdvo_get_value(intel_sdvo,
1961 SDVO_CMD_GET_ATTACHED_DISPLAYS,
1963 return connector_status_unknown;
1965 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
1966 response & 0xff, response >> 8,
1967 intel_sdvo_connector->output_flag);
1970 return connector_status_disconnected;
1972 intel_sdvo->attached_output = response;
1974 intel_sdvo->has_hdmi_monitor = false;
1975 intel_sdvo->has_hdmi_audio = false;
1977 if ((intel_sdvo_connector->output_flag & response) == 0)
1978 ret = connector_status_disconnected;
1979 else if (IS_TMDS(intel_sdvo_connector))
1980 ret = intel_sdvo_tmds_sink_detect(connector);
1984 /* if we have an edid check it matches the connection */
1985 edid = intel_sdvo_get_edid(connector);
1987 edid = intel_sdvo_get_analog_edid(connector);
1989 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
1991 ret = connector_status_connected;
1993 ret = connector_status_disconnected;
1997 ret = connector_status_connected;
2003 static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
2007 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2008 connector->base.id, connector->name);
2010 /* set the bus switch and get the modes */
2011 edid = intel_sdvo_get_edid(connector);
2014 * Mac mini hack. On this device, the DVI-I connector shares one DDC
2015 * link between analog and digital outputs. So, if the regular SDVO
2016 * DDC fails, check to see if the analog output is disconnected, in
2017 * which case we'll look there for the digital DDC data.
2020 edid = intel_sdvo_get_analog_edid(connector);
2023 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
2025 drm_connector_update_edid_property(connector, edid);
2026 drm_add_edid_modes(connector, edid);
2034 * Set of SDVO TV modes.
2035 * Note! This is in reply order (see loop in get_tv_modes).
2036 * XXX: all 60Hz refresh?
2038 static const struct drm_display_mode sdvo_tv_modes[] = {
2039 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
2040 416, 0, 200, 201, 232, 233, 0,
2041 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2042 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
2043 416, 0, 240, 241, 272, 273, 0,
2044 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2045 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
2046 496, 0, 300, 301, 332, 333, 0,
2047 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2048 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
2049 736, 0, 350, 351, 382, 383, 0,
2050 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2051 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
2052 736, 0, 400, 401, 432, 433, 0,
2053 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2054 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
2055 736, 0, 480, 481, 512, 513, 0,
2056 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2057 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
2058 800, 0, 480, 481, 512, 513, 0,
2059 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2060 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
2061 800, 0, 576, 577, 608, 609, 0,
2062 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2063 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
2064 816, 0, 350, 351, 382, 383, 0,
2065 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2066 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
2067 816, 0, 400, 401, 432, 433, 0,
2068 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2069 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
2070 816, 0, 480, 481, 512, 513, 0,
2071 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2072 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
2073 816, 0, 540, 541, 572, 573, 0,
2074 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2075 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
2076 816, 0, 576, 577, 608, 609, 0,
2077 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2078 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
2079 864, 0, 576, 577, 608, 609, 0,
2080 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2081 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
2082 896, 0, 600, 601, 632, 633, 0,
2083 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2084 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
2085 928, 0, 624, 625, 656, 657, 0,
2086 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2087 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
2088 1016, 0, 766, 767, 798, 799, 0,
2089 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2090 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
2091 1120, 0, 768, 769, 800, 801, 0,
2092 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2093 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
2094 1376, 0, 1024, 1025, 1056, 1057, 0,
2095 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2098 static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
2100 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
2101 const struct drm_connector_state *conn_state = connector->state;
2102 struct intel_sdvo_sdtv_resolution_request tv_res;
2103 u32 reply = 0, format_map = 0;
2106 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2107 connector->base.id, connector->name);
2110 * Read the list of supported input resolutions for the selected TV
2113 format_map = 1 << conn_state->tv.mode;
2114 memcpy(&tv_res, &format_map,
2115 min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
2117 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
2120 BUILD_BUG_ON(sizeof(tv_res) != 3);
2121 if (!intel_sdvo_write_cmd(intel_sdvo,
2122 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
2123 &tv_res, sizeof(tv_res)))
2125 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
2128 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
2129 if (reply & (1 << i)) {
2130 struct drm_display_mode *nmode;
2131 nmode = drm_mode_duplicate(connector->dev,
2134 drm_mode_probed_add(connector, nmode);
2138 static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
2140 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
2141 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2142 struct drm_display_mode *newmode;
2144 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2145 connector->base.id, connector->name);
2148 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
2149 * SDVO->LVDS transcoders can't cope with the EDID mode.
2151 if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
2152 newmode = drm_mode_duplicate(connector->dev,
2153 dev_priv->vbt.sdvo_lvds_vbt_mode);
2154 if (newmode != NULL) {
2155 /* Guarantee the mode is preferred */
2156 newmode->type = (DRM_MODE_TYPE_PREFERRED |
2157 DRM_MODE_TYPE_DRIVER);
2158 drm_mode_probed_add(connector, newmode);
2163 * Attempt to get the mode list from DDC.
2164 * Assume that the preferred modes are
2165 * arranged in priority order.
2167 intel_ddc_get_modes(connector, &intel_sdvo->ddc);
2170 static int intel_sdvo_get_modes(struct drm_connector *connector)
2172 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2174 if (IS_TV(intel_sdvo_connector))
2175 intel_sdvo_get_tv_modes(connector);
2176 else if (IS_LVDS(intel_sdvo_connector))
2177 intel_sdvo_get_lvds_modes(connector);
2179 intel_sdvo_get_ddc_modes(connector);
2181 return !list_empty(&connector->probed_modes);
2185 intel_sdvo_connector_atomic_get_property(struct drm_connector *connector,
2186 const struct drm_connector_state *state,
2187 struct drm_property *property,
2190 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2191 const struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state((void *)state);
2193 if (property == intel_sdvo_connector->tv_format) {
2196 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2197 if (state->tv.mode == intel_sdvo_connector->tv_format_supported[i]) {
2205 } else if (property == intel_sdvo_connector->top ||
2206 property == intel_sdvo_connector->bottom)
2207 *val = intel_sdvo_connector->max_vscan - sdvo_state->tv.overscan_v;
2208 else if (property == intel_sdvo_connector->left ||
2209 property == intel_sdvo_connector->right)
2210 *val = intel_sdvo_connector->max_hscan - sdvo_state->tv.overscan_h;
2211 else if (property == intel_sdvo_connector->hpos)
2212 *val = sdvo_state->tv.hpos;
2213 else if (property == intel_sdvo_connector->vpos)
2214 *val = sdvo_state->tv.vpos;
2215 else if (property == intel_sdvo_connector->saturation)
2216 *val = state->tv.saturation;
2217 else if (property == intel_sdvo_connector->contrast)
2218 *val = state->tv.contrast;
2219 else if (property == intel_sdvo_connector->hue)
2220 *val = state->tv.hue;
2221 else if (property == intel_sdvo_connector->brightness)
2222 *val = state->tv.brightness;
2223 else if (property == intel_sdvo_connector->sharpness)
2224 *val = sdvo_state->tv.sharpness;
2225 else if (property == intel_sdvo_connector->flicker_filter)
2226 *val = sdvo_state->tv.flicker_filter;
2227 else if (property == intel_sdvo_connector->flicker_filter_2d)
2228 *val = sdvo_state->tv.flicker_filter_2d;
2229 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2230 *val = sdvo_state->tv.flicker_filter_adaptive;
2231 else if (property == intel_sdvo_connector->tv_chroma_filter)
2232 *val = sdvo_state->tv.chroma_filter;
2233 else if (property == intel_sdvo_connector->tv_luma_filter)
2234 *val = sdvo_state->tv.luma_filter;
2235 else if (property == intel_sdvo_connector->dot_crawl)
2236 *val = sdvo_state->tv.dot_crawl;
2238 return intel_digital_connector_atomic_get_property(connector, state, property, val);
2244 intel_sdvo_connector_atomic_set_property(struct drm_connector *connector,
2245 struct drm_connector_state *state,
2246 struct drm_property *property,
2249 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2250 struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state(state);
2252 if (property == intel_sdvo_connector->tv_format) {
2253 state->tv.mode = intel_sdvo_connector->tv_format_supported[val];
2256 struct drm_crtc_state *crtc_state =
2257 drm_atomic_get_new_crtc_state(state->state, state->crtc);
2259 crtc_state->connectors_changed = true;
2261 } else if (property == intel_sdvo_connector->top ||
2262 property == intel_sdvo_connector->bottom)
2263 /* Cannot set these independent from each other */
2264 sdvo_state->tv.overscan_v = intel_sdvo_connector->max_vscan - val;
2265 else if (property == intel_sdvo_connector->left ||
2266 property == intel_sdvo_connector->right)
2267 /* Cannot set these independent from each other */
2268 sdvo_state->tv.overscan_h = intel_sdvo_connector->max_hscan - val;
2269 else if (property == intel_sdvo_connector->hpos)
2270 sdvo_state->tv.hpos = val;
2271 else if (property == intel_sdvo_connector->vpos)
2272 sdvo_state->tv.vpos = val;
2273 else if (property == intel_sdvo_connector->saturation)
2274 state->tv.saturation = val;
2275 else if (property == intel_sdvo_connector->contrast)
2276 state->tv.contrast = val;
2277 else if (property == intel_sdvo_connector->hue)
2278 state->tv.hue = val;
2279 else if (property == intel_sdvo_connector->brightness)
2280 state->tv.brightness = val;
2281 else if (property == intel_sdvo_connector->sharpness)
2282 sdvo_state->tv.sharpness = val;
2283 else if (property == intel_sdvo_connector->flicker_filter)
2284 sdvo_state->tv.flicker_filter = val;
2285 else if (property == intel_sdvo_connector->flicker_filter_2d)
2286 sdvo_state->tv.flicker_filter_2d = val;
2287 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2288 sdvo_state->tv.flicker_filter_adaptive = val;
2289 else if (property == intel_sdvo_connector->tv_chroma_filter)
2290 sdvo_state->tv.chroma_filter = val;
2291 else if (property == intel_sdvo_connector->tv_luma_filter)
2292 sdvo_state->tv.luma_filter = val;
2293 else if (property == intel_sdvo_connector->dot_crawl)
2294 sdvo_state->tv.dot_crawl = val;
2296 return intel_digital_connector_atomic_set_property(connector, state, property, val);
2302 intel_sdvo_connector_register(struct drm_connector *connector)
2304 struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
2307 ret = intel_connector_register(connector);
2311 return sysfs_create_link(&connector->kdev->kobj,
2312 &sdvo->ddc.dev.kobj,
2313 sdvo->ddc.dev.kobj.name);
2317 intel_sdvo_connector_unregister(struct drm_connector *connector)
2319 struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
2321 sysfs_remove_link(&connector->kdev->kobj,
2322 sdvo->ddc.dev.kobj.name);
2323 intel_connector_unregister(connector);
2326 static struct drm_connector_state *
2327 intel_sdvo_connector_duplicate_state(struct drm_connector *connector)
2329 struct intel_sdvo_connector_state *state;
2331 state = kmemdup(connector->state, sizeof(*state), GFP_KERNEL);
2335 __drm_atomic_helper_connector_duplicate_state(connector, &state->base.base);
2336 return &state->base.base;
2339 static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
2340 .detect = intel_sdvo_detect,
2341 .fill_modes = drm_helper_probe_single_connector_modes,
2342 .atomic_get_property = intel_sdvo_connector_atomic_get_property,
2343 .atomic_set_property = intel_sdvo_connector_atomic_set_property,
2344 .late_register = intel_sdvo_connector_register,
2345 .early_unregister = intel_sdvo_connector_unregister,
2346 .destroy = intel_connector_destroy,
2347 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
2348 .atomic_duplicate_state = intel_sdvo_connector_duplicate_state,
2351 static int intel_sdvo_atomic_check(struct drm_connector *conn,
2352 struct drm_connector_state *new_conn_state)
2354 struct drm_atomic_state *state = new_conn_state->state;
2355 struct drm_connector_state *old_conn_state =
2356 drm_atomic_get_old_connector_state(state, conn);
2357 struct intel_sdvo_connector_state *old_state =
2358 to_intel_sdvo_connector_state(old_conn_state);
2359 struct intel_sdvo_connector_state *new_state =
2360 to_intel_sdvo_connector_state(new_conn_state);
2362 if (new_conn_state->crtc &&
2363 (memcmp(&old_state->tv, &new_state->tv, sizeof(old_state->tv)) ||
2364 memcmp(&old_conn_state->tv, &new_conn_state->tv, sizeof(old_conn_state->tv)))) {
2365 struct drm_crtc_state *crtc_state =
2366 drm_atomic_get_new_crtc_state(new_conn_state->state,
2367 new_conn_state->crtc);
2369 crtc_state->connectors_changed = true;
2372 return intel_digital_connector_atomic_check(conn, new_conn_state);
2375 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2376 .get_modes = intel_sdvo_get_modes,
2377 .mode_valid = intel_sdvo_mode_valid,
2378 .atomic_check = intel_sdvo_atomic_check,
2381 static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2383 struct intel_sdvo *intel_sdvo = to_sdvo(to_intel_encoder(encoder));
2385 i2c_del_adapter(&intel_sdvo->ddc);
2386 intel_encoder_destroy(encoder);
2389 static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2390 .destroy = intel_sdvo_enc_destroy,
2394 intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
2397 unsigned int num_bits;
2400 * Make a mask of outputs less than or equal to our own priority in the
2403 switch (sdvo->controlled_output) {
2404 case SDVO_OUTPUT_LVDS1:
2405 mask |= SDVO_OUTPUT_LVDS1;
2407 case SDVO_OUTPUT_LVDS0:
2408 mask |= SDVO_OUTPUT_LVDS0;
2410 case SDVO_OUTPUT_TMDS1:
2411 mask |= SDVO_OUTPUT_TMDS1;
2413 case SDVO_OUTPUT_TMDS0:
2414 mask |= SDVO_OUTPUT_TMDS0;
2416 case SDVO_OUTPUT_RGB1:
2417 mask |= SDVO_OUTPUT_RGB1;
2419 case SDVO_OUTPUT_RGB0:
2420 mask |= SDVO_OUTPUT_RGB0;
2424 /* Count bits to find what number we are in the priority list. */
2425 mask &= sdvo->caps.output_flags;
2426 num_bits = hweight16(mask);
2427 /* If more than 3 outputs, default to DDC bus 3 for now. */
2431 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2432 sdvo->ddc_bus = 1 << num_bits;
2436 * Choose the appropriate DDC bus for control bus switch command for this
2437 * SDVO output based on the controlled output.
2439 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2440 * outputs, then LVDS outputs.
2443 intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
2444 struct intel_sdvo *sdvo)
2446 struct sdvo_device_mapping *mapping;
2448 if (sdvo->port == PORT_B)
2449 mapping = &dev_priv->vbt.sdvo_mappings[0];
2451 mapping = &dev_priv->vbt.sdvo_mappings[1];
2453 if (mapping->initialized)
2454 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
2456 intel_sdvo_guess_ddc_bus(sdvo);
2460 intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
2461 struct intel_sdvo *sdvo)
2463 struct sdvo_device_mapping *mapping;
2466 if (sdvo->port == PORT_B)
2467 mapping = &dev_priv->vbt.sdvo_mappings[0];
2469 mapping = &dev_priv->vbt.sdvo_mappings[1];
2471 if (mapping->initialized &&
2472 intel_gmbus_is_valid_pin(dev_priv, mapping->i2c_pin))
2473 pin = mapping->i2c_pin;
2475 pin = GMBUS_PIN_DPB;
2477 sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
2480 * With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
2481 * our code totally fails once we start using gmbus. Hence fall back to
2482 * bit banging for now.
2484 intel_gmbus_force_bit(sdvo->i2c, true);
2487 /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
2489 intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
2491 intel_gmbus_force_bit(sdvo->i2c, false);
2495 intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)
2497 return intel_sdvo_check_supp_encode(intel_sdvo);
2501 intel_sdvo_get_slave_addr(struct drm_i915_private *dev_priv,
2502 struct intel_sdvo *sdvo)
2504 struct sdvo_device_mapping *my_mapping, *other_mapping;
2506 if (sdvo->port == PORT_B) {
2507 my_mapping = &dev_priv->vbt.sdvo_mappings[0];
2508 other_mapping = &dev_priv->vbt.sdvo_mappings[1];
2510 my_mapping = &dev_priv->vbt.sdvo_mappings[1];
2511 other_mapping = &dev_priv->vbt.sdvo_mappings[0];
2514 /* If the BIOS described our SDVO device, take advantage of it. */
2515 if (my_mapping->slave_addr)
2516 return my_mapping->slave_addr;
2519 * If the BIOS only described a different SDVO device, use the
2520 * address that it isn't using.
2522 if (other_mapping->slave_addr) {
2523 if (other_mapping->slave_addr == 0x70)
2530 * No SDVO device info is found for another DVO port,
2531 * so use mapping assumption we had before BIOS parsing.
2533 if (sdvo->port == PORT_B)
2540 intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2541 struct intel_sdvo *encoder)
2543 struct drm_connector *drm_connector;
2546 drm_connector = &connector->base.base;
2547 ret = drm_connector_init(encoder->base.base.dev,
2549 &intel_sdvo_connector_funcs,
2550 connector->base.base.connector_type);
2554 drm_connector_helper_add(drm_connector,
2555 &intel_sdvo_connector_helper_funcs);
2557 connector->base.base.interlace_allowed = 1;
2558 connector->base.base.doublescan_allowed = 0;
2559 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2560 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2562 intel_connector_attach_encoder(&connector->base, &encoder->base);
2568 intel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
2569 struct intel_sdvo_connector *connector)
2571 struct drm_i915_private *dev_priv = to_i915(connector->base.base.dev);
2573 intel_attach_force_audio_property(&connector->base.base);
2574 if (INTEL_GEN(dev_priv) >= 4 && IS_MOBILE(dev_priv)) {
2575 intel_attach_broadcast_rgb_property(&connector->base.base);
2577 intel_attach_aspect_ratio_property(&connector->base.base);
2578 connector->base.base.state->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
2581 static struct intel_sdvo_connector *intel_sdvo_connector_alloc(void)
2583 struct intel_sdvo_connector *sdvo_connector;
2584 struct intel_sdvo_connector_state *conn_state;
2586 sdvo_connector = kzalloc(sizeof(*sdvo_connector), GFP_KERNEL);
2587 if (!sdvo_connector)
2590 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
2592 kfree(sdvo_connector);
2596 __drm_atomic_helper_connector_reset(&sdvo_connector->base.base,
2597 &conn_state->base.base);
2599 return sdvo_connector;
2603 intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2605 struct drm_encoder *encoder = &intel_sdvo->base.base;
2606 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
2607 struct drm_connector *connector;
2608 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2609 struct intel_connector *intel_connector;
2610 struct intel_sdvo_connector *intel_sdvo_connector;
2612 DRM_DEBUG_KMS("initialising DVI device %d\n", device);
2614 intel_sdvo_connector = intel_sdvo_connector_alloc();
2615 if (!intel_sdvo_connector)
2619 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
2620 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2621 } else if (device == 1) {
2622 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
2623 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2626 intel_connector = &intel_sdvo_connector->base;
2627 connector = &intel_connector->base;
2628 if (intel_sdvo_get_hotplug_support(intel_sdvo) &
2629 intel_sdvo_connector->output_flag) {
2630 intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
2632 * Some SDVO devices have one-shot hotplug interrupts.
2633 * Ensure that they get re-enabled when an interrupt happens.
2635 intel_encoder->hotplug = intel_sdvo_hotplug;
2636 intel_sdvo_enable_hotplug(intel_encoder);
2638 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2640 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2641 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2643 /* gen3 doesn't do the hdmi bits in the SDVO register */
2644 if (INTEL_GEN(dev_priv) >= 4 &&
2645 intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
2646 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2647 intel_sdvo_connector->is_hdmi = true;
2650 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2651 kfree(intel_sdvo_connector);
2655 if (intel_sdvo_connector->is_hdmi)
2656 intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
2662 intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
2664 struct drm_encoder *encoder = &intel_sdvo->base.base;
2665 struct drm_connector *connector;
2666 struct intel_connector *intel_connector;
2667 struct intel_sdvo_connector *intel_sdvo_connector;
2669 DRM_DEBUG_KMS("initialising TV type %d\n", type);
2671 intel_sdvo_connector = intel_sdvo_connector_alloc();
2672 if (!intel_sdvo_connector)
2675 intel_connector = &intel_sdvo_connector->base;
2676 connector = &intel_connector->base;
2677 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2678 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2680 intel_sdvo->controlled_output |= type;
2681 intel_sdvo_connector->output_flag = type;
2683 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2684 kfree(intel_sdvo_connector);
2688 if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
2691 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2697 intel_connector_destroy(connector);
2702 intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
2704 struct drm_encoder *encoder = &intel_sdvo->base.base;
2705 struct drm_connector *connector;
2706 struct intel_connector *intel_connector;
2707 struct intel_sdvo_connector *intel_sdvo_connector;
2709 DRM_DEBUG_KMS("initialising analog device %d\n", device);
2711 intel_sdvo_connector = intel_sdvo_connector_alloc();
2712 if (!intel_sdvo_connector)
2715 intel_connector = &intel_sdvo_connector->base;
2716 connector = &intel_connector->base;
2717 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2718 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2719 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2722 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
2723 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2724 } else if (device == 1) {
2725 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
2726 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2729 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2730 kfree(intel_sdvo_connector);
2738 intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
2740 struct drm_encoder *encoder = &intel_sdvo->base.base;
2741 struct drm_connector *connector;
2742 struct intel_connector *intel_connector;
2743 struct intel_sdvo_connector *intel_sdvo_connector;
2744 struct drm_display_mode *mode;
2746 DRM_DEBUG_KMS("initialising LVDS device %d\n", device);
2748 intel_sdvo_connector = intel_sdvo_connector_alloc();
2749 if (!intel_sdvo_connector)
2752 intel_connector = &intel_sdvo_connector->base;
2753 connector = &intel_connector->base;
2754 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2755 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2758 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
2759 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2760 } else if (device == 1) {
2761 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
2762 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2765 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2766 kfree(intel_sdvo_connector);
2770 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2773 intel_sdvo_get_lvds_modes(connector);
2775 list_for_each_entry(mode, &connector->probed_modes, head) {
2776 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
2777 struct drm_display_mode *fixed_mode =
2778 drm_mode_duplicate(connector->dev, mode);
2780 intel_panel_init(&intel_connector->panel,
2786 if (!intel_connector->panel.fixed_mode)
2792 intel_connector_destroy(connector);
2797 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, u16 flags)
2799 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2801 if (flags & SDVO_OUTPUT_TMDS0)
2802 if (!intel_sdvo_dvi_init(intel_sdvo, 0))
2805 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2806 if (!intel_sdvo_dvi_init(intel_sdvo, 1))
2809 /* TV has no XXX1 function block */
2810 if (flags & SDVO_OUTPUT_SVID0)
2811 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
2814 if (flags & SDVO_OUTPUT_CVBS0)
2815 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
2818 if (flags & SDVO_OUTPUT_YPRPB0)
2819 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
2822 if (flags & SDVO_OUTPUT_RGB0)
2823 if (!intel_sdvo_analog_init(intel_sdvo, 0))
2826 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2827 if (!intel_sdvo_analog_init(intel_sdvo, 1))
2830 if (flags & SDVO_OUTPUT_LVDS0)
2831 if (!intel_sdvo_lvds_init(intel_sdvo, 0))
2834 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2835 if (!intel_sdvo_lvds_init(intel_sdvo, 1))
2838 if ((flags & SDVO_OUTPUT_MASK) == 0) {
2839 unsigned char bytes[2];
2841 intel_sdvo->controlled_output = 0;
2842 memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
2843 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2844 SDVO_NAME(intel_sdvo),
2845 bytes[0], bytes[1]);
2848 intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2853 static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
2855 struct drm_device *dev = intel_sdvo->base.base.dev;
2856 struct drm_connector *connector, *tmp;
2858 list_for_each_entry_safe(connector, tmp,
2859 &dev->mode_config.connector_list, head) {
2860 if (intel_attached_encoder(connector) == &intel_sdvo->base) {
2861 drm_connector_unregister(connector);
2862 intel_connector_destroy(connector);
2867 static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
2868 struct intel_sdvo_connector *intel_sdvo_connector,
2871 struct drm_device *dev = intel_sdvo->base.base.dev;
2872 struct intel_sdvo_tv_format format;
2875 if (!intel_sdvo_set_target_output(intel_sdvo, type))
2878 BUILD_BUG_ON(sizeof(format) != 6);
2879 if (!intel_sdvo_get_value(intel_sdvo,
2880 SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
2881 &format, sizeof(format)))
2884 memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
2886 if (format_map == 0)
2889 intel_sdvo_connector->format_supported_num = 0;
2890 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2891 if (format_map & (1 << i))
2892 intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
2895 intel_sdvo_connector->tv_format =
2896 drm_property_create(dev, DRM_MODE_PROP_ENUM,
2897 "mode", intel_sdvo_connector->format_supported_num);
2898 if (!intel_sdvo_connector->tv_format)
2901 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2902 drm_property_add_enum(intel_sdvo_connector->tv_format, i,
2903 tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
2905 intel_sdvo_connector->base.base.state->tv.mode = intel_sdvo_connector->tv_format_supported[0];
2906 drm_object_attach_property(&intel_sdvo_connector->base.base.base,
2907 intel_sdvo_connector->tv_format, 0);
2912 #define _ENHANCEMENT(state_assignment, name, NAME) do { \
2913 if (enhancements.name) { \
2914 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
2915 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
2917 intel_sdvo_connector->name = \
2918 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
2919 if (!intel_sdvo_connector->name) return false; \
2920 state_assignment = response; \
2921 drm_object_attach_property(&connector->base, \
2922 intel_sdvo_connector->name, 0); \
2923 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
2924 data_value[0], data_value[1], response); \
2928 #define ENHANCEMENT(state, name, NAME) _ENHANCEMENT((state)->name, name, NAME)
2931 intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
2932 struct intel_sdvo_connector *intel_sdvo_connector,
2933 struct intel_sdvo_enhancements_reply enhancements)
2935 struct drm_device *dev = intel_sdvo->base.base.dev;
2936 struct drm_connector *connector = &intel_sdvo_connector->base.base;
2937 struct drm_connector_state *conn_state = connector->state;
2938 struct intel_sdvo_connector_state *sdvo_state =
2939 to_intel_sdvo_connector_state(conn_state);
2940 u16 response, data_value[2];
2942 /* when horizontal overscan is supported, Add the left/right property */
2943 if (enhancements.overscan_h) {
2944 if (!intel_sdvo_get_value(intel_sdvo,
2945 SDVO_CMD_GET_MAX_OVERSCAN_H,
2949 if (!intel_sdvo_get_value(intel_sdvo,
2950 SDVO_CMD_GET_OVERSCAN_H,
2954 sdvo_state->tv.overscan_h = response;
2956 intel_sdvo_connector->max_hscan = data_value[0];
2957 intel_sdvo_connector->left =
2958 drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
2959 if (!intel_sdvo_connector->left)
2962 drm_object_attach_property(&connector->base,
2963 intel_sdvo_connector->left, 0);
2965 intel_sdvo_connector->right =
2966 drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
2967 if (!intel_sdvo_connector->right)
2970 drm_object_attach_property(&connector->base,
2971 intel_sdvo_connector->right, 0);
2972 DRM_DEBUG_KMS("h_overscan: max %d, "
2973 "default %d, current %d\n",
2974 data_value[0], data_value[1], response);
2977 if (enhancements.overscan_v) {
2978 if (!intel_sdvo_get_value(intel_sdvo,
2979 SDVO_CMD_GET_MAX_OVERSCAN_V,
2983 if (!intel_sdvo_get_value(intel_sdvo,
2984 SDVO_CMD_GET_OVERSCAN_V,
2988 sdvo_state->tv.overscan_v = response;
2990 intel_sdvo_connector->max_vscan = data_value[0];
2991 intel_sdvo_connector->top =
2992 drm_property_create_range(dev, 0,
2993 "top_margin", 0, data_value[0]);
2994 if (!intel_sdvo_connector->top)
2997 drm_object_attach_property(&connector->base,
2998 intel_sdvo_connector->top, 0);
3000 intel_sdvo_connector->bottom =
3001 drm_property_create_range(dev, 0,
3002 "bottom_margin", 0, data_value[0]);
3003 if (!intel_sdvo_connector->bottom)
3006 drm_object_attach_property(&connector->base,
3007 intel_sdvo_connector->bottom, 0);
3008 DRM_DEBUG_KMS("v_overscan: max %d, "
3009 "default %d, current %d\n",
3010 data_value[0], data_value[1], response);
3013 ENHANCEMENT(&sdvo_state->tv, hpos, HPOS);
3014 ENHANCEMENT(&sdvo_state->tv, vpos, VPOS);
3015 ENHANCEMENT(&conn_state->tv, saturation, SATURATION);
3016 ENHANCEMENT(&conn_state->tv, contrast, CONTRAST);
3017 ENHANCEMENT(&conn_state->tv, hue, HUE);
3018 ENHANCEMENT(&conn_state->tv, brightness, BRIGHTNESS);
3019 ENHANCEMENT(&sdvo_state->tv, sharpness, SHARPNESS);
3020 ENHANCEMENT(&sdvo_state->tv, flicker_filter, FLICKER_FILTER);
3021 ENHANCEMENT(&sdvo_state->tv, flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
3022 ENHANCEMENT(&sdvo_state->tv, flicker_filter_2d, FLICKER_FILTER_2D);
3023 _ENHANCEMENT(sdvo_state->tv.chroma_filter, tv_chroma_filter, TV_CHROMA_FILTER);
3024 _ENHANCEMENT(sdvo_state->tv.luma_filter, tv_luma_filter, TV_LUMA_FILTER);
3026 if (enhancements.dot_crawl) {
3027 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
3030 sdvo_state->tv.dot_crawl = response & 0x1;
3031 intel_sdvo_connector->dot_crawl =
3032 drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
3033 if (!intel_sdvo_connector->dot_crawl)
3036 drm_object_attach_property(&connector->base,
3037 intel_sdvo_connector->dot_crawl, 0);
3038 DRM_DEBUG_KMS("dot crawl: current %d\n", response);
3045 intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
3046 struct intel_sdvo_connector *intel_sdvo_connector,
3047 struct intel_sdvo_enhancements_reply enhancements)
3049 struct drm_device *dev = intel_sdvo->base.base.dev;
3050 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3051 u16 response, data_value[2];
3053 ENHANCEMENT(&connector->state->tv, brightness, BRIGHTNESS);
3060 static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
3061 struct intel_sdvo_connector *intel_sdvo_connector)
3064 struct intel_sdvo_enhancements_reply reply;
3068 BUILD_BUG_ON(sizeof(enhancements) != 2);
3070 if (!intel_sdvo_get_value(intel_sdvo,
3071 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
3072 &enhancements, sizeof(enhancements)) ||
3073 enhancements.response == 0) {
3074 DRM_DEBUG_KMS("No enhancement is supported\n");
3078 if (IS_TV(intel_sdvo_connector))
3079 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3080 else if (IS_LVDS(intel_sdvo_connector))
3081 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3086 static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
3087 struct i2c_msg *msgs,
3090 struct intel_sdvo *sdvo = adapter->algo_data;
3092 if (!__intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
3095 return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
3098 static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
3100 struct intel_sdvo *sdvo = adapter->algo_data;
3101 return sdvo->i2c->algo->functionality(sdvo->i2c);
3104 static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
3105 .master_xfer = intel_sdvo_ddc_proxy_xfer,
3106 .functionality = intel_sdvo_ddc_proxy_func
3109 static void proxy_lock_bus(struct i2c_adapter *adapter,
3112 struct intel_sdvo *sdvo = adapter->algo_data;
3113 sdvo->i2c->lock_ops->lock_bus(sdvo->i2c, flags);
3116 static int proxy_trylock_bus(struct i2c_adapter *adapter,
3119 struct intel_sdvo *sdvo = adapter->algo_data;
3120 return sdvo->i2c->lock_ops->trylock_bus(sdvo->i2c, flags);
3123 static void proxy_unlock_bus(struct i2c_adapter *adapter,
3126 struct intel_sdvo *sdvo = adapter->algo_data;
3127 sdvo->i2c->lock_ops->unlock_bus(sdvo->i2c, flags);
3130 static const struct i2c_lock_operations proxy_lock_ops = {
3131 .lock_bus = proxy_lock_bus,
3132 .trylock_bus = proxy_trylock_bus,
3133 .unlock_bus = proxy_unlock_bus,
3137 intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
3138 struct drm_i915_private *dev_priv)
3140 struct pci_dev *pdev = dev_priv->drm.pdev;
3142 sdvo->ddc.owner = THIS_MODULE;
3143 sdvo->ddc.class = I2C_CLASS_DDC;
3144 snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
3145 sdvo->ddc.dev.parent = &pdev->dev;
3146 sdvo->ddc.algo_data = sdvo;
3147 sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
3148 sdvo->ddc.lock_ops = &proxy_lock_ops;
3150 return i2c_add_adapter(&sdvo->ddc) == 0;
3153 static void assert_sdvo_port_valid(const struct drm_i915_private *dev_priv,
3156 if (HAS_PCH_SPLIT(dev_priv))
3157 WARN_ON(port != PORT_B);
3159 WARN_ON(port != PORT_B && port != PORT_C);
3162 bool intel_sdvo_init(struct drm_i915_private *dev_priv,
3163 i915_reg_t sdvo_reg, enum port port)
3165 struct intel_encoder *intel_encoder;
3166 struct intel_sdvo *intel_sdvo;
3169 assert_sdvo_port_valid(dev_priv, port);
3171 intel_sdvo = kzalloc(sizeof(*intel_sdvo), GFP_KERNEL);
3175 intel_sdvo->sdvo_reg = sdvo_reg;
3176 intel_sdvo->port = port;
3177 intel_sdvo->slave_addr =
3178 intel_sdvo_get_slave_addr(dev_priv, intel_sdvo) >> 1;
3179 intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo);
3180 if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev_priv))
3183 /* encoder type will be decided later */
3184 intel_encoder = &intel_sdvo->base;
3185 intel_encoder->type = INTEL_OUTPUT_SDVO;
3186 intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
3187 intel_encoder->port = port;
3188 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
3189 &intel_sdvo_enc_funcs, 0,
3190 "SDVO %c", port_name(port));
3192 /* Read the regs to test if we can talk to the device */
3193 for (i = 0; i < 0x40; i++) {
3196 if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
3197 DRM_DEBUG_KMS("No SDVO device found on %s\n",
3198 SDVO_NAME(intel_sdvo));
3203 intel_encoder->compute_config = intel_sdvo_compute_config;
3204 if (HAS_PCH_SPLIT(dev_priv)) {
3205 intel_encoder->disable = pch_disable_sdvo;
3206 intel_encoder->post_disable = pch_post_disable_sdvo;
3208 intel_encoder->disable = intel_disable_sdvo;
3210 intel_encoder->pre_enable = intel_sdvo_pre_enable;
3211 intel_encoder->enable = intel_enable_sdvo;
3212 intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
3213 intel_encoder->get_config = intel_sdvo_get_config;
3215 /* In default case sdvo lvds is false */
3216 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
3219 if (intel_sdvo_output_setup(intel_sdvo,
3220 intel_sdvo->caps.output_flags) != true) {
3221 DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
3222 SDVO_NAME(intel_sdvo));
3223 /* Output_setup can leave behind connectors! */
3228 * Only enable the hotplug irq if we need it, to work around noisy
3231 if (intel_sdvo->hotplug_active) {
3232 if (intel_sdvo->port == PORT_B)
3233 intel_encoder->hpd_pin = HPD_SDVO_B;
3235 intel_encoder->hpd_pin = HPD_SDVO_C;
3239 * Cloning SDVO with anything is often impossible, since the SDVO
3240 * encoder can request a special input timing mode. And even if that's
3241 * not the case we have evidence that cloning a plain unscaled mode with
3242 * VGA doesn't really work. Furthermore the cloning flags are way too
3243 * simplistic anyway to express such constraints, so just give up on
3244 * cloning for SDVO encoders.
3246 intel_sdvo->base.cloneable = 0;
3248 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo);
3250 /* Set the input timing to the screen. Assume always input 0. */
3251 if (!intel_sdvo_set_target_input(intel_sdvo))
3254 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
3255 &intel_sdvo->pixel_clock_min,
3256 &intel_sdvo->pixel_clock_max))
3259 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
3260 "clock range %dMHz - %dMHz, "
3261 "input 1: %c, input 2: %c, "
3262 "output 1: %c, output 2: %c\n",
3263 SDVO_NAME(intel_sdvo),
3264 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
3265 intel_sdvo->caps.device_rev_id,
3266 intel_sdvo->pixel_clock_min / 1000,
3267 intel_sdvo->pixel_clock_max / 1000,
3268 (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
3269 (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
3270 /* check currently supported outputs */
3271 intel_sdvo->caps.output_flags &
3272 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
3273 intel_sdvo->caps.output_flags &
3274 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
3278 intel_sdvo_output_cleanup(intel_sdvo);
3281 drm_encoder_cleanup(&intel_encoder->base);
3282 i2c_del_adapter(&intel_sdvo->ddc);
3284 intel_sdvo_unselect_i2c_bus(intel_sdvo);