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>
39 #include "intel_atomic.h"
40 #include "intel_connector.h"
41 #include "intel_display_types.h"
42 #include "intel_fifo_underrun.h"
43 #include "intel_gmbus.h"
44 #include "intel_hdmi.h"
45 #include "intel_hotplug.h"
46 #include "intel_panel.h"
47 #include "intel_sdvo.h"
48 #include "intel_sdvo_regs.h"
50 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
51 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
52 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
53 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
55 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
58 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
59 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
60 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
61 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
62 #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
65 static const char * const tv_format_names[] = {
66 "NTSC_M" , "NTSC_J" , "NTSC_443",
67 "PAL_B" , "PAL_D" , "PAL_G" ,
68 "PAL_H" , "PAL_I" , "PAL_M" ,
69 "PAL_N" , "PAL_NC" , "PAL_60" ,
70 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
71 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
75 #define TV_FORMAT_NUM ARRAY_SIZE(tv_format_names)
78 struct intel_encoder base;
80 struct i2c_adapter *i2c;
83 struct i2c_adapter ddc;
85 /* Register for the SDVO device: SDVOB or SDVOC */
88 /* Active outputs controlled by this SDVO output */
89 u16 controlled_output;
92 * Capabilities of the SDVO device returned by
93 * intel_sdvo_get_capabilities()
95 struct intel_sdvo_caps caps;
99 /* Pixel clock limitations reported by the SDVO device, in kHz */
100 int pixel_clock_min, pixel_clock_max;
103 * For multiple function SDVO device,
104 * this is for current attached outputs.
109 * Hotplug activation bits for this device
115 bool has_hdmi_monitor;
118 /* DDC bus used by this SDVO encoder */
122 * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
127 struct intel_sdvo_connector {
128 struct intel_connector base;
130 /* Mark the type of connector */
133 /* This contains all current supported TV format */
134 u8 tv_format_supported[TV_FORMAT_NUM];
135 int format_supported_num;
136 struct drm_property *tv_format;
138 /* add the property for the SDVO-TV */
139 struct drm_property *left;
140 struct drm_property *right;
141 struct drm_property *top;
142 struct drm_property *bottom;
143 struct drm_property *hpos;
144 struct drm_property *vpos;
145 struct drm_property *contrast;
146 struct drm_property *saturation;
147 struct drm_property *hue;
148 struct drm_property *sharpness;
149 struct drm_property *flicker_filter;
150 struct drm_property *flicker_filter_adaptive;
151 struct drm_property *flicker_filter_2d;
152 struct drm_property *tv_chroma_filter;
153 struct drm_property *tv_luma_filter;
154 struct drm_property *dot_crawl;
156 /* add the property for the SDVO-TV/LVDS */
157 struct drm_property *brightness;
159 /* this is to get the range of margin.*/
160 u32 max_hscan, max_vscan;
163 * This is set if we treat the device as HDMI, instead of DVI.
168 struct intel_sdvo_connector_state {
169 /* base.base: tv.saturation/contrast/hue/brightness */
170 struct intel_digital_connector_state base;
173 unsigned overscan_h, overscan_v, hpos, vpos, sharpness;
174 unsigned flicker_filter, flicker_filter_2d, flicker_filter_adaptive;
175 unsigned chroma_filter, luma_filter, dot_crawl;
179 static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
181 return container_of(encoder, struct intel_sdvo, base);
184 static struct intel_sdvo *intel_attached_sdvo(struct intel_connector *connector)
186 return to_sdvo(intel_attached_encoder(connector));
189 static struct intel_sdvo_connector *
190 to_intel_sdvo_connector(struct drm_connector *connector)
192 return container_of(connector, struct intel_sdvo_connector, base.base);
195 #define to_intel_sdvo_connector_state(conn_state) \
196 container_of((conn_state), struct intel_sdvo_connector_state, base.base)
199 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, u16 flags);
201 intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
202 struct intel_sdvo_connector *intel_sdvo_connector,
205 intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
206 struct intel_sdvo_connector *intel_sdvo_connector);
209 * Writes the SDVOB or SDVOC with the given value, but always writes both
210 * SDVOB and SDVOC to work around apparent hardware issues (according to
211 * comments in the BIOS).
213 static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
215 struct drm_device *dev = intel_sdvo->base.base.dev;
216 struct drm_i915_private *dev_priv = to_i915(dev);
217 u32 bval = val, cval = val;
220 if (HAS_PCH_SPLIT(dev_priv)) {
221 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
222 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
224 * HW workaround, need to write this twice for issue
225 * that may result in first write getting masked.
227 if (HAS_PCH_IBX(dev_priv)) {
228 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
229 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
234 if (intel_sdvo->port == PORT_B)
235 cval = intel_de_read(dev_priv, GEN3_SDVOC);
237 bval = intel_de_read(dev_priv, GEN3_SDVOB);
240 * Write the registers twice for luck. Sometimes,
241 * writing them only once doesn't appear to 'stick'.
242 * The BIOS does this too. Yay, magic
244 for (i = 0; i < 2; i++) {
245 intel_de_write(dev_priv, GEN3_SDVOB, bval);
246 intel_de_posting_read(dev_priv, GEN3_SDVOB);
248 intel_de_write(dev_priv, GEN3_SDVOC, cval);
249 intel_de_posting_read(dev_priv, GEN3_SDVOC);
253 static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
255 struct i2c_msg msgs[] = {
257 .addr = intel_sdvo->slave_addr,
263 .addr = intel_sdvo->slave_addr,
271 if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
274 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
278 #define SDVO_CMD_NAME_ENTRY(cmd_) { .cmd = SDVO_CMD_ ## cmd_, .name = #cmd_ }
280 /** Mapping of command numbers to names, for debug output */
281 static const struct {
284 } __attribute__ ((packed)) sdvo_cmd_names[] = {
285 SDVO_CMD_NAME_ENTRY(RESET),
286 SDVO_CMD_NAME_ENTRY(GET_DEVICE_CAPS),
287 SDVO_CMD_NAME_ENTRY(GET_FIRMWARE_REV),
288 SDVO_CMD_NAME_ENTRY(GET_TRAINED_INPUTS),
289 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_OUTPUTS),
290 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_OUTPUTS),
291 SDVO_CMD_NAME_ENTRY(GET_IN_OUT_MAP),
292 SDVO_CMD_NAME_ENTRY(SET_IN_OUT_MAP),
293 SDVO_CMD_NAME_ENTRY(GET_ATTACHED_DISPLAYS),
294 SDVO_CMD_NAME_ENTRY(GET_HOT_PLUG_SUPPORT),
295 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_HOT_PLUG),
296 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_HOT_PLUG),
297 SDVO_CMD_NAME_ENTRY(GET_INTERRUPT_EVENT_SOURCE),
298 SDVO_CMD_NAME_ENTRY(SET_TARGET_INPUT),
299 SDVO_CMD_NAME_ENTRY(SET_TARGET_OUTPUT),
300 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART1),
301 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART2),
302 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART1),
303 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART2),
304 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART1),
305 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART2),
306 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART1),
307 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART2),
308 SDVO_CMD_NAME_ENTRY(CREATE_PREFERRED_INPUT_TIMING),
309 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART1),
310 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART2),
311 SDVO_CMD_NAME_ENTRY(GET_INPUT_PIXEL_CLOCK_RANGE),
312 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_PIXEL_CLOCK_RANGE),
313 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_CLOCK_RATE_MULTS),
314 SDVO_CMD_NAME_ENTRY(GET_CLOCK_RATE_MULT),
315 SDVO_CMD_NAME_ENTRY(SET_CLOCK_RATE_MULT),
316 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_TV_FORMATS),
317 SDVO_CMD_NAME_ENTRY(GET_TV_FORMAT),
318 SDVO_CMD_NAME_ENTRY(SET_TV_FORMAT),
319 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_POWER_STATES),
320 SDVO_CMD_NAME_ENTRY(GET_POWER_STATE),
321 SDVO_CMD_NAME_ENTRY(SET_ENCODER_POWER_STATE),
322 SDVO_CMD_NAME_ENTRY(SET_DISPLAY_POWER_STATE),
323 SDVO_CMD_NAME_ENTRY(SET_CONTROL_BUS_SWITCH),
324 SDVO_CMD_NAME_ENTRY(GET_SDTV_RESOLUTION_SUPPORT),
325 SDVO_CMD_NAME_ENTRY(GET_SCALED_HDTV_RESOLUTION_SUPPORT),
326 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_ENHANCEMENTS),
328 /* Add the op code for SDVO enhancements */
329 SDVO_CMD_NAME_ENTRY(GET_MAX_HPOS),
330 SDVO_CMD_NAME_ENTRY(GET_HPOS),
331 SDVO_CMD_NAME_ENTRY(SET_HPOS),
332 SDVO_CMD_NAME_ENTRY(GET_MAX_VPOS),
333 SDVO_CMD_NAME_ENTRY(GET_VPOS),
334 SDVO_CMD_NAME_ENTRY(SET_VPOS),
335 SDVO_CMD_NAME_ENTRY(GET_MAX_SATURATION),
336 SDVO_CMD_NAME_ENTRY(GET_SATURATION),
337 SDVO_CMD_NAME_ENTRY(SET_SATURATION),
338 SDVO_CMD_NAME_ENTRY(GET_MAX_HUE),
339 SDVO_CMD_NAME_ENTRY(GET_HUE),
340 SDVO_CMD_NAME_ENTRY(SET_HUE),
341 SDVO_CMD_NAME_ENTRY(GET_MAX_CONTRAST),
342 SDVO_CMD_NAME_ENTRY(GET_CONTRAST),
343 SDVO_CMD_NAME_ENTRY(SET_CONTRAST),
344 SDVO_CMD_NAME_ENTRY(GET_MAX_BRIGHTNESS),
345 SDVO_CMD_NAME_ENTRY(GET_BRIGHTNESS),
346 SDVO_CMD_NAME_ENTRY(SET_BRIGHTNESS),
347 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_H),
348 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_H),
349 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_H),
350 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_V),
351 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_V),
352 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_V),
353 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER),
354 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER),
355 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER),
356 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_ADAPTIVE),
357 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_ADAPTIVE),
358 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_ADAPTIVE),
359 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_2D),
360 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_2D),
361 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_2D),
362 SDVO_CMD_NAME_ENTRY(GET_MAX_SHARPNESS),
363 SDVO_CMD_NAME_ENTRY(GET_SHARPNESS),
364 SDVO_CMD_NAME_ENTRY(SET_SHARPNESS),
365 SDVO_CMD_NAME_ENTRY(GET_DOT_CRAWL),
366 SDVO_CMD_NAME_ENTRY(SET_DOT_CRAWL),
367 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_CHROMA_FILTER),
368 SDVO_CMD_NAME_ENTRY(GET_TV_CHROMA_FILTER),
369 SDVO_CMD_NAME_ENTRY(SET_TV_CHROMA_FILTER),
370 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_LUMA_FILTER),
371 SDVO_CMD_NAME_ENTRY(GET_TV_LUMA_FILTER),
372 SDVO_CMD_NAME_ENTRY(SET_TV_LUMA_FILTER),
375 SDVO_CMD_NAME_ENTRY(GET_SUPP_ENCODE),
376 SDVO_CMD_NAME_ENTRY(GET_ENCODE),
377 SDVO_CMD_NAME_ENTRY(SET_ENCODE),
378 SDVO_CMD_NAME_ENTRY(SET_PIXEL_REPLI),
379 SDVO_CMD_NAME_ENTRY(GET_PIXEL_REPLI),
380 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY_CAP),
381 SDVO_CMD_NAME_ENTRY(SET_COLORIMETRY),
382 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY),
383 SDVO_CMD_NAME_ENTRY(GET_AUDIO_ENCRYPT_PREFER),
384 SDVO_CMD_NAME_ENTRY(SET_AUDIO_STAT),
385 SDVO_CMD_NAME_ENTRY(GET_AUDIO_STAT),
386 SDVO_CMD_NAME_ENTRY(GET_HBUF_INDEX),
387 SDVO_CMD_NAME_ENTRY(SET_HBUF_INDEX),
388 SDVO_CMD_NAME_ENTRY(GET_HBUF_INFO),
389 SDVO_CMD_NAME_ENTRY(GET_HBUF_AV_SPLIT),
390 SDVO_CMD_NAME_ENTRY(SET_HBUF_AV_SPLIT),
391 SDVO_CMD_NAME_ENTRY(GET_HBUF_TXRATE),
392 SDVO_CMD_NAME_ENTRY(SET_HBUF_TXRATE),
393 SDVO_CMD_NAME_ENTRY(SET_HBUF_DATA),
394 SDVO_CMD_NAME_ENTRY(GET_HBUF_DATA),
397 #undef SDVO_CMD_NAME_ENTRY
399 static const char *sdvo_cmd_name(u8 cmd)
403 for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
404 if (cmd == sdvo_cmd_names[i].cmd)
405 return sdvo_cmd_names[i].name;
411 #define SDVO_NAME(svdo) ((svdo)->port == PORT_B ? "SDVOB" : "SDVOC")
413 static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
414 const void *args, int args_len)
416 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
417 const char *cmd_name;
421 #define BUF_PRINT(args...) \
422 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
424 for (i = 0; i < args_len; i++) {
425 BUF_PRINT("%02X ", ((u8 *)args)[i]);
431 cmd_name = sdvo_cmd_name(cmd);
433 BUF_PRINT("(%s)", cmd_name);
435 BUF_PRINT("(%02X)", cmd);
437 drm_WARN_ON(&dev_priv->drm, pos >= sizeof(buffer) - 1);
440 DRM_DEBUG_KMS("%s: W: %02X %s\n", SDVO_NAME(intel_sdvo), cmd, buffer);
443 static const char * const cmd_status_names[] = {
444 [SDVO_CMD_STATUS_POWER_ON] = "Power on",
445 [SDVO_CMD_STATUS_SUCCESS] = "Success",
446 [SDVO_CMD_STATUS_NOTSUPP] = "Not supported",
447 [SDVO_CMD_STATUS_INVALID_ARG] = "Invalid arg",
448 [SDVO_CMD_STATUS_PENDING] = "Pending",
449 [SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED] = "Target not specified",
450 [SDVO_CMD_STATUS_SCALING_NOT_SUPP] = "Scaling not supported",
453 static const char *sdvo_cmd_status(u8 status)
455 if (status < ARRAY_SIZE(cmd_status_names))
456 return cmd_status_names[status];
461 static bool __intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
462 const void *args, int args_len,
466 struct i2c_msg *msgs;
469 /* Would be simpler to allocate both in one go ? */
470 buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
474 msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
480 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
482 for (i = 0; i < args_len; i++) {
483 msgs[i].addr = intel_sdvo->slave_addr;
486 msgs[i].buf = buf + 2 *i;
487 buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
488 buf[2*i + 1] = ((u8*)args)[i];
490 msgs[i].addr = intel_sdvo->slave_addr;
493 msgs[i].buf = buf + 2*i;
494 buf[2*i + 0] = SDVO_I2C_OPCODE;
497 /* the following two are to read the response */
498 status = SDVO_I2C_CMD_STATUS;
499 msgs[i+1].addr = intel_sdvo->slave_addr;
502 msgs[i+1].buf = &status;
504 msgs[i+2].addr = intel_sdvo->slave_addr;
505 msgs[i+2].flags = I2C_M_RD;
507 msgs[i+2].buf = &status;
510 ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
512 ret = __i2c_transfer(intel_sdvo->i2c, msgs, i+3);
514 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
519 /* failure in I2C transfer */
520 DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
530 static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
531 const void *args, int args_len)
533 return __intel_sdvo_write_cmd(intel_sdvo, cmd, args, args_len, true);
536 static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
537 void *response, int response_len)
539 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
540 const char *cmd_status;
541 u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
549 * The documentation states that all commands will be
550 * processed within 15µs, and that we need only poll
551 * the status byte a maximum of 3 times in order for the
552 * command to be complete.
554 * Check 5 times in case the hardware failed to read the docs.
556 * Also beware that the first response by many devices is to
557 * reply PENDING and stall for time. TVs are notorious for
558 * requiring longer than specified to complete their replies.
559 * Originally (in the DDX long ago), the delay was only ever 15ms
560 * with an additional delay of 30ms applied for TVs added later after
561 * many experiments. To accommodate both sets of delays, we do a
562 * sequence of slow checks if the device is falling behind and fails
563 * to reply within 5*15µs.
565 if (!intel_sdvo_read_byte(intel_sdvo,
570 while ((status == SDVO_CMD_STATUS_PENDING ||
571 status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
577 if (!intel_sdvo_read_byte(intel_sdvo,
583 #define BUF_PRINT(args...) \
584 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
586 cmd_status = sdvo_cmd_status(status);
588 BUF_PRINT("(%s)", cmd_status);
590 BUF_PRINT("(??? %d)", status);
592 if (status != SDVO_CMD_STATUS_SUCCESS)
595 /* Read the command response */
596 for (i = 0; i < response_len; i++) {
597 if (!intel_sdvo_read_byte(intel_sdvo,
598 SDVO_I2C_RETURN_0 + i,
599 &((u8 *)response)[i]))
601 BUF_PRINT(" %02X", ((u8 *)response)[i]);
604 drm_WARN_ON(&dev_priv->drm, pos >= sizeof(buffer) - 1);
607 DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo), buffer);
611 DRM_DEBUG_KMS("%s: R: ... failed %s\n",
612 SDVO_NAME(intel_sdvo), buffer);
616 static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode *adjusted_mode)
618 if (adjusted_mode->crtc_clock >= 100000)
620 else if (adjusted_mode->crtc_clock >= 50000)
626 static bool __intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
629 /* This must be the immediately preceding write before the i2c xfer */
630 return __intel_sdvo_write_cmd(intel_sdvo,
631 SDVO_CMD_SET_CONTROL_BUS_SWITCH,
635 static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
637 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
640 return intel_sdvo_read_response(intel_sdvo, NULL, 0);
644 intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
646 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
649 return intel_sdvo_read_response(intel_sdvo, value, len);
652 static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
654 struct intel_sdvo_set_target_input_args targets = {0};
655 return intel_sdvo_set_value(intel_sdvo,
656 SDVO_CMD_SET_TARGET_INPUT,
657 &targets, sizeof(targets));
661 * Return whether each input is trained.
663 * This function is making an assumption about the layout of the response,
664 * which should be checked against the docs.
666 static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
668 struct intel_sdvo_get_trained_inputs_response response;
670 BUILD_BUG_ON(sizeof(response) != 1);
671 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
672 &response, sizeof(response)))
675 *input_1 = response.input0_trained;
676 *input_2 = response.input1_trained;
680 static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
683 return intel_sdvo_set_value(intel_sdvo,
684 SDVO_CMD_SET_ACTIVE_OUTPUTS,
685 &outputs, sizeof(outputs));
688 static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
691 return intel_sdvo_get_value(intel_sdvo,
692 SDVO_CMD_GET_ACTIVE_OUTPUTS,
693 outputs, sizeof(*outputs));
696 static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
699 u8 state = SDVO_ENCODER_STATE_ON;
702 case DRM_MODE_DPMS_ON:
703 state = SDVO_ENCODER_STATE_ON;
705 case DRM_MODE_DPMS_STANDBY:
706 state = SDVO_ENCODER_STATE_STANDBY;
708 case DRM_MODE_DPMS_SUSPEND:
709 state = SDVO_ENCODER_STATE_SUSPEND;
711 case DRM_MODE_DPMS_OFF:
712 state = SDVO_ENCODER_STATE_OFF;
716 return intel_sdvo_set_value(intel_sdvo,
717 SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
720 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
724 struct intel_sdvo_pixel_clock_range clocks;
726 BUILD_BUG_ON(sizeof(clocks) != 4);
727 if (!intel_sdvo_get_value(intel_sdvo,
728 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
729 &clocks, sizeof(clocks)))
732 /* Convert the values from units of 10 kHz to kHz. */
733 *clock_min = clocks.min * 10;
734 *clock_max = clocks.max * 10;
738 static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
741 return intel_sdvo_set_value(intel_sdvo,
742 SDVO_CMD_SET_TARGET_OUTPUT,
743 &outputs, sizeof(outputs));
746 static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
747 struct intel_sdvo_dtd *dtd)
749 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
750 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
753 static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
754 struct intel_sdvo_dtd *dtd)
756 return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
757 intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
760 static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
761 struct intel_sdvo_dtd *dtd)
763 return intel_sdvo_set_timing(intel_sdvo,
764 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
767 static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
768 struct intel_sdvo_dtd *dtd)
770 return intel_sdvo_set_timing(intel_sdvo,
771 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
774 static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
775 struct intel_sdvo_dtd *dtd)
777 return intel_sdvo_get_timing(intel_sdvo,
778 SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
782 intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
783 struct intel_sdvo_connector *intel_sdvo_connector,
788 struct intel_sdvo_preferred_input_timing_args args;
790 memset(&args, 0, sizeof(args));
793 args.height = height;
796 if (IS_LVDS(intel_sdvo_connector)) {
797 const struct drm_display_mode *fixed_mode =
798 intel_sdvo_connector->base.panel.fixed_mode;
800 if (fixed_mode->hdisplay != width ||
801 fixed_mode->vdisplay != height)
805 return intel_sdvo_set_value(intel_sdvo,
806 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
807 &args, sizeof(args));
810 static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
811 struct intel_sdvo_dtd *dtd)
813 BUILD_BUG_ON(sizeof(dtd->part1) != 8);
814 BUILD_BUG_ON(sizeof(dtd->part2) != 8);
815 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
816 &dtd->part1, sizeof(dtd->part1)) &&
817 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
818 &dtd->part2, sizeof(dtd->part2));
821 static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
823 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
826 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
827 const struct drm_display_mode *mode)
830 u16 h_blank_len, h_sync_len, v_blank_len, v_sync_len;
831 u16 h_sync_offset, v_sync_offset;
834 memset(dtd, 0, sizeof(*dtd));
836 width = mode->hdisplay;
837 height = mode->vdisplay;
839 /* do some mode translations */
840 h_blank_len = mode->htotal - mode->hdisplay;
841 h_sync_len = mode->hsync_end - mode->hsync_start;
843 v_blank_len = mode->vtotal - mode->vdisplay;
844 v_sync_len = mode->vsync_end - mode->vsync_start;
846 h_sync_offset = mode->hsync_start - mode->hdisplay;
847 v_sync_offset = mode->vsync_start - mode->vdisplay;
849 mode_clock = mode->clock;
851 dtd->part1.clock = mode_clock;
853 dtd->part1.h_active = width & 0xff;
854 dtd->part1.h_blank = h_blank_len & 0xff;
855 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
856 ((h_blank_len >> 8) & 0xf);
857 dtd->part1.v_active = height & 0xff;
858 dtd->part1.v_blank = v_blank_len & 0xff;
859 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
860 ((v_blank_len >> 8) & 0xf);
862 dtd->part2.h_sync_off = h_sync_offset & 0xff;
863 dtd->part2.h_sync_width = h_sync_len & 0xff;
864 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
866 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
867 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
868 ((v_sync_len & 0x30) >> 4);
870 dtd->part2.dtd_flags = 0x18;
871 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
872 dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
873 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
874 dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
875 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
876 dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
878 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
881 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode *pmode,
882 const struct intel_sdvo_dtd *dtd)
884 struct drm_display_mode mode = {};
886 mode.hdisplay = dtd->part1.h_active;
887 mode.hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
888 mode.hsync_start = mode.hdisplay + dtd->part2.h_sync_off;
889 mode.hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
890 mode.hsync_end = mode.hsync_start + dtd->part2.h_sync_width;
891 mode.hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
892 mode.htotal = mode.hdisplay + dtd->part1.h_blank;
893 mode.htotal += (dtd->part1.h_high & 0xf) << 8;
895 mode.vdisplay = dtd->part1.v_active;
896 mode.vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
897 mode.vsync_start = mode.vdisplay;
898 mode.vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
899 mode.vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
900 mode.vsync_start += dtd->part2.v_sync_off_high & 0xc0;
901 mode.vsync_end = mode.vsync_start +
902 (dtd->part2.v_sync_off_width & 0xf);
903 mode.vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
904 mode.vtotal = mode.vdisplay + dtd->part1.v_blank;
905 mode.vtotal += (dtd->part1.v_high & 0xf) << 8;
907 mode.clock = dtd->part1.clock * 10;
909 if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
910 mode.flags |= DRM_MODE_FLAG_INTERLACE;
911 if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
912 mode.flags |= DRM_MODE_FLAG_PHSYNC;
914 mode.flags |= DRM_MODE_FLAG_NHSYNC;
915 if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
916 mode.flags |= DRM_MODE_FLAG_PVSYNC;
918 mode.flags |= DRM_MODE_FLAG_NVSYNC;
920 drm_mode_set_crtcinfo(&mode, 0);
922 drm_mode_copy(pmode, &mode);
925 static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
927 struct intel_sdvo_encode encode;
929 BUILD_BUG_ON(sizeof(encode) != 2);
930 return intel_sdvo_get_value(intel_sdvo,
931 SDVO_CMD_GET_SUPP_ENCODE,
932 &encode, sizeof(encode));
935 static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
938 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
941 static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
944 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
947 static bool intel_sdvo_set_pixel_replication(struct intel_sdvo *intel_sdvo,
950 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_PIXEL_REPLI,
954 static bool intel_sdvo_set_audio_state(struct intel_sdvo *intel_sdvo,
957 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_AUDIO_STAT,
961 static bool intel_sdvo_get_hbuf_size(struct intel_sdvo *intel_sdvo,
964 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
968 /* Buffer size is 0 based, hooray! However zero means zero. */
976 static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
985 intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
987 for (i = 0; i <= av_split; i++) {
988 set_buf_index[0] = i; set_buf_index[1] = 0;
989 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
991 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
992 intel_sdvo_read_response(encoder, &buf_size, 1);
995 for (j = 0; j <= buf_size; j += 8) {
996 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
998 intel_sdvo_read_response(encoder, pos, 8);
1005 static bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
1006 unsigned int if_index, u8 tx_rate,
1007 const u8 *data, unsigned int length)
1009 u8 set_buf_index[2] = { if_index, 0 };
1010 u8 hbuf_size, tmp[8];
1013 if (!intel_sdvo_set_value(intel_sdvo,
1014 SDVO_CMD_SET_HBUF_INDEX,
1018 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1021 DRM_DEBUG_KMS("writing sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1022 if_index, length, hbuf_size);
1024 if (hbuf_size < length)
1027 for (i = 0; i < hbuf_size; i += 8) {
1030 memcpy(tmp, data + i, min_t(unsigned, 8, length - i));
1032 if (!intel_sdvo_set_value(intel_sdvo,
1033 SDVO_CMD_SET_HBUF_DATA,
1038 return intel_sdvo_set_value(intel_sdvo,
1039 SDVO_CMD_SET_HBUF_TXRATE,
1043 static ssize_t intel_sdvo_read_infoframe(struct intel_sdvo *intel_sdvo,
1044 unsigned int if_index,
1045 u8 *data, unsigned int length)
1047 u8 set_buf_index[2] = { if_index, 0 };
1048 u8 hbuf_size, tx_rate, av_split;
1051 if (!intel_sdvo_get_value(intel_sdvo,
1052 SDVO_CMD_GET_HBUF_AV_SPLIT,
1056 if (av_split < if_index)
1059 if (!intel_sdvo_set_value(intel_sdvo,
1060 SDVO_CMD_SET_HBUF_INDEX,
1064 if (!intel_sdvo_get_value(intel_sdvo,
1065 SDVO_CMD_GET_HBUF_TXRATE,
1069 if (tx_rate == SDVO_HBUF_TX_DISABLED)
1072 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1075 DRM_DEBUG_KMS("reading sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1076 if_index, length, hbuf_size);
1078 hbuf_size = min_t(unsigned int, length, hbuf_size);
1080 for (i = 0; i < hbuf_size; i += 8) {
1081 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HBUF_DATA, NULL, 0))
1083 if (!intel_sdvo_read_response(intel_sdvo, &data[i],
1084 min_t(unsigned int, 8, hbuf_size - i)))
1091 static bool intel_sdvo_compute_avi_infoframe(struct intel_sdvo *intel_sdvo,
1092 struct intel_crtc_state *crtc_state,
1093 struct drm_connector_state *conn_state)
1095 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1096 struct hdmi_avi_infoframe *frame = &crtc_state->infoframes.avi.avi;
1097 const struct drm_display_mode *adjusted_mode =
1098 &crtc_state->hw.adjusted_mode;
1101 if (!crtc_state->has_hdmi_sink)
1104 crtc_state->infoframes.enable |=
1105 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1107 ret = drm_hdmi_avi_infoframe_from_display_mode(frame,
1108 conn_state->connector,
1113 drm_hdmi_avi_infoframe_quant_range(frame,
1114 conn_state->connector,
1116 crtc_state->limited_color_range ?
1117 HDMI_QUANTIZATION_RANGE_LIMITED :
1118 HDMI_QUANTIZATION_RANGE_FULL);
1120 ret = hdmi_avi_infoframe_check(frame);
1121 if (drm_WARN_ON(&dev_priv->drm, ret))
1127 static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1128 const struct intel_crtc_state *crtc_state)
1130 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1131 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1132 const union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1135 if ((crtc_state->infoframes.enable &
1136 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI)) == 0)
1139 if (drm_WARN_ON(&dev_priv->drm,
1140 frame->any.type != HDMI_INFOFRAME_TYPE_AVI))
1143 len = hdmi_infoframe_pack_only(frame, sdvo_data, sizeof(sdvo_data));
1144 if (drm_WARN_ON(&dev_priv->drm, len < 0))
1147 return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1152 static void intel_sdvo_get_avi_infoframe(struct intel_sdvo *intel_sdvo,
1153 struct intel_crtc_state *crtc_state)
1155 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1156 union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1160 if (!crtc_state->has_hdmi_sink)
1163 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1164 sdvo_data, sizeof(sdvo_data));
1166 DRM_DEBUG_KMS("failed to read AVI infoframe\n");
1168 } else if (len == 0) {
1172 crtc_state->infoframes.enable |=
1173 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1175 ret = hdmi_infoframe_unpack(frame, sdvo_data, len);
1177 DRM_DEBUG_KMS("Failed to unpack AVI infoframe\n");
1181 if (frame->any.type != HDMI_INFOFRAME_TYPE_AVI)
1182 DRM_DEBUG_KMS("Found the wrong infoframe type 0x%x (expected 0x%02x)\n",
1183 frame->any.type, HDMI_INFOFRAME_TYPE_AVI);
1186 static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo,
1187 const struct drm_connector_state *conn_state)
1189 struct intel_sdvo_tv_format format;
1192 format_map = 1 << conn_state->tv.mode;
1193 memset(&format, 0, sizeof(format));
1194 memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1196 BUILD_BUG_ON(sizeof(format) != 6);
1197 return intel_sdvo_set_value(intel_sdvo,
1198 SDVO_CMD_SET_TV_FORMAT,
1199 &format, sizeof(format));
1203 intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1204 const struct drm_display_mode *mode)
1206 struct intel_sdvo_dtd output_dtd;
1208 if (!intel_sdvo_set_target_output(intel_sdvo,
1209 intel_sdvo->attached_output))
1212 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1213 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1220 * Asks the sdvo controller for the preferred input mode given the output mode.
1221 * Unfortunately we have to set up the full output mode to do that.
1224 intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
1225 struct intel_sdvo_connector *intel_sdvo_connector,
1226 const struct drm_display_mode *mode,
1227 struct drm_display_mode *adjusted_mode)
1229 struct intel_sdvo_dtd input_dtd;
1231 /* Reset the input timing to the screen. Assume always input 0. */
1232 if (!intel_sdvo_set_target_input(intel_sdvo))
1235 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1236 intel_sdvo_connector,
1242 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1246 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1247 intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1252 static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_state *pipe_config)
1254 struct drm_i915_private *dev_priv = to_i915(pipe_config->uapi.crtc->dev);
1255 unsigned dotclock = pipe_config->port_clock;
1256 struct dpll *clock = &pipe_config->dpll;
1259 * SDVO TV has fixed PLL values depend on its clock range,
1260 * this mirrors vbios setting.
1262 if (dotclock >= 100000 && dotclock < 140500) {
1268 } else if (dotclock >= 140500 && dotclock <= 200000) {
1275 drm_WARN(&dev_priv->drm, 1,
1276 "SDVO TV clock out of range: %i\n", dotclock);
1279 pipe_config->clock_set = true;
1282 static bool intel_has_hdmi_sink(struct intel_sdvo *sdvo,
1283 const struct drm_connector_state *conn_state)
1285 return sdvo->has_hdmi_monitor &&
1286 READ_ONCE(to_intel_digital_connector_state(conn_state)->force_audio) != HDMI_AUDIO_OFF_DVI;
1289 static bool intel_sdvo_limited_color_range(struct intel_encoder *encoder,
1290 const struct intel_crtc_state *crtc_state,
1291 const struct drm_connector_state *conn_state)
1293 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1295 if ((intel_sdvo->colorimetry_cap & SDVO_COLORIMETRY_RGB220) == 0)
1298 return intel_hdmi_limited_color_range(crtc_state, conn_state);
1301 static int intel_sdvo_compute_config(struct intel_encoder *encoder,
1302 struct intel_crtc_state *pipe_config,
1303 struct drm_connector_state *conn_state)
1305 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1306 struct intel_sdvo_connector_state *intel_sdvo_state =
1307 to_intel_sdvo_connector_state(conn_state);
1308 struct intel_sdvo_connector *intel_sdvo_connector =
1309 to_intel_sdvo_connector(conn_state->connector);
1310 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1311 struct drm_display_mode *mode = &pipe_config->hw.mode;
1313 DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1314 pipe_config->pipe_bpp = 8*3;
1315 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
1317 if (HAS_PCH_SPLIT(to_i915(encoder->base.dev)))
1318 pipe_config->has_pch_encoder = true;
1321 * We need to construct preferred input timings based on our
1322 * output timings. To do that, we have to set the output
1323 * timings, even though this isn't really the right place in
1324 * the sequence to do it. Oh well.
1326 if (IS_TV(intel_sdvo_connector)) {
1327 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1330 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1331 intel_sdvo_connector,
1334 pipe_config->sdvo_tv_clock = true;
1335 } else if (IS_LVDS(intel_sdvo_connector)) {
1336 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1337 intel_sdvo_connector->base.panel.fixed_mode))
1340 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1341 intel_sdvo_connector,
1346 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
1350 * Make the CRTC code factor in the SDVO pixel multiplier. The
1351 * SDVO device will factor out the multiplier during mode_set.
1353 pipe_config->pixel_multiplier =
1354 intel_sdvo_get_pixel_multiplier(adjusted_mode);
1356 pipe_config->has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo, conn_state);
1358 if (pipe_config->has_hdmi_sink) {
1359 if (intel_sdvo_state->base.force_audio == HDMI_AUDIO_AUTO)
1360 pipe_config->has_audio = intel_sdvo->has_hdmi_audio;
1362 pipe_config->has_audio =
1363 intel_sdvo_state->base.force_audio == HDMI_AUDIO_ON;
1366 pipe_config->limited_color_range =
1367 intel_sdvo_limited_color_range(encoder, pipe_config,
1370 /* Clock computation needs to happen after pixel multiplier. */
1371 if (IS_TV(intel_sdvo_connector))
1372 i9xx_adjust_sdvo_tv_clock(pipe_config);
1374 if (conn_state->picture_aspect_ratio)
1375 adjusted_mode->picture_aspect_ratio =
1376 conn_state->picture_aspect_ratio;
1378 if (!intel_sdvo_compute_avi_infoframe(intel_sdvo,
1379 pipe_config, conn_state)) {
1380 DRM_DEBUG_KMS("bad AVI infoframe\n");
1387 #define UPDATE_PROPERTY(input, NAME) \
1390 intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_##NAME, &val, sizeof(val)); \
1393 static void intel_sdvo_update_props(struct intel_sdvo *intel_sdvo,
1394 const struct intel_sdvo_connector_state *sdvo_state)
1396 const struct drm_connector_state *conn_state = &sdvo_state->base.base;
1397 struct intel_sdvo_connector *intel_sdvo_conn =
1398 to_intel_sdvo_connector(conn_state->connector);
1401 if (intel_sdvo_conn->left)
1402 UPDATE_PROPERTY(sdvo_state->tv.overscan_h, OVERSCAN_H);
1404 if (intel_sdvo_conn->top)
1405 UPDATE_PROPERTY(sdvo_state->tv.overscan_v, OVERSCAN_V);
1407 if (intel_sdvo_conn->hpos)
1408 UPDATE_PROPERTY(sdvo_state->tv.hpos, HPOS);
1410 if (intel_sdvo_conn->vpos)
1411 UPDATE_PROPERTY(sdvo_state->tv.vpos, VPOS);
1413 if (intel_sdvo_conn->saturation)
1414 UPDATE_PROPERTY(conn_state->tv.saturation, SATURATION);
1416 if (intel_sdvo_conn->contrast)
1417 UPDATE_PROPERTY(conn_state->tv.contrast, CONTRAST);
1419 if (intel_sdvo_conn->hue)
1420 UPDATE_PROPERTY(conn_state->tv.hue, HUE);
1422 if (intel_sdvo_conn->brightness)
1423 UPDATE_PROPERTY(conn_state->tv.brightness, BRIGHTNESS);
1425 if (intel_sdvo_conn->sharpness)
1426 UPDATE_PROPERTY(sdvo_state->tv.sharpness, SHARPNESS);
1428 if (intel_sdvo_conn->flicker_filter)
1429 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter, FLICKER_FILTER);
1431 if (intel_sdvo_conn->flicker_filter_2d)
1432 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_2d, FLICKER_FILTER_2D);
1434 if (intel_sdvo_conn->flicker_filter_adaptive)
1435 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
1437 if (intel_sdvo_conn->tv_chroma_filter)
1438 UPDATE_PROPERTY(sdvo_state->tv.chroma_filter, TV_CHROMA_FILTER);
1440 if (intel_sdvo_conn->tv_luma_filter)
1441 UPDATE_PROPERTY(sdvo_state->tv.luma_filter, TV_LUMA_FILTER);
1443 if (intel_sdvo_conn->dot_crawl)
1444 UPDATE_PROPERTY(sdvo_state->tv.dot_crawl, DOT_CRAWL);
1446 #undef UPDATE_PROPERTY
1449 static void intel_sdvo_pre_enable(struct intel_atomic_state *state,
1450 struct intel_encoder *intel_encoder,
1451 const struct intel_crtc_state *crtc_state,
1452 const struct drm_connector_state *conn_state)
1454 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
1455 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1456 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
1457 const struct intel_sdvo_connector_state *sdvo_state =
1458 to_intel_sdvo_connector_state(conn_state);
1459 const struct intel_sdvo_connector *intel_sdvo_connector =
1460 to_intel_sdvo_connector(conn_state->connector);
1461 const struct drm_display_mode *mode = &crtc_state->hw.mode;
1462 struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
1464 struct intel_sdvo_in_out_map in_out;
1465 struct intel_sdvo_dtd input_dtd, output_dtd;
1468 intel_sdvo_update_props(intel_sdvo, sdvo_state);
1471 * First, set the input mapping for the first input to our controlled
1472 * output. This is only correct if we're a single-input device, in
1473 * which case the first input is the output from the appropriate SDVO
1474 * channel on the motherboard. In a two-input device, the first input
1475 * will be SDVOB and the second SDVOC.
1477 in_out.in0 = intel_sdvo->attached_output;
1480 intel_sdvo_set_value(intel_sdvo,
1481 SDVO_CMD_SET_IN_OUT_MAP,
1482 &in_out, sizeof(in_out));
1484 /* Set the output timings to the screen */
1485 if (!intel_sdvo_set_target_output(intel_sdvo,
1486 intel_sdvo->attached_output))
1489 /* lvds has a special fixed output timing. */
1490 if (IS_LVDS(intel_sdvo_connector))
1491 intel_sdvo_get_dtd_from_mode(&output_dtd,
1492 intel_sdvo_connector->base.panel.fixed_mode);
1494 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1495 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1496 drm_info(&dev_priv->drm,
1497 "Setting output timings on %s failed\n",
1498 SDVO_NAME(intel_sdvo));
1500 /* Set the input timing to the screen. Assume always input 0. */
1501 if (!intel_sdvo_set_target_input(intel_sdvo))
1504 if (crtc_state->has_hdmi_sink) {
1505 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
1506 intel_sdvo_set_colorimetry(intel_sdvo,
1507 crtc_state->limited_color_range ?
1508 SDVO_COLORIMETRY_RGB220 :
1509 SDVO_COLORIMETRY_RGB256);
1510 intel_sdvo_set_avi_infoframe(intel_sdvo, crtc_state);
1511 intel_sdvo_set_pixel_replication(intel_sdvo,
1512 !!(adjusted_mode->flags &
1513 DRM_MODE_FLAG_DBLCLK));
1515 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
1517 if (IS_TV(intel_sdvo_connector) &&
1518 !intel_sdvo_set_tv_format(intel_sdvo, conn_state))
1521 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1523 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector))
1524 input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1525 if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1526 drm_info(&dev_priv->drm,
1527 "Setting input timings on %s failed\n",
1528 SDVO_NAME(intel_sdvo));
1530 switch (crtc_state->pixel_multiplier) {
1532 drm_WARN(&dev_priv->drm, 1,
1533 "unknown pixel multiplier specified\n");
1535 case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1536 case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1537 case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1539 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1542 /* Set the SDVO control regs. */
1543 if (INTEL_GEN(dev_priv) >= 4) {
1544 /* The real mode polarity is set by the SDVO commands, using
1545 * struct intel_sdvo_dtd. */
1546 sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
1547 if (INTEL_GEN(dev_priv) < 5)
1548 sdvox |= SDVO_BORDER_ENABLE;
1550 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1551 if (intel_sdvo->port == PORT_B)
1552 sdvox &= SDVOB_PRESERVE_MASK;
1554 sdvox &= SDVOC_PRESERVE_MASK;
1555 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1558 if (HAS_PCH_CPT(dev_priv))
1559 sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
1561 sdvox |= SDVO_PIPE_SEL(crtc->pipe);
1563 if (INTEL_GEN(dev_priv) >= 4) {
1564 /* done in crtc_mode_set as the dpll_md reg must be written early */
1565 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
1566 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
1567 /* done in crtc_mode_set as it lives inside the dpll register */
1569 sdvox |= (crtc_state->pixel_multiplier - 1)
1570 << SDVO_PORT_MULTIPLY_SHIFT;
1573 if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
1574 INTEL_GEN(dev_priv) < 5)
1575 sdvox |= SDVO_STALL_SELECT;
1576 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1579 static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1581 struct intel_sdvo_connector *intel_sdvo_connector =
1582 to_intel_sdvo_connector(&connector->base);
1583 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1584 u16 active_outputs = 0;
1586 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1588 return active_outputs & intel_sdvo_connector->output_flag;
1591 bool intel_sdvo_port_enabled(struct drm_i915_private *dev_priv,
1592 i915_reg_t sdvo_reg, enum pipe *pipe)
1596 val = intel_de_read(dev_priv, sdvo_reg);
1598 /* asserts want to know the pipe even if the port is disabled */
1599 if (HAS_PCH_CPT(dev_priv))
1600 *pipe = (val & SDVO_PIPE_SEL_MASK_CPT) >> SDVO_PIPE_SEL_SHIFT_CPT;
1601 else if (IS_CHERRYVIEW(dev_priv))
1602 *pipe = (val & SDVO_PIPE_SEL_MASK_CHV) >> SDVO_PIPE_SEL_SHIFT_CHV;
1604 *pipe = (val & SDVO_PIPE_SEL_MASK) >> SDVO_PIPE_SEL_SHIFT;
1606 return val & SDVO_ENABLE;
1609 static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1612 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1613 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1614 u16 active_outputs = 0;
1617 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1619 ret = intel_sdvo_port_enabled(dev_priv, intel_sdvo->sdvo_reg, pipe);
1621 return ret || active_outputs;
1624 static void intel_sdvo_get_config(struct intel_encoder *encoder,
1625 struct intel_crtc_state *pipe_config)
1627 struct drm_device *dev = encoder->base.dev;
1628 struct drm_i915_private *dev_priv = to_i915(dev);
1629 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1630 struct intel_sdvo_dtd dtd;
1631 int encoder_pixel_multiplier = 0;
1633 u32 flags = 0, sdvox;
1637 pipe_config->output_types |= BIT(INTEL_OUTPUT_SDVO);
1639 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1641 ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
1644 * Some sdvo encoders are not spec compliant and don't
1645 * implement the mandatory get_timings function.
1647 drm_dbg(&dev_priv->drm, "failed to retrieve SDVO DTD\n");
1648 pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
1650 if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1651 flags |= DRM_MODE_FLAG_PHSYNC;
1653 flags |= DRM_MODE_FLAG_NHSYNC;
1655 if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1656 flags |= DRM_MODE_FLAG_PVSYNC;
1658 flags |= DRM_MODE_FLAG_NVSYNC;
1661 pipe_config->hw.adjusted_mode.flags |= flags;
1664 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1665 * the sdvo port register, on all other platforms it is part of the dpll
1666 * state. Since the general pipe state readout happens before the
1667 * encoder->get_config we so already have a valid pixel multplier on all
1670 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
1671 pipe_config->pixel_multiplier =
1672 ((sdvox & SDVO_PORT_MULTIPLY_MASK)
1673 >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
1676 dotclock = pipe_config->port_clock;
1678 if (pipe_config->pixel_multiplier)
1679 dotclock /= pipe_config->pixel_multiplier;
1681 pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
1683 /* Cross check the port pixel multiplier with the sdvo encoder state. */
1684 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
1687 case SDVO_CLOCK_RATE_MULT_1X:
1688 encoder_pixel_multiplier = 1;
1690 case SDVO_CLOCK_RATE_MULT_2X:
1691 encoder_pixel_multiplier = 2;
1693 case SDVO_CLOCK_RATE_MULT_4X:
1694 encoder_pixel_multiplier = 4;
1700 encoder_pixel_multiplier != pipe_config->pixel_multiplier,
1701 "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1702 pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1704 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_COLORIMETRY,
1706 if (val == SDVO_COLORIMETRY_RGB220)
1707 pipe_config->limited_color_range = true;
1710 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_AUDIO_STAT,
1712 u8 mask = SDVO_AUDIO_ELD_VALID | SDVO_AUDIO_PRESENCE_DETECT;
1714 if ((val & mask) == mask)
1715 pipe_config->has_audio = true;
1718 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE,
1720 if (val == SDVO_ENCODE_HDMI)
1721 pipe_config->has_hdmi_sink = true;
1724 intel_sdvo_get_avi_infoframe(intel_sdvo, pipe_config);
1727 static void intel_sdvo_disable_audio(struct intel_sdvo *intel_sdvo)
1729 intel_sdvo_set_audio_state(intel_sdvo, 0);
1732 static void intel_sdvo_enable_audio(struct intel_sdvo *intel_sdvo,
1733 const struct intel_crtc_state *crtc_state,
1734 const struct drm_connector_state *conn_state)
1736 const struct drm_display_mode *adjusted_mode =
1737 &crtc_state->hw.adjusted_mode;
1738 struct drm_connector *connector = conn_state->connector;
1739 u8 *eld = connector->eld;
1741 eld[6] = drm_av_sync_delay(connector, adjusted_mode) / 2;
1743 intel_sdvo_set_audio_state(intel_sdvo, 0);
1745 intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_ELD,
1746 SDVO_HBUF_TX_DISABLED,
1747 eld, drm_eld_size(eld));
1749 intel_sdvo_set_audio_state(intel_sdvo, SDVO_AUDIO_ELD_VALID |
1750 SDVO_AUDIO_PRESENCE_DETECT);
1753 static void intel_disable_sdvo(struct intel_atomic_state *state,
1754 struct intel_encoder *encoder,
1755 const struct intel_crtc_state *old_crtc_state,
1756 const struct drm_connector_state *conn_state)
1758 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1759 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1760 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1763 if (old_crtc_state->has_audio)
1764 intel_sdvo_disable_audio(intel_sdvo);
1766 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1768 intel_sdvo_set_encoder_power_state(intel_sdvo,
1771 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1773 temp &= ~SDVO_ENABLE;
1774 intel_sdvo_write_sdvox(intel_sdvo, temp);
1777 * HW workaround for IBX, we need to move the port
1778 * to transcoder A after disabling it to allow the
1779 * matching DP port to be enabled on transcoder A.
1781 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1783 * We get CPU/PCH FIFO underruns on the other pipe when
1784 * doing the workaround. Sweep them under the rug.
1786 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1787 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1789 temp &= ~SDVO_PIPE_SEL_MASK;
1790 temp |= SDVO_ENABLE | SDVO_PIPE_SEL(PIPE_A);
1791 intel_sdvo_write_sdvox(intel_sdvo, temp);
1793 temp &= ~SDVO_ENABLE;
1794 intel_sdvo_write_sdvox(intel_sdvo, temp);
1796 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1797 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1798 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1802 static void pch_disable_sdvo(struct intel_atomic_state *state,
1803 struct intel_encoder *encoder,
1804 const struct intel_crtc_state *old_crtc_state,
1805 const struct drm_connector_state *old_conn_state)
1809 static void pch_post_disable_sdvo(struct intel_atomic_state *state,
1810 struct intel_encoder *encoder,
1811 const struct intel_crtc_state *old_crtc_state,
1812 const struct drm_connector_state *old_conn_state)
1814 intel_disable_sdvo(state, encoder, old_crtc_state, old_conn_state);
1817 static void intel_enable_sdvo(struct intel_atomic_state *state,
1818 struct intel_encoder *encoder,
1819 const struct intel_crtc_state *pipe_config,
1820 const struct drm_connector_state *conn_state)
1822 struct drm_device *dev = encoder->base.dev;
1823 struct drm_i915_private *dev_priv = to_i915(dev);
1824 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1825 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
1827 bool input1, input2;
1831 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1832 temp |= SDVO_ENABLE;
1833 intel_sdvo_write_sdvox(intel_sdvo, temp);
1835 for (i = 0; i < 2; i++)
1836 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
1838 success = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1840 * Warn if the device reported failure to sync.
1842 * A lot of SDVO devices fail to notify of sync, but it's
1843 * a given it the status is a success, we succeeded.
1845 if (success && !input1) {
1846 drm_dbg_kms(&dev_priv->drm,
1847 "First %s output reported failure to "
1848 "sync\n", SDVO_NAME(intel_sdvo));
1852 intel_sdvo_set_encoder_power_state(intel_sdvo,
1854 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1856 if (pipe_config->has_audio)
1857 intel_sdvo_enable_audio(intel_sdvo, pipe_config, conn_state);
1860 static enum drm_mode_status
1861 intel_sdvo_mode_valid(struct drm_connector *connector,
1862 struct drm_display_mode *mode)
1864 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
1865 struct intel_sdvo_connector *intel_sdvo_connector =
1866 to_intel_sdvo_connector(connector);
1867 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1868 bool has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo, connector->state);
1869 int clock = mode->clock;
1871 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1872 return MODE_NO_DBLESCAN;
1875 if (clock > max_dotclk)
1876 return MODE_CLOCK_HIGH;
1878 if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
1880 return MODE_CLOCK_LOW;
1884 if (intel_sdvo->pixel_clock_min > clock)
1885 return MODE_CLOCK_LOW;
1887 if (intel_sdvo->pixel_clock_max < clock)
1888 return MODE_CLOCK_HIGH;
1890 if (IS_LVDS(intel_sdvo_connector)) {
1891 const struct drm_display_mode *fixed_mode =
1892 intel_sdvo_connector->base.panel.fixed_mode;
1894 if (mode->hdisplay > fixed_mode->hdisplay)
1897 if (mode->vdisplay > fixed_mode->vdisplay)
1904 static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1906 BUILD_BUG_ON(sizeof(*caps) != 8);
1907 if (!intel_sdvo_get_value(intel_sdvo,
1908 SDVO_CMD_GET_DEVICE_CAPS,
1909 caps, sizeof(*caps)))
1912 DRM_DEBUG_KMS("SDVO capabilities:\n"
1915 " device_rev_id: %d\n"
1916 " sdvo_version_major: %d\n"
1917 " sdvo_version_minor: %d\n"
1918 " sdvo_inputs_mask: %d\n"
1919 " smooth_scaling: %d\n"
1920 " sharp_scaling: %d\n"
1922 " down_scaling: %d\n"
1923 " stall_support: %d\n"
1924 " output_flags: %d\n",
1927 caps->device_rev_id,
1928 caps->sdvo_version_major,
1929 caps->sdvo_version_minor,
1930 caps->sdvo_inputs_mask,
1931 caps->smooth_scaling,
1932 caps->sharp_scaling,
1935 caps->stall_support,
1936 caps->output_flags);
1941 static u8 intel_sdvo_get_colorimetry_cap(struct intel_sdvo *intel_sdvo)
1945 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_COLORIMETRY_CAP,
1947 return SDVO_COLORIMETRY_RGB256;
1952 static u16 intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1954 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1957 if (!I915_HAS_HOTPLUG(dev_priv))
1961 * HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1964 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
1967 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1968 &hotplug, sizeof(hotplug)))
1974 static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1976 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1978 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
1979 &intel_sdvo->hotplug_active, 2);
1982 static enum intel_hotplug_state
1983 intel_sdvo_hotplug(struct intel_encoder *encoder,
1984 struct intel_connector *connector)
1986 intel_sdvo_enable_hotplug(encoder);
1988 return intel_encoder_hotplug(encoder, connector);
1992 intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
1994 /* Is there more than one type of output? */
1995 return hweight16(intel_sdvo->caps.output_flags) > 1;
1998 static struct edid *
1999 intel_sdvo_get_edid(struct drm_connector *connector)
2001 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2002 return drm_get_edid(connector, &sdvo->ddc);
2005 /* Mac mini hack -- use the same DDC as the analog connector */
2006 static struct edid *
2007 intel_sdvo_get_analog_edid(struct drm_connector *connector)
2009 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2011 return drm_get_edid(connector,
2012 intel_gmbus_get_adapter(dev_priv,
2013 dev_priv->vbt.crt_ddc_pin));
2016 static enum drm_connector_status
2017 intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
2019 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2020 struct intel_sdvo_connector *intel_sdvo_connector =
2021 to_intel_sdvo_connector(connector);
2022 enum drm_connector_status status;
2025 edid = intel_sdvo_get_edid(connector);
2027 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
2028 u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
2031 * Don't use the 1 as the argument of DDC bus switch to get
2032 * the EDID. It is used for SDVO SPD ROM.
2034 for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
2035 intel_sdvo->ddc_bus = ddc;
2036 edid = intel_sdvo_get_edid(connector);
2041 * If we found the EDID on the other bus,
2042 * assume that is the correct DDC bus.
2045 intel_sdvo->ddc_bus = saved_ddc;
2049 * When there is no edid and no monitor is connected with VGA
2050 * port, try to use the CRT ddc to read the EDID for DVI-connector.
2053 edid = intel_sdvo_get_analog_edid(connector);
2055 status = connector_status_unknown;
2057 /* DDC bus is shared, match EDID to connector type */
2058 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
2059 status = connector_status_connected;
2060 if (intel_sdvo_connector->is_hdmi) {
2061 intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
2062 intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
2065 status = connector_status_disconnected;
2073 intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
2076 bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
2077 bool connector_is_digital = !!IS_DIGITAL(sdvo);
2079 DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
2080 connector_is_digital, monitor_is_digital);
2081 return connector_is_digital == monitor_is_digital;
2084 static enum drm_connector_status
2085 intel_sdvo_detect(struct drm_connector *connector, bool force)
2088 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2089 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2090 enum drm_connector_status ret;
2092 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2093 connector->base.id, connector->name);
2095 if (!intel_sdvo_get_value(intel_sdvo,
2096 SDVO_CMD_GET_ATTACHED_DISPLAYS,
2098 return connector_status_unknown;
2100 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
2101 response & 0xff, response >> 8,
2102 intel_sdvo_connector->output_flag);
2105 return connector_status_disconnected;
2107 intel_sdvo->attached_output = response;
2109 intel_sdvo->has_hdmi_monitor = false;
2110 intel_sdvo->has_hdmi_audio = false;
2112 if ((intel_sdvo_connector->output_flag & response) == 0)
2113 ret = connector_status_disconnected;
2114 else if (IS_TMDS(intel_sdvo_connector))
2115 ret = intel_sdvo_tmds_sink_detect(connector);
2119 /* if we have an edid check it matches the connection */
2120 edid = intel_sdvo_get_edid(connector);
2122 edid = intel_sdvo_get_analog_edid(connector);
2124 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
2126 ret = connector_status_connected;
2128 ret = connector_status_disconnected;
2132 ret = connector_status_connected;
2138 static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
2142 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2143 connector->base.id, connector->name);
2145 /* set the bus switch and get the modes */
2146 edid = intel_sdvo_get_edid(connector);
2149 * Mac mini hack. On this device, the DVI-I connector shares one DDC
2150 * link between analog and digital outputs. So, if the regular SDVO
2151 * DDC fails, check to see if the analog output is disconnected, in
2152 * which case we'll look there for the digital DDC data.
2155 edid = intel_sdvo_get_analog_edid(connector);
2158 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
2160 drm_connector_update_edid_property(connector, edid);
2161 drm_add_edid_modes(connector, edid);
2169 * Set of SDVO TV modes.
2170 * Note! This is in reply order (see loop in get_tv_modes).
2171 * XXX: all 60Hz refresh?
2173 static const struct drm_display_mode sdvo_tv_modes[] = {
2174 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
2175 416, 0, 200, 201, 232, 233, 0,
2176 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2177 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
2178 416, 0, 240, 241, 272, 273, 0,
2179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2180 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
2181 496, 0, 300, 301, 332, 333, 0,
2182 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2183 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
2184 736, 0, 350, 351, 382, 383, 0,
2185 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2186 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
2187 736, 0, 400, 401, 432, 433, 0,
2188 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2189 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
2190 736, 0, 480, 481, 512, 513, 0,
2191 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2192 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
2193 800, 0, 480, 481, 512, 513, 0,
2194 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2195 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
2196 800, 0, 576, 577, 608, 609, 0,
2197 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2198 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
2199 816, 0, 350, 351, 382, 383, 0,
2200 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2201 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
2202 816, 0, 400, 401, 432, 433, 0,
2203 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2204 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
2205 816, 0, 480, 481, 512, 513, 0,
2206 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2207 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
2208 816, 0, 540, 541, 572, 573, 0,
2209 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2210 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
2211 816, 0, 576, 577, 608, 609, 0,
2212 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2213 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
2214 864, 0, 576, 577, 608, 609, 0,
2215 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2216 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
2217 896, 0, 600, 601, 632, 633, 0,
2218 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2219 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
2220 928, 0, 624, 625, 656, 657, 0,
2221 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2222 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
2223 1016, 0, 766, 767, 798, 799, 0,
2224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2225 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
2226 1120, 0, 768, 769, 800, 801, 0,
2227 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2228 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
2229 1376, 0, 1024, 1025, 1056, 1057, 0,
2230 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2233 static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
2235 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2236 const struct drm_connector_state *conn_state = connector->state;
2237 struct intel_sdvo_sdtv_resolution_request tv_res;
2238 u32 reply = 0, format_map = 0;
2241 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2242 connector->base.id, connector->name);
2245 * Read the list of supported input resolutions for the selected TV
2248 format_map = 1 << conn_state->tv.mode;
2249 memcpy(&tv_res, &format_map,
2250 min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
2252 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
2255 BUILD_BUG_ON(sizeof(tv_res) != 3);
2256 if (!intel_sdvo_write_cmd(intel_sdvo,
2257 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
2258 &tv_res, sizeof(tv_res)))
2260 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
2263 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
2264 if (reply & (1 << i)) {
2265 struct drm_display_mode *nmode;
2266 nmode = drm_mode_duplicate(connector->dev,
2269 drm_mode_probed_add(connector, nmode);
2273 static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
2275 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2276 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2277 struct drm_display_mode *newmode;
2279 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s]\n",
2280 connector->base.id, connector->name);
2283 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
2284 * SDVO->LVDS transcoders can't cope with the EDID mode.
2286 if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
2287 newmode = drm_mode_duplicate(connector->dev,
2288 dev_priv->vbt.sdvo_lvds_vbt_mode);
2289 if (newmode != NULL) {
2290 /* Guarantee the mode is preferred */
2291 newmode->type = (DRM_MODE_TYPE_PREFERRED |
2292 DRM_MODE_TYPE_DRIVER);
2293 drm_mode_probed_add(connector, newmode);
2298 * Attempt to get the mode list from DDC.
2299 * Assume that the preferred modes are
2300 * arranged in priority order.
2302 intel_ddc_get_modes(connector, &intel_sdvo->ddc);
2305 static int intel_sdvo_get_modes(struct drm_connector *connector)
2307 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2309 if (IS_TV(intel_sdvo_connector))
2310 intel_sdvo_get_tv_modes(connector);
2311 else if (IS_LVDS(intel_sdvo_connector))
2312 intel_sdvo_get_lvds_modes(connector);
2314 intel_sdvo_get_ddc_modes(connector);
2316 return !list_empty(&connector->probed_modes);
2320 intel_sdvo_connector_atomic_get_property(struct drm_connector *connector,
2321 const struct drm_connector_state *state,
2322 struct drm_property *property,
2325 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2326 const struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state((void *)state);
2328 if (property == intel_sdvo_connector->tv_format) {
2331 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2332 if (state->tv.mode == intel_sdvo_connector->tv_format_supported[i]) {
2338 drm_WARN_ON(connector->dev, 1);
2340 } else if (property == intel_sdvo_connector->top ||
2341 property == intel_sdvo_connector->bottom)
2342 *val = intel_sdvo_connector->max_vscan - sdvo_state->tv.overscan_v;
2343 else if (property == intel_sdvo_connector->left ||
2344 property == intel_sdvo_connector->right)
2345 *val = intel_sdvo_connector->max_hscan - sdvo_state->tv.overscan_h;
2346 else if (property == intel_sdvo_connector->hpos)
2347 *val = sdvo_state->tv.hpos;
2348 else if (property == intel_sdvo_connector->vpos)
2349 *val = sdvo_state->tv.vpos;
2350 else if (property == intel_sdvo_connector->saturation)
2351 *val = state->tv.saturation;
2352 else if (property == intel_sdvo_connector->contrast)
2353 *val = state->tv.contrast;
2354 else if (property == intel_sdvo_connector->hue)
2355 *val = state->tv.hue;
2356 else if (property == intel_sdvo_connector->brightness)
2357 *val = state->tv.brightness;
2358 else if (property == intel_sdvo_connector->sharpness)
2359 *val = sdvo_state->tv.sharpness;
2360 else if (property == intel_sdvo_connector->flicker_filter)
2361 *val = sdvo_state->tv.flicker_filter;
2362 else if (property == intel_sdvo_connector->flicker_filter_2d)
2363 *val = sdvo_state->tv.flicker_filter_2d;
2364 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2365 *val = sdvo_state->tv.flicker_filter_adaptive;
2366 else if (property == intel_sdvo_connector->tv_chroma_filter)
2367 *val = sdvo_state->tv.chroma_filter;
2368 else if (property == intel_sdvo_connector->tv_luma_filter)
2369 *val = sdvo_state->tv.luma_filter;
2370 else if (property == intel_sdvo_connector->dot_crawl)
2371 *val = sdvo_state->tv.dot_crawl;
2373 return intel_digital_connector_atomic_get_property(connector, state, property, val);
2379 intel_sdvo_connector_atomic_set_property(struct drm_connector *connector,
2380 struct drm_connector_state *state,
2381 struct drm_property *property,
2384 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2385 struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state(state);
2387 if (property == intel_sdvo_connector->tv_format) {
2388 state->tv.mode = intel_sdvo_connector->tv_format_supported[val];
2391 struct drm_crtc_state *crtc_state =
2392 drm_atomic_get_new_crtc_state(state->state, state->crtc);
2394 crtc_state->connectors_changed = true;
2396 } else if (property == intel_sdvo_connector->top ||
2397 property == intel_sdvo_connector->bottom)
2398 /* Cannot set these independent from each other */
2399 sdvo_state->tv.overscan_v = intel_sdvo_connector->max_vscan - val;
2400 else if (property == intel_sdvo_connector->left ||
2401 property == intel_sdvo_connector->right)
2402 /* Cannot set these independent from each other */
2403 sdvo_state->tv.overscan_h = intel_sdvo_connector->max_hscan - val;
2404 else if (property == intel_sdvo_connector->hpos)
2405 sdvo_state->tv.hpos = val;
2406 else if (property == intel_sdvo_connector->vpos)
2407 sdvo_state->tv.vpos = val;
2408 else if (property == intel_sdvo_connector->saturation)
2409 state->tv.saturation = val;
2410 else if (property == intel_sdvo_connector->contrast)
2411 state->tv.contrast = val;
2412 else if (property == intel_sdvo_connector->hue)
2413 state->tv.hue = val;
2414 else if (property == intel_sdvo_connector->brightness)
2415 state->tv.brightness = val;
2416 else if (property == intel_sdvo_connector->sharpness)
2417 sdvo_state->tv.sharpness = val;
2418 else if (property == intel_sdvo_connector->flicker_filter)
2419 sdvo_state->tv.flicker_filter = val;
2420 else if (property == intel_sdvo_connector->flicker_filter_2d)
2421 sdvo_state->tv.flicker_filter_2d = val;
2422 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2423 sdvo_state->tv.flicker_filter_adaptive = val;
2424 else if (property == intel_sdvo_connector->tv_chroma_filter)
2425 sdvo_state->tv.chroma_filter = val;
2426 else if (property == intel_sdvo_connector->tv_luma_filter)
2427 sdvo_state->tv.luma_filter = val;
2428 else if (property == intel_sdvo_connector->dot_crawl)
2429 sdvo_state->tv.dot_crawl = val;
2431 return intel_digital_connector_atomic_set_property(connector, state, property, val);
2437 intel_sdvo_connector_register(struct drm_connector *connector)
2439 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2442 ret = intel_connector_register(connector);
2446 return sysfs_create_link(&connector->kdev->kobj,
2447 &sdvo->ddc.dev.kobj,
2448 sdvo->ddc.dev.kobj.name);
2452 intel_sdvo_connector_unregister(struct drm_connector *connector)
2454 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2456 sysfs_remove_link(&connector->kdev->kobj,
2457 sdvo->ddc.dev.kobj.name);
2458 intel_connector_unregister(connector);
2461 static struct drm_connector_state *
2462 intel_sdvo_connector_duplicate_state(struct drm_connector *connector)
2464 struct intel_sdvo_connector_state *state;
2466 state = kmemdup(connector->state, sizeof(*state), GFP_KERNEL);
2470 __drm_atomic_helper_connector_duplicate_state(connector, &state->base.base);
2471 return &state->base.base;
2474 static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
2475 .detect = intel_sdvo_detect,
2476 .fill_modes = drm_helper_probe_single_connector_modes,
2477 .atomic_get_property = intel_sdvo_connector_atomic_get_property,
2478 .atomic_set_property = intel_sdvo_connector_atomic_set_property,
2479 .late_register = intel_sdvo_connector_register,
2480 .early_unregister = intel_sdvo_connector_unregister,
2481 .destroy = intel_connector_destroy,
2482 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
2483 .atomic_duplicate_state = intel_sdvo_connector_duplicate_state,
2486 static int intel_sdvo_atomic_check(struct drm_connector *conn,
2487 struct drm_atomic_state *state)
2489 struct drm_connector_state *new_conn_state =
2490 drm_atomic_get_new_connector_state(state, conn);
2491 struct drm_connector_state *old_conn_state =
2492 drm_atomic_get_old_connector_state(state, conn);
2493 struct intel_sdvo_connector_state *old_state =
2494 to_intel_sdvo_connector_state(old_conn_state);
2495 struct intel_sdvo_connector_state *new_state =
2496 to_intel_sdvo_connector_state(new_conn_state);
2498 if (new_conn_state->crtc &&
2499 (memcmp(&old_state->tv, &new_state->tv, sizeof(old_state->tv)) ||
2500 memcmp(&old_conn_state->tv, &new_conn_state->tv, sizeof(old_conn_state->tv)))) {
2501 struct drm_crtc_state *crtc_state =
2502 drm_atomic_get_new_crtc_state(state,
2503 new_conn_state->crtc);
2505 crtc_state->connectors_changed = true;
2508 return intel_digital_connector_atomic_check(conn, state);
2511 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2512 .get_modes = intel_sdvo_get_modes,
2513 .mode_valid = intel_sdvo_mode_valid,
2514 .atomic_check = intel_sdvo_atomic_check,
2517 static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2519 struct intel_sdvo *intel_sdvo = to_sdvo(to_intel_encoder(encoder));
2521 i2c_del_adapter(&intel_sdvo->ddc);
2522 intel_encoder_destroy(encoder);
2525 static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2526 .destroy = intel_sdvo_enc_destroy,
2530 intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
2533 unsigned int num_bits;
2536 * Make a mask of outputs less than or equal to our own priority in the
2539 switch (sdvo->controlled_output) {
2540 case SDVO_OUTPUT_LVDS1:
2541 mask |= SDVO_OUTPUT_LVDS1;
2543 case SDVO_OUTPUT_LVDS0:
2544 mask |= SDVO_OUTPUT_LVDS0;
2546 case SDVO_OUTPUT_TMDS1:
2547 mask |= SDVO_OUTPUT_TMDS1;
2549 case SDVO_OUTPUT_TMDS0:
2550 mask |= SDVO_OUTPUT_TMDS0;
2552 case SDVO_OUTPUT_RGB1:
2553 mask |= SDVO_OUTPUT_RGB1;
2555 case SDVO_OUTPUT_RGB0:
2556 mask |= SDVO_OUTPUT_RGB0;
2560 /* Count bits to find what number we are in the priority list. */
2561 mask &= sdvo->caps.output_flags;
2562 num_bits = hweight16(mask);
2563 /* If more than 3 outputs, default to DDC bus 3 for now. */
2567 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2568 sdvo->ddc_bus = 1 << num_bits;
2572 * Choose the appropriate DDC bus for control bus switch command for this
2573 * SDVO output based on the controlled output.
2575 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2576 * outputs, then LVDS outputs.
2579 intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
2580 struct intel_sdvo *sdvo)
2582 struct sdvo_device_mapping *mapping;
2584 if (sdvo->port == PORT_B)
2585 mapping = &dev_priv->vbt.sdvo_mappings[0];
2587 mapping = &dev_priv->vbt.sdvo_mappings[1];
2589 if (mapping->initialized)
2590 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
2592 intel_sdvo_guess_ddc_bus(sdvo);
2596 intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
2597 struct intel_sdvo *sdvo)
2599 struct sdvo_device_mapping *mapping;
2602 if (sdvo->port == PORT_B)
2603 mapping = &dev_priv->vbt.sdvo_mappings[0];
2605 mapping = &dev_priv->vbt.sdvo_mappings[1];
2607 if (mapping->initialized &&
2608 intel_gmbus_is_valid_pin(dev_priv, mapping->i2c_pin))
2609 pin = mapping->i2c_pin;
2611 pin = GMBUS_PIN_DPB;
2613 sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
2616 * With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
2617 * our code totally fails once we start using gmbus. Hence fall back to
2618 * bit banging for now.
2620 intel_gmbus_force_bit(sdvo->i2c, true);
2623 /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
2625 intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
2627 intel_gmbus_force_bit(sdvo->i2c, false);
2631 intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)
2633 return intel_sdvo_check_supp_encode(intel_sdvo);
2637 intel_sdvo_get_slave_addr(struct drm_i915_private *dev_priv,
2638 struct intel_sdvo *sdvo)
2640 struct sdvo_device_mapping *my_mapping, *other_mapping;
2642 if (sdvo->port == PORT_B) {
2643 my_mapping = &dev_priv->vbt.sdvo_mappings[0];
2644 other_mapping = &dev_priv->vbt.sdvo_mappings[1];
2646 my_mapping = &dev_priv->vbt.sdvo_mappings[1];
2647 other_mapping = &dev_priv->vbt.sdvo_mappings[0];
2650 /* If the BIOS described our SDVO device, take advantage of it. */
2651 if (my_mapping->slave_addr)
2652 return my_mapping->slave_addr;
2655 * If the BIOS only described a different SDVO device, use the
2656 * address that it isn't using.
2658 if (other_mapping->slave_addr) {
2659 if (other_mapping->slave_addr == 0x70)
2666 * No SDVO device info is found for another DVO port,
2667 * so use mapping assumption we had before BIOS parsing.
2669 if (sdvo->port == PORT_B)
2676 intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2677 struct intel_sdvo *encoder)
2679 struct drm_connector *drm_connector;
2682 drm_connector = &connector->base.base;
2683 ret = drm_connector_init(encoder->base.base.dev,
2685 &intel_sdvo_connector_funcs,
2686 connector->base.base.connector_type);
2690 drm_connector_helper_add(drm_connector,
2691 &intel_sdvo_connector_helper_funcs);
2693 connector->base.base.interlace_allowed = 1;
2694 connector->base.base.doublescan_allowed = 0;
2695 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2696 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2698 intel_connector_attach_encoder(&connector->base, &encoder->base);
2704 intel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
2705 struct intel_sdvo_connector *connector)
2707 intel_attach_force_audio_property(&connector->base.base);
2708 if (intel_sdvo->colorimetry_cap & SDVO_COLORIMETRY_RGB220)
2709 intel_attach_broadcast_rgb_property(&connector->base.base);
2710 intel_attach_aspect_ratio_property(&connector->base.base);
2713 static struct intel_sdvo_connector *intel_sdvo_connector_alloc(void)
2715 struct intel_sdvo_connector *sdvo_connector;
2716 struct intel_sdvo_connector_state *conn_state;
2718 sdvo_connector = kzalloc(sizeof(*sdvo_connector), GFP_KERNEL);
2719 if (!sdvo_connector)
2722 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
2724 kfree(sdvo_connector);
2728 __drm_atomic_helper_connector_reset(&sdvo_connector->base.base,
2729 &conn_state->base.base);
2731 return sdvo_connector;
2735 intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2737 struct drm_encoder *encoder = &intel_sdvo->base.base;
2738 struct drm_connector *connector;
2739 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2740 struct intel_connector *intel_connector;
2741 struct intel_sdvo_connector *intel_sdvo_connector;
2743 DRM_DEBUG_KMS("initialising DVI device %d\n", device);
2745 intel_sdvo_connector = intel_sdvo_connector_alloc();
2746 if (!intel_sdvo_connector)
2750 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
2751 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2752 } else if (device == 1) {
2753 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
2754 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2757 intel_connector = &intel_sdvo_connector->base;
2758 connector = &intel_connector->base;
2759 if (intel_sdvo_get_hotplug_support(intel_sdvo) &
2760 intel_sdvo_connector->output_flag) {
2761 intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
2763 * Some SDVO devices have one-shot hotplug interrupts.
2764 * Ensure that they get re-enabled when an interrupt happens.
2766 intel_connector->polled = DRM_CONNECTOR_POLL_HPD;
2767 intel_encoder->hotplug = intel_sdvo_hotplug;
2768 intel_sdvo_enable_hotplug(intel_encoder);
2770 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2772 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2773 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2775 if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
2776 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2777 intel_sdvo_connector->is_hdmi = true;
2780 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2781 kfree(intel_sdvo_connector);
2785 if (intel_sdvo_connector->is_hdmi)
2786 intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
2792 intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
2794 struct drm_encoder *encoder = &intel_sdvo->base.base;
2795 struct drm_connector *connector;
2796 struct intel_connector *intel_connector;
2797 struct intel_sdvo_connector *intel_sdvo_connector;
2799 DRM_DEBUG_KMS("initialising TV type %d\n", type);
2801 intel_sdvo_connector = intel_sdvo_connector_alloc();
2802 if (!intel_sdvo_connector)
2805 intel_connector = &intel_sdvo_connector->base;
2806 connector = &intel_connector->base;
2807 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2808 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2810 intel_sdvo->controlled_output |= type;
2811 intel_sdvo_connector->output_flag = type;
2813 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2814 kfree(intel_sdvo_connector);
2818 if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
2821 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2827 intel_connector_destroy(connector);
2832 intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
2834 struct drm_encoder *encoder = &intel_sdvo->base.base;
2835 struct drm_connector *connector;
2836 struct intel_connector *intel_connector;
2837 struct intel_sdvo_connector *intel_sdvo_connector;
2839 DRM_DEBUG_KMS("initialising analog device %d\n", device);
2841 intel_sdvo_connector = intel_sdvo_connector_alloc();
2842 if (!intel_sdvo_connector)
2845 intel_connector = &intel_sdvo_connector->base;
2846 connector = &intel_connector->base;
2847 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2848 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2849 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2852 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
2853 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2854 } else if (device == 1) {
2855 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
2856 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2859 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2860 kfree(intel_sdvo_connector);
2868 intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
2870 struct drm_encoder *encoder = &intel_sdvo->base.base;
2871 struct drm_connector *connector;
2872 struct intel_connector *intel_connector;
2873 struct intel_sdvo_connector *intel_sdvo_connector;
2874 struct drm_display_mode *mode;
2876 DRM_DEBUG_KMS("initialising LVDS device %d\n", device);
2878 intel_sdvo_connector = intel_sdvo_connector_alloc();
2879 if (!intel_sdvo_connector)
2882 intel_connector = &intel_sdvo_connector->base;
2883 connector = &intel_connector->base;
2884 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2885 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2888 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
2889 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2890 } else if (device == 1) {
2891 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
2892 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2895 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2896 kfree(intel_sdvo_connector);
2900 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2903 intel_sdvo_get_lvds_modes(connector);
2905 list_for_each_entry(mode, &connector->probed_modes, head) {
2906 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
2907 struct drm_display_mode *fixed_mode =
2908 drm_mode_duplicate(connector->dev, mode);
2910 intel_panel_init(&intel_connector->panel,
2916 if (!intel_connector->panel.fixed_mode)
2922 intel_connector_destroy(connector);
2927 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, u16 flags)
2929 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2931 if (flags & SDVO_OUTPUT_TMDS0)
2932 if (!intel_sdvo_dvi_init(intel_sdvo, 0))
2935 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2936 if (!intel_sdvo_dvi_init(intel_sdvo, 1))
2939 /* TV has no XXX1 function block */
2940 if (flags & SDVO_OUTPUT_SVID0)
2941 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
2944 if (flags & SDVO_OUTPUT_CVBS0)
2945 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
2948 if (flags & SDVO_OUTPUT_YPRPB0)
2949 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
2952 if (flags & SDVO_OUTPUT_RGB0)
2953 if (!intel_sdvo_analog_init(intel_sdvo, 0))
2956 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2957 if (!intel_sdvo_analog_init(intel_sdvo, 1))
2960 if (flags & SDVO_OUTPUT_LVDS0)
2961 if (!intel_sdvo_lvds_init(intel_sdvo, 0))
2964 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2965 if (!intel_sdvo_lvds_init(intel_sdvo, 1))
2968 if ((flags & SDVO_OUTPUT_MASK) == 0) {
2969 unsigned char bytes[2];
2971 intel_sdvo->controlled_output = 0;
2972 memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
2973 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2974 SDVO_NAME(intel_sdvo),
2975 bytes[0], bytes[1]);
2978 intel_sdvo->base.pipe_mask = ~0;
2983 static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
2985 struct drm_device *dev = intel_sdvo->base.base.dev;
2986 struct drm_connector *connector, *tmp;
2988 list_for_each_entry_safe(connector, tmp,
2989 &dev->mode_config.connector_list, head) {
2990 if (intel_attached_encoder(to_intel_connector(connector)) == &intel_sdvo->base) {
2991 drm_connector_unregister(connector);
2992 intel_connector_destroy(connector);
2997 static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
2998 struct intel_sdvo_connector *intel_sdvo_connector,
3001 struct drm_device *dev = intel_sdvo->base.base.dev;
3002 struct intel_sdvo_tv_format format;
3005 if (!intel_sdvo_set_target_output(intel_sdvo, type))
3008 BUILD_BUG_ON(sizeof(format) != 6);
3009 if (!intel_sdvo_get_value(intel_sdvo,
3010 SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
3011 &format, sizeof(format)))
3014 memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
3016 if (format_map == 0)
3019 intel_sdvo_connector->format_supported_num = 0;
3020 for (i = 0 ; i < TV_FORMAT_NUM; i++)
3021 if (format_map & (1 << i))
3022 intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
3025 intel_sdvo_connector->tv_format =
3026 drm_property_create(dev, DRM_MODE_PROP_ENUM,
3027 "mode", intel_sdvo_connector->format_supported_num);
3028 if (!intel_sdvo_connector->tv_format)
3031 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
3032 drm_property_add_enum(intel_sdvo_connector->tv_format, i,
3033 tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
3035 intel_sdvo_connector->base.base.state->tv.mode = intel_sdvo_connector->tv_format_supported[0];
3036 drm_object_attach_property(&intel_sdvo_connector->base.base.base,
3037 intel_sdvo_connector->tv_format, 0);
3042 #define _ENHANCEMENT(state_assignment, name, NAME) do { \
3043 if (enhancements.name) { \
3044 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
3045 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
3047 intel_sdvo_connector->name = \
3048 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
3049 if (!intel_sdvo_connector->name) return false; \
3050 state_assignment = response; \
3051 drm_object_attach_property(&connector->base, \
3052 intel_sdvo_connector->name, 0); \
3053 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
3054 data_value[0], data_value[1], response); \
3058 #define ENHANCEMENT(state, name, NAME) _ENHANCEMENT((state)->name, name, NAME)
3061 intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
3062 struct intel_sdvo_connector *intel_sdvo_connector,
3063 struct intel_sdvo_enhancements_reply enhancements)
3065 struct drm_device *dev = intel_sdvo->base.base.dev;
3066 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3067 struct drm_connector_state *conn_state = connector->state;
3068 struct intel_sdvo_connector_state *sdvo_state =
3069 to_intel_sdvo_connector_state(conn_state);
3070 u16 response, data_value[2];
3072 /* when horizontal overscan is supported, Add the left/right property */
3073 if (enhancements.overscan_h) {
3074 if (!intel_sdvo_get_value(intel_sdvo,
3075 SDVO_CMD_GET_MAX_OVERSCAN_H,
3079 if (!intel_sdvo_get_value(intel_sdvo,
3080 SDVO_CMD_GET_OVERSCAN_H,
3084 sdvo_state->tv.overscan_h = response;
3086 intel_sdvo_connector->max_hscan = data_value[0];
3087 intel_sdvo_connector->left =
3088 drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
3089 if (!intel_sdvo_connector->left)
3092 drm_object_attach_property(&connector->base,
3093 intel_sdvo_connector->left, 0);
3095 intel_sdvo_connector->right =
3096 drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
3097 if (!intel_sdvo_connector->right)
3100 drm_object_attach_property(&connector->base,
3101 intel_sdvo_connector->right, 0);
3102 DRM_DEBUG_KMS("h_overscan: max %d, "
3103 "default %d, current %d\n",
3104 data_value[0], data_value[1], response);
3107 if (enhancements.overscan_v) {
3108 if (!intel_sdvo_get_value(intel_sdvo,
3109 SDVO_CMD_GET_MAX_OVERSCAN_V,
3113 if (!intel_sdvo_get_value(intel_sdvo,
3114 SDVO_CMD_GET_OVERSCAN_V,
3118 sdvo_state->tv.overscan_v = response;
3120 intel_sdvo_connector->max_vscan = data_value[0];
3121 intel_sdvo_connector->top =
3122 drm_property_create_range(dev, 0,
3123 "top_margin", 0, data_value[0]);
3124 if (!intel_sdvo_connector->top)
3127 drm_object_attach_property(&connector->base,
3128 intel_sdvo_connector->top, 0);
3130 intel_sdvo_connector->bottom =
3131 drm_property_create_range(dev, 0,
3132 "bottom_margin", 0, data_value[0]);
3133 if (!intel_sdvo_connector->bottom)
3136 drm_object_attach_property(&connector->base,
3137 intel_sdvo_connector->bottom, 0);
3138 DRM_DEBUG_KMS("v_overscan: max %d, "
3139 "default %d, current %d\n",
3140 data_value[0], data_value[1], response);
3143 ENHANCEMENT(&sdvo_state->tv, hpos, HPOS);
3144 ENHANCEMENT(&sdvo_state->tv, vpos, VPOS);
3145 ENHANCEMENT(&conn_state->tv, saturation, SATURATION);
3146 ENHANCEMENT(&conn_state->tv, contrast, CONTRAST);
3147 ENHANCEMENT(&conn_state->tv, hue, HUE);
3148 ENHANCEMENT(&conn_state->tv, brightness, BRIGHTNESS);
3149 ENHANCEMENT(&sdvo_state->tv, sharpness, SHARPNESS);
3150 ENHANCEMENT(&sdvo_state->tv, flicker_filter, FLICKER_FILTER);
3151 ENHANCEMENT(&sdvo_state->tv, flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
3152 ENHANCEMENT(&sdvo_state->tv, flicker_filter_2d, FLICKER_FILTER_2D);
3153 _ENHANCEMENT(sdvo_state->tv.chroma_filter, tv_chroma_filter, TV_CHROMA_FILTER);
3154 _ENHANCEMENT(sdvo_state->tv.luma_filter, tv_luma_filter, TV_LUMA_FILTER);
3156 if (enhancements.dot_crawl) {
3157 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
3160 sdvo_state->tv.dot_crawl = response & 0x1;
3161 intel_sdvo_connector->dot_crawl =
3162 drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
3163 if (!intel_sdvo_connector->dot_crawl)
3166 drm_object_attach_property(&connector->base,
3167 intel_sdvo_connector->dot_crawl, 0);
3168 DRM_DEBUG_KMS("dot crawl: current %d\n", response);
3175 intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
3176 struct intel_sdvo_connector *intel_sdvo_connector,
3177 struct intel_sdvo_enhancements_reply enhancements)
3179 struct drm_device *dev = intel_sdvo->base.base.dev;
3180 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3181 u16 response, data_value[2];
3183 ENHANCEMENT(&connector->state->tv, brightness, BRIGHTNESS);
3190 static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
3191 struct intel_sdvo_connector *intel_sdvo_connector)
3194 struct intel_sdvo_enhancements_reply reply;
3198 BUILD_BUG_ON(sizeof(enhancements) != 2);
3200 if (!intel_sdvo_get_value(intel_sdvo,
3201 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
3202 &enhancements, sizeof(enhancements)) ||
3203 enhancements.response == 0) {
3204 DRM_DEBUG_KMS("No enhancement is supported\n");
3208 if (IS_TV(intel_sdvo_connector))
3209 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3210 else if (IS_LVDS(intel_sdvo_connector))
3211 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3216 static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
3217 struct i2c_msg *msgs,
3220 struct intel_sdvo *sdvo = adapter->algo_data;
3222 if (!__intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
3225 return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
3228 static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
3230 struct intel_sdvo *sdvo = adapter->algo_data;
3231 return sdvo->i2c->algo->functionality(sdvo->i2c);
3234 static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
3235 .master_xfer = intel_sdvo_ddc_proxy_xfer,
3236 .functionality = intel_sdvo_ddc_proxy_func
3239 static void proxy_lock_bus(struct i2c_adapter *adapter,
3242 struct intel_sdvo *sdvo = adapter->algo_data;
3243 sdvo->i2c->lock_ops->lock_bus(sdvo->i2c, flags);
3246 static int proxy_trylock_bus(struct i2c_adapter *adapter,
3249 struct intel_sdvo *sdvo = adapter->algo_data;
3250 return sdvo->i2c->lock_ops->trylock_bus(sdvo->i2c, flags);
3253 static void proxy_unlock_bus(struct i2c_adapter *adapter,
3256 struct intel_sdvo *sdvo = adapter->algo_data;
3257 sdvo->i2c->lock_ops->unlock_bus(sdvo->i2c, flags);
3260 static const struct i2c_lock_operations proxy_lock_ops = {
3261 .lock_bus = proxy_lock_bus,
3262 .trylock_bus = proxy_trylock_bus,
3263 .unlock_bus = proxy_unlock_bus,
3267 intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
3268 struct drm_i915_private *dev_priv)
3270 struct pci_dev *pdev = dev_priv->drm.pdev;
3272 sdvo->ddc.owner = THIS_MODULE;
3273 sdvo->ddc.class = I2C_CLASS_DDC;
3274 snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
3275 sdvo->ddc.dev.parent = &pdev->dev;
3276 sdvo->ddc.algo_data = sdvo;
3277 sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
3278 sdvo->ddc.lock_ops = &proxy_lock_ops;
3280 return i2c_add_adapter(&sdvo->ddc) == 0;
3283 static void assert_sdvo_port_valid(const struct drm_i915_private *dev_priv,
3286 if (HAS_PCH_SPLIT(dev_priv))
3287 drm_WARN_ON(&dev_priv->drm, port != PORT_B);
3289 drm_WARN_ON(&dev_priv->drm, port != PORT_B && port != PORT_C);
3292 bool intel_sdvo_init(struct drm_i915_private *dev_priv,
3293 i915_reg_t sdvo_reg, enum port port)
3295 struct intel_encoder *intel_encoder;
3296 struct intel_sdvo *intel_sdvo;
3299 assert_sdvo_port_valid(dev_priv, port);
3301 intel_sdvo = kzalloc(sizeof(*intel_sdvo), GFP_KERNEL);
3305 intel_sdvo->sdvo_reg = sdvo_reg;
3306 intel_sdvo->port = port;
3307 intel_sdvo->slave_addr =
3308 intel_sdvo_get_slave_addr(dev_priv, intel_sdvo) >> 1;
3309 intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo);
3310 if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev_priv))
3313 /* encoder type will be decided later */
3314 intel_encoder = &intel_sdvo->base;
3315 intel_encoder->type = INTEL_OUTPUT_SDVO;
3316 intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
3317 intel_encoder->port = port;
3318 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
3319 &intel_sdvo_enc_funcs, 0,
3320 "SDVO %c", port_name(port));
3322 /* Read the regs to test if we can talk to the device */
3323 for (i = 0; i < 0x40; i++) {
3326 if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
3327 drm_dbg_kms(&dev_priv->drm,
3328 "No SDVO device found on %s\n",
3329 SDVO_NAME(intel_sdvo));
3334 intel_encoder->compute_config = intel_sdvo_compute_config;
3335 if (HAS_PCH_SPLIT(dev_priv)) {
3336 intel_encoder->disable = pch_disable_sdvo;
3337 intel_encoder->post_disable = pch_post_disable_sdvo;
3339 intel_encoder->disable = intel_disable_sdvo;
3341 intel_encoder->pre_enable = intel_sdvo_pre_enable;
3342 intel_encoder->enable = intel_enable_sdvo;
3343 intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
3344 intel_encoder->get_config = intel_sdvo_get_config;
3346 /* In default case sdvo lvds is false */
3347 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
3350 intel_sdvo->colorimetry_cap =
3351 intel_sdvo_get_colorimetry_cap(intel_sdvo);
3353 if (intel_sdvo_output_setup(intel_sdvo,
3354 intel_sdvo->caps.output_flags) != true) {
3355 drm_dbg_kms(&dev_priv->drm,
3356 "SDVO output failed to setup on %s\n",
3357 SDVO_NAME(intel_sdvo));
3358 /* Output_setup can leave behind connectors! */
3363 * Only enable the hotplug irq if we need it, to work around noisy
3366 if (intel_sdvo->hotplug_active) {
3367 if (intel_sdvo->port == PORT_B)
3368 intel_encoder->hpd_pin = HPD_SDVO_B;
3370 intel_encoder->hpd_pin = HPD_SDVO_C;
3374 * Cloning SDVO with anything is often impossible, since the SDVO
3375 * encoder can request a special input timing mode. And even if that's
3376 * not the case we have evidence that cloning a plain unscaled mode with
3377 * VGA doesn't really work. Furthermore the cloning flags are way too
3378 * simplistic anyway to express such constraints, so just give up on
3379 * cloning for SDVO encoders.
3381 intel_sdvo->base.cloneable = 0;
3383 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo);
3385 /* Set the input timing to the screen. Assume always input 0. */
3386 if (!intel_sdvo_set_target_input(intel_sdvo))
3389 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
3390 &intel_sdvo->pixel_clock_min,
3391 &intel_sdvo->pixel_clock_max))
3394 drm_dbg_kms(&dev_priv->drm, "%s device VID/DID: %02X:%02X.%02X, "
3395 "clock range %dMHz - %dMHz, "
3396 "input 1: %c, input 2: %c, "
3397 "output 1: %c, output 2: %c\n",
3398 SDVO_NAME(intel_sdvo),
3399 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
3400 intel_sdvo->caps.device_rev_id,
3401 intel_sdvo->pixel_clock_min / 1000,
3402 intel_sdvo->pixel_clock_max / 1000,
3403 (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
3404 (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
3405 /* check currently supported outputs */
3406 intel_sdvo->caps.output_flags &
3407 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
3408 intel_sdvo->caps.output_flags &
3409 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
3413 intel_sdvo_output_cleanup(intel_sdvo);
3416 drm_encoder_cleanup(&intel_encoder->base);
3417 i2c_del_adapter(&intel_sdvo->ddc);
3419 intel_sdvo_unselect_i2c_bus(intel_sdvo);