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/display/drm_hdmi_helper.h>
35 #include <drm/drm_atomic_helper.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_edid.h>
41 #include "intel_atomic.h"
42 #include "intel_audio.h"
43 #include "intel_connector.h"
44 #include "intel_crtc.h"
46 #include "intel_display_types.h"
47 #include "intel_fifo_underrun.h"
48 #include "intel_gmbus.h"
49 #include "intel_hdmi.h"
50 #include "intel_hotplug.h"
51 #include "intel_panel.h"
52 #include "intel_sdvo.h"
53 #include "intel_sdvo_regs.h"
55 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
56 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
57 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
58 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
60 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
63 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
64 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
65 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
66 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
67 #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
70 static const char * const tv_format_names[] = {
71 "NTSC_M" , "NTSC_J" , "NTSC_443",
72 "PAL_B" , "PAL_D" , "PAL_G" ,
73 "PAL_H" , "PAL_I" , "PAL_M" ,
74 "PAL_N" , "PAL_NC" , "PAL_60" ,
75 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
76 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
80 #define TV_FORMAT_NUM ARRAY_SIZE(tv_format_names)
83 struct intel_encoder base;
85 struct i2c_adapter *i2c;
88 struct i2c_adapter ddc;
90 /* Register for the SDVO device: SDVOB or SDVOC */
93 /* Active outputs controlled by this SDVO output */
94 u16 controlled_output;
97 * Capabilities of the SDVO device returned by
98 * intel_sdvo_get_capabilities()
100 struct intel_sdvo_caps caps;
104 /* Pixel clock limitations reported by the SDVO device, in kHz */
105 int pixel_clock_min, pixel_clock_max;
108 * For multiple function SDVO device,
109 * this is for current attached outputs.
114 * Hotplug activation bits for this device
120 /* DDC bus used by this SDVO encoder */
124 * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
129 struct intel_sdvo_connector {
130 struct intel_connector base;
132 /* Mark the type of connector */
135 /* This contains all current supported TV format */
136 u8 tv_format_supported[TV_FORMAT_NUM];
137 int format_supported_num;
138 struct drm_property *tv_format;
140 /* add the property for the SDVO-TV */
141 struct drm_property *left;
142 struct drm_property *right;
143 struct drm_property *top;
144 struct drm_property *bottom;
145 struct drm_property *hpos;
146 struct drm_property *vpos;
147 struct drm_property *contrast;
148 struct drm_property *saturation;
149 struct drm_property *hue;
150 struct drm_property *sharpness;
151 struct drm_property *flicker_filter;
152 struct drm_property *flicker_filter_adaptive;
153 struct drm_property *flicker_filter_2d;
154 struct drm_property *tv_chroma_filter;
155 struct drm_property *tv_luma_filter;
156 struct drm_property *dot_crawl;
158 /* add the property for the SDVO-TV/LVDS */
159 struct drm_property *brightness;
161 /* this is to get the range of margin.*/
162 u32 max_hscan, max_vscan;
165 * This is set if we treat the device as HDMI, instead of DVI.
170 struct intel_sdvo_connector_state {
171 /* base.base: tv.saturation/contrast/hue/brightness */
172 struct intel_digital_connector_state base;
175 unsigned overscan_h, overscan_v, hpos, vpos, sharpness;
176 unsigned flicker_filter, flicker_filter_2d, flicker_filter_adaptive;
177 unsigned chroma_filter, luma_filter, dot_crawl;
181 static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
183 return container_of(encoder, struct intel_sdvo, base);
186 static struct intel_sdvo *intel_attached_sdvo(struct intel_connector *connector)
188 return to_sdvo(intel_attached_encoder(connector));
191 static struct intel_sdvo_connector *
192 to_intel_sdvo_connector(struct drm_connector *connector)
194 return container_of(connector, struct intel_sdvo_connector, base.base);
197 #define to_intel_sdvo_connector_state(conn_state) \
198 container_of((conn_state), struct intel_sdvo_connector_state, base.base)
201 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo);
203 intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
204 struct intel_sdvo_connector *intel_sdvo_connector,
207 intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
208 struct intel_sdvo_connector *intel_sdvo_connector);
211 * Writes the SDVOB or SDVOC with the given value, but always writes both
212 * SDVOB and SDVOC to work around apparent hardware issues (according to
213 * comments in the BIOS).
215 static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
217 struct drm_device *dev = intel_sdvo->base.base.dev;
218 struct drm_i915_private *dev_priv = to_i915(dev);
219 u32 bval = val, cval = val;
222 if (HAS_PCH_SPLIT(dev_priv)) {
223 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
224 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
226 * HW workaround, need to write this twice for issue
227 * that may result in first write getting masked.
229 if (HAS_PCH_IBX(dev_priv)) {
230 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
231 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
236 if (intel_sdvo->port == PORT_B)
237 cval = intel_de_read(dev_priv, GEN3_SDVOC);
239 bval = intel_de_read(dev_priv, GEN3_SDVOB);
242 * Write the registers twice for luck. Sometimes,
243 * writing them only once doesn't appear to 'stick'.
244 * The BIOS does this too. Yay, magic
246 for (i = 0; i < 2; i++) {
247 intel_de_write(dev_priv, GEN3_SDVOB, bval);
248 intel_de_posting_read(dev_priv, GEN3_SDVOB);
250 intel_de_write(dev_priv, GEN3_SDVOC, cval);
251 intel_de_posting_read(dev_priv, GEN3_SDVOC);
255 static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
257 struct i2c_msg msgs[] = {
259 .addr = intel_sdvo->slave_addr,
265 .addr = intel_sdvo->slave_addr,
273 if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
276 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
280 #define SDVO_CMD_NAME_ENTRY(cmd_) { .cmd = SDVO_CMD_ ## cmd_, .name = #cmd_ }
282 /** Mapping of command numbers to names, for debug output */
283 static const struct {
286 } __packed sdvo_cmd_names[] = {
287 SDVO_CMD_NAME_ENTRY(RESET),
288 SDVO_CMD_NAME_ENTRY(GET_DEVICE_CAPS),
289 SDVO_CMD_NAME_ENTRY(GET_FIRMWARE_REV),
290 SDVO_CMD_NAME_ENTRY(GET_TRAINED_INPUTS),
291 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_OUTPUTS),
292 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_OUTPUTS),
293 SDVO_CMD_NAME_ENTRY(GET_IN_OUT_MAP),
294 SDVO_CMD_NAME_ENTRY(SET_IN_OUT_MAP),
295 SDVO_CMD_NAME_ENTRY(GET_ATTACHED_DISPLAYS),
296 SDVO_CMD_NAME_ENTRY(GET_HOT_PLUG_SUPPORT),
297 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_HOT_PLUG),
298 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_HOT_PLUG),
299 SDVO_CMD_NAME_ENTRY(GET_INTERRUPT_EVENT_SOURCE),
300 SDVO_CMD_NAME_ENTRY(SET_TARGET_INPUT),
301 SDVO_CMD_NAME_ENTRY(SET_TARGET_OUTPUT),
302 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART1),
303 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART2),
304 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART1),
305 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART2),
306 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART1),
307 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART2),
308 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART1),
309 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART2),
310 SDVO_CMD_NAME_ENTRY(CREATE_PREFERRED_INPUT_TIMING),
311 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART1),
312 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART2),
313 SDVO_CMD_NAME_ENTRY(GET_INPUT_PIXEL_CLOCK_RANGE),
314 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_PIXEL_CLOCK_RANGE),
315 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_CLOCK_RATE_MULTS),
316 SDVO_CMD_NAME_ENTRY(GET_CLOCK_RATE_MULT),
317 SDVO_CMD_NAME_ENTRY(SET_CLOCK_RATE_MULT),
318 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_TV_FORMATS),
319 SDVO_CMD_NAME_ENTRY(GET_TV_FORMAT),
320 SDVO_CMD_NAME_ENTRY(SET_TV_FORMAT),
321 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_POWER_STATES),
322 SDVO_CMD_NAME_ENTRY(GET_POWER_STATE),
323 SDVO_CMD_NAME_ENTRY(SET_ENCODER_POWER_STATE),
324 SDVO_CMD_NAME_ENTRY(SET_DISPLAY_POWER_STATE),
325 SDVO_CMD_NAME_ENTRY(SET_CONTROL_BUS_SWITCH),
326 SDVO_CMD_NAME_ENTRY(GET_SDTV_RESOLUTION_SUPPORT),
327 SDVO_CMD_NAME_ENTRY(GET_SCALED_HDTV_RESOLUTION_SUPPORT),
328 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_ENHANCEMENTS),
330 /* Add the op code for SDVO enhancements */
331 SDVO_CMD_NAME_ENTRY(GET_MAX_HPOS),
332 SDVO_CMD_NAME_ENTRY(GET_HPOS),
333 SDVO_CMD_NAME_ENTRY(SET_HPOS),
334 SDVO_CMD_NAME_ENTRY(GET_MAX_VPOS),
335 SDVO_CMD_NAME_ENTRY(GET_VPOS),
336 SDVO_CMD_NAME_ENTRY(SET_VPOS),
337 SDVO_CMD_NAME_ENTRY(GET_MAX_SATURATION),
338 SDVO_CMD_NAME_ENTRY(GET_SATURATION),
339 SDVO_CMD_NAME_ENTRY(SET_SATURATION),
340 SDVO_CMD_NAME_ENTRY(GET_MAX_HUE),
341 SDVO_CMD_NAME_ENTRY(GET_HUE),
342 SDVO_CMD_NAME_ENTRY(SET_HUE),
343 SDVO_CMD_NAME_ENTRY(GET_MAX_CONTRAST),
344 SDVO_CMD_NAME_ENTRY(GET_CONTRAST),
345 SDVO_CMD_NAME_ENTRY(SET_CONTRAST),
346 SDVO_CMD_NAME_ENTRY(GET_MAX_BRIGHTNESS),
347 SDVO_CMD_NAME_ENTRY(GET_BRIGHTNESS),
348 SDVO_CMD_NAME_ENTRY(SET_BRIGHTNESS),
349 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_H),
350 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_H),
351 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_H),
352 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_V),
353 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_V),
354 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_V),
355 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER),
356 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER),
357 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER),
358 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_ADAPTIVE),
359 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_ADAPTIVE),
360 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_ADAPTIVE),
361 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_2D),
362 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_2D),
363 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_2D),
364 SDVO_CMD_NAME_ENTRY(GET_MAX_SHARPNESS),
365 SDVO_CMD_NAME_ENTRY(GET_SHARPNESS),
366 SDVO_CMD_NAME_ENTRY(SET_SHARPNESS),
367 SDVO_CMD_NAME_ENTRY(GET_DOT_CRAWL),
368 SDVO_CMD_NAME_ENTRY(SET_DOT_CRAWL),
369 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_CHROMA_FILTER),
370 SDVO_CMD_NAME_ENTRY(GET_TV_CHROMA_FILTER),
371 SDVO_CMD_NAME_ENTRY(SET_TV_CHROMA_FILTER),
372 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_LUMA_FILTER),
373 SDVO_CMD_NAME_ENTRY(GET_TV_LUMA_FILTER),
374 SDVO_CMD_NAME_ENTRY(SET_TV_LUMA_FILTER),
377 SDVO_CMD_NAME_ENTRY(GET_SUPP_ENCODE),
378 SDVO_CMD_NAME_ENTRY(GET_ENCODE),
379 SDVO_CMD_NAME_ENTRY(SET_ENCODE),
380 SDVO_CMD_NAME_ENTRY(SET_PIXEL_REPLI),
381 SDVO_CMD_NAME_ENTRY(GET_PIXEL_REPLI),
382 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY_CAP),
383 SDVO_CMD_NAME_ENTRY(SET_COLORIMETRY),
384 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY),
385 SDVO_CMD_NAME_ENTRY(GET_AUDIO_ENCRYPT_PREFER),
386 SDVO_CMD_NAME_ENTRY(SET_AUDIO_STAT),
387 SDVO_CMD_NAME_ENTRY(GET_AUDIO_STAT),
388 SDVO_CMD_NAME_ENTRY(GET_HBUF_INDEX),
389 SDVO_CMD_NAME_ENTRY(SET_HBUF_INDEX),
390 SDVO_CMD_NAME_ENTRY(GET_HBUF_INFO),
391 SDVO_CMD_NAME_ENTRY(GET_HBUF_AV_SPLIT),
392 SDVO_CMD_NAME_ENTRY(SET_HBUF_AV_SPLIT),
393 SDVO_CMD_NAME_ENTRY(GET_HBUF_TXRATE),
394 SDVO_CMD_NAME_ENTRY(SET_HBUF_TXRATE),
395 SDVO_CMD_NAME_ENTRY(SET_HBUF_DATA),
396 SDVO_CMD_NAME_ENTRY(GET_HBUF_DATA),
399 #undef SDVO_CMD_NAME_ENTRY
401 static const char *sdvo_cmd_name(u8 cmd)
405 for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
406 if (cmd == sdvo_cmd_names[i].cmd)
407 return sdvo_cmd_names[i].name;
413 #define SDVO_NAME(svdo) ((svdo)->port == PORT_B ? "SDVOB" : "SDVOC")
415 static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
416 const void *args, int args_len)
418 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
419 const char *cmd_name;
423 #define BUF_PRINT(args...) \
424 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
426 for (i = 0; i < args_len; i++) {
427 BUF_PRINT("%02X ", ((u8 *)args)[i]);
433 cmd_name = sdvo_cmd_name(cmd);
435 BUF_PRINT("(%s)", cmd_name);
437 BUF_PRINT("(%02X)", cmd);
439 drm_WARN_ON(&dev_priv->drm, pos >= sizeof(buffer) - 1);
442 DRM_DEBUG_KMS("%s: W: %02X %s\n", SDVO_NAME(intel_sdvo), cmd, buffer);
445 static const char * const cmd_status_names[] = {
446 [SDVO_CMD_STATUS_POWER_ON] = "Power on",
447 [SDVO_CMD_STATUS_SUCCESS] = "Success",
448 [SDVO_CMD_STATUS_NOTSUPP] = "Not supported",
449 [SDVO_CMD_STATUS_INVALID_ARG] = "Invalid arg",
450 [SDVO_CMD_STATUS_PENDING] = "Pending",
451 [SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED] = "Target not specified",
452 [SDVO_CMD_STATUS_SCALING_NOT_SUPP] = "Scaling not supported",
455 static const char *sdvo_cmd_status(u8 status)
457 if (status < ARRAY_SIZE(cmd_status_names))
458 return cmd_status_names[status];
463 static bool __intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
464 const void *args, int args_len,
468 struct i2c_msg *msgs;
471 /* Would be simpler to allocate both in one go ? */
472 buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
476 msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
482 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
484 for (i = 0; i < args_len; i++) {
485 msgs[i].addr = intel_sdvo->slave_addr;
488 msgs[i].buf = buf + 2 *i;
489 buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
490 buf[2*i + 1] = ((u8*)args)[i];
492 msgs[i].addr = intel_sdvo->slave_addr;
495 msgs[i].buf = buf + 2*i;
496 buf[2*i + 0] = SDVO_I2C_OPCODE;
499 /* the following two are to read the response */
500 status = SDVO_I2C_CMD_STATUS;
501 msgs[i+1].addr = intel_sdvo->slave_addr;
504 msgs[i+1].buf = &status;
506 msgs[i+2].addr = intel_sdvo->slave_addr;
507 msgs[i+2].flags = I2C_M_RD;
509 msgs[i+2].buf = &status;
512 ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
514 ret = __i2c_transfer(intel_sdvo->i2c, msgs, i+3);
516 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
521 /* failure in I2C transfer */
522 DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
532 static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
533 const void *args, int args_len)
535 return __intel_sdvo_write_cmd(intel_sdvo, cmd, args, args_len, true);
538 static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
539 void *response, int response_len)
541 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
542 const char *cmd_status;
543 u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
551 * The documentation states that all commands will be
552 * processed within 15µs, and that we need only poll
553 * the status byte a maximum of 3 times in order for the
554 * command to be complete.
556 * Check 5 times in case the hardware failed to read the docs.
558 * Also beware that the first response by many devices is to
559 * reply PENDING and stall for time. TVs are notorious for
560 * requiring longer than specified to complete their replies.
561 * Originally (in the DDX long ago), the delay was only ever 15ms
562 * with an additional delay of 30ms applied for TVs added later after
563 * many experiments. To accommodate both sets of delays, we do a
564 * sequence of slow checks if the device is falling behind and fails
565 * to reply within 5*15µs.
567 if (!intel_sdvo_read_byte(intel_sdvo,
572 while ((status == SDVO_CMD_STATUS_PENDING ||
573 status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
579 if (!intel_sdvo_read_byte(intel_sdvo,
585 #define BUF_PRINT(args...) \
586 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
588 cmd_status = sdvo_cmd_status(status);
590 BUF_PRINT("(%s)", cmd_status);
592 BUF_PRINT("(??? %d)", status);
594 if (status != SDVO_CMD_STATUS_SUCCESS)
597 /* Read the command response */
598 for (i = 0; i < response_len; i++) {
599 if (!intel_sdvo_read_byte(intel_sdvo,
600 SDVO_I2C_RETURN_0 + i,
601 &((u8 *)response)[i]))
603 BUF_PRINT(" %02X", ((u8 *)response)[i]);
606 drm_WARN_ON(&dev_priv->drm, pos >= sizeof(buffer) - 1);
609 DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo), buffer);
613 DRM_DEBUG_KMS("%s: R: ... failed %s\n",
614 SDVO_NAME(intel_sdvo), buffer);
618 static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode *adjusted_mode)
620 if (adjusted_mode->crtc_clock >= 100000)
622 else if (adjusted_mode->crtc_clock >= 50000)
628 static bool __intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
631 /* This must be the immediately preceding write before the i2c xfer */
632 return __intel_sdvo_write_cmd(intel_sdvo,
633 SDVO_CMD_SET_CONTROL_BUS_SWITCH,
637 static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
639 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
642 return intel_sdvo_read_response(intel_sdvo, NULL, 0);
646 intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
648 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
651 return intel_sdvo_read_response(intel_sdvo, value, len);
654 static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
656 struct intel_sdvo_set_target_input_args targets = {0};
657 return intel_sdvo_set_value(intel_sdvo,
658 SDVO_CMD_SET_TARGET_INPUT,
659 &targets, sizeof(targets));
663 * Return whether each input is trained.
665 * This function is making an assumption about the layout of the response,
666 * which should be checked against the docs.
668 static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
670 struct intel_sdvo_get_trained_inputs_response response;
672 BUILD_BUG_ON(sizeof(response) != 1);
673 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
674 &response, sizeof(response)))
677 *input_1 = response.input0_trained;
678 *input_2 = response.input1_trained;
682 static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
685 return intel_sdvo_set_value(intel_sdvo,
686 SDVO_CMD_SET_ACTIVE_OUTPUTS,
687 &outputs, sizeof(outputs));
690 static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
693 return intel_sdvo_get_value(intel_sdvo,
694 SDVO_CMD_GET_ACTIVE_OUTPUTS,
695 outputs, sizeof(*outputs));
698 static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
701 u8 state = SDVO_ENCODER_STATE_ON;
704 case DRM_MODE_DPMS_ON:
705 state = SDVO_ENCODER_STATE_ON;
707 case DRM_MODE_DPMS_STANDBY:
708 state = SDVO_ENCODER_STATE_STANDBY;
710 case DRM_MODE_DPMS_SUSPEND:
711 state = SDVO_ENCODER_STATE_SUSPEND;
713 case DRM_MODE_DPMS_OFF:
714 state = SDVO_ENCODER_STATE_OFF;
718 return intel_sdvo_set_value(intel_sdvo,
719 SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
722 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
726 struct intel_sdvo_pixel_clock_range clocks;
728 BUILD_BUG_ON(sizeof(clocks) != 4);
729 if (!intel_sdvo_get_value(intel_sdvo,
730 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
731 &clocks, sizeof(clocks)))
734 /* Convert the values from units of 10 kHz to kHz. */
735 *clock_min = clocks.min * 10;
736 *clock_max = clocks.max * 10;
740 static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
743 return intel_sdvo_set_value(intel_sdvo,
744 SDVO_CMD_SET_TARGET_OUTPUT,
745 &outputs, sizeof(outputs));
748 static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
749 struct intel_sdvo_dtd *dtd)
751 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
752 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
755 static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
756 struct intel_sdvo_dtd *dtd)
758 return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
759 intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
762 static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
763 struct intel_sdvo_dtd *dtd)
765 return intel_sdvo_set_timing(intel_sdvo,
766 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
769 static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
770 struct intel_sdvo_dtd *dtd)
772 return intel_sdvo_set_timing(intel_sdvo,
773 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
776 static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
777 struct intel_sdvo_dtd *dtd)
779 return intel_sdvo_get_timing(intel_sdvo,
780 SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
784 intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
785 struct intel_sdvo_connector *intel_sdvo_connector,
786 const struct drm_display_mode *mode)
788 struct intel_sdvo_preferred_input_timing_args args;
790 memset(&args, 0, sizeof(args));
791 args.clock = mode->clock / 10;
792 args.width = mode->hdisplay;
793 args.height = mode->vdisplay;
796 if (IS_LVDS(intel_sdvo_connector)) {
797 const struct drm_display_mode *fixed_mode =
798 intel_panel_fixed_mode(&intel_sdvo_connector->base, mode);
800 if (fixed_mode->hdisplay != args.width ||
801 fixed_mode->vdisplay != args.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 /* TX_DISABLED doesn't mean disabled for ELD */
1070 if (if_index != SDVO_HBUF_INDEX_ELD && tx_rate == SDVO_HBUF_TX_DISABLED)
1073 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1076 DRM_DEBUG_KMS("reading sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1077 if_index, length, hbuf_size);
1079 hbuf_size = min_t(unsigned int, length, hbuf_size);
1081 for (i = 0; i < hbuf_size; i += 8) {
1082 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HBUF_DATA, NULL, 0))
1084 if (!intel_sdvo_read_response(intel_sdvo, &data[i],
1085 min_t(unsigned int, 8, hbuf_size - i)))
1092 static bool intel_sdvo_compute_avi_infoframe(struct intel_sdvo *intel_sdvo,
1093 struct intel_crtc_state *crtc_state,
1094 struct drm_connector_state *conn_state)
1096 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1097 struct hdmi_avi_infoframe *frame = &crtc_state->infoframes.avi.avi;
1098 const struct drm_display_mode *adjusted_mode =
1099 &crtc_state->hw.adjusted_mode;
1102 if (!crtc_state->has_hdmi_sink)
1105 crtc_state->infoframes.enable |=
1106 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1108 ret = drm_hdmi_avi_infoframe_from_display_mode(frame,
1109 conn_state->connector,
1114 drm_hdmi_avi_infoframe_quant_range(frame,
1115 conn_state->connector,
1117 crtc_state->limited_color_range ?
1118 HDMI_QUANTIZATION_RANGE_LIMITED :
1119 HDMI_QUANTIZATION_RANGE_FULL);
1121 ret = hdmi_avi_infoframe_check(frame);
1122 if (drm_WARN_ON(&dev_priv->drm, ret))
1128 static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1129 const struct intel_crtc_state *crtc_state)
1131 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1132 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1133 const union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1136 if ((crtc_state->infoframes.enable &
1137 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI)) == 0)
1140 if (drm_WARN_ON(&dev_priv->drm,
1141 frame->any.type != HDMI_INFOFRAME_TYPE_AVI))
1144 len = hdmi_infoframe_pack_only(frame, sdvo_data, sizeof(sdvo_data));
1145 if (drm_WARN_ON(&dev_priv->drm, len < 0))
1148 return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1153 static void intel_sdvo_get_avi_infoframe(struct intel_sdvo *intel_sdvo,
1154 struct intel_crtc_state *crtc_state)
1156 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1157 union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1161 if (!crtc_state->has_hdmi_sink)
1164 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1165 sdvo_data, sizeof(sdvo_data));
1167 DRM_DEBUG_KMS("failed to read AVI infoframe\n");
1169 } else if (len == 0) {
1173 crtc_state->infoframes.enable |=
1174 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1176 ret = hdmi_infoframe_unpack(frame, sdvo_data, len);
1178 DRM_DEBUG_KMS("Failed to unpack AVI infoframe\n");
1182 if (frame->any.type != HDMI_INFOFRAME_TYPE_AVI)
1183 DRM_DEBUG_KMS("Found the wrong infoframe type 0x%x (expected 0x%02x)\n",
1184 frame->any.type, HDMI_INFOFRAME_TYPE_AVI);
1187 static void intel_sdvo_get_eld(struct intel_sdvo *intel_sdvo,
1188 struct intel_crtc_state *crtc_state)
1190 struct drm_i915_private *i915 = to_i915(intel_sdvo->base.base.dev);
1194 if (!crtc_state->has_audio)
1197 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_AUDIO_STAT, &val, 1))
1200 if ((val & SDVO_AUDIO_ELD_VALID) == 0)
1203 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_ELD,
1204 crtc_state->eld, sizeof(crtc_state->eld));
1206 drm_dbg_kms(&i915->drm, "failed to read ELD\n");
1209 static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo,
1210 const struct drm_connector_state *conn_state)
1212 struct intel_sdvo_tv_format format;
1215 format_map = 1 << conn_state->tv.mode;
1216 memset(&format, 0, sizeof(format));
1217 memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1219 BUILD_BUG_ON(sizeof(format) != 6);
1220 return intel_sdvo_set_value(intel_sdvo,
1221 SDVO_CMD_SET_TV_FORMAT,
1222 &format, sizeof(format));
1226 intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1227 const struct drm_display_mode *mode)
1229 struct intel_sdvo_dtd output_dtd;
1231 if (!intel_sdvo_set_target_output(intel_sdvo,
1232 intel_sdvo->attached_output))
1235 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1236 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1243 * Asks the sdvo controller for the preferred input mode given the output mode.
1244 * Unfortunately we have to set up the full output mode to do that.
1247 intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
1248 struct intel_sdvo_connector *intel_sdvo_connector,
1249 const struct drm_display_mode *mode,
1250 struct drm_display_mode *adjusted_mode)
1252 struct intel_sdvo_dtd input_dtd;
1254 /* Reset the input timing to the screen. Assume always input 0. */
1255 if (!intel_sdvo_set_target_input(intel_sdvo))
1258 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1259 intel_sdvo_connector,
1263 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1267 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1268 intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1273 static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_state *pipe_config)
1275 struct drm_i915_private *dev_priv = to_i915(pipe_config->uapi.crtc->dev);
1276 unsigned dotclock = pipe_config->port_clock;
1277 struct dpll *clock = &pipe_config->dpll;
1280 * SDVO TV has fixed PLL values depend on its clock range,
1281 * this mirrors vbios setting.
1283 if (dotclock >= 100000 && dotclock < 140500) {
1289 } else if (dotclock >= 140500 && dotclock <= 200000) {
1296 drm_WARN(&dev_priv->drm, 1,
1297 "SDVO TV clock out of range: %i\n", dotclock);
1300 pipe_config->clock_set = true;
1303 static bool intel_has_hdmi_sink(struct intel_sdvo_connector *intel_sdvo_connector,
1304 const struct drm_connector_state *conn_state)
1306 struct drm_connector *connector = conn_state->connector;
1308 return intel_sdvo_connector->is_hdmi &&
1309 connector->display_info.is_hdmi &&
1310 READ_ONCE(to_intel_digital_connector_state(conn_state)->force_audio) != HDMI_AUDIO_OFF_DVI;
1313 static bool intel_sdvo_limited_color_range(struct intel_encoder *encoder,
1314 const struct intel_crtc_state *crtc_state,
1315 const struct drm_connector_state *conn_state)
1317 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1319 if ((intel_sdvo->colorimetry_cap & SDVO_COLORIMETRY_RGB220) == 0)
1322 return intel_hdmi_limited_color_range(crtc_state, conn_state);
1325 static bool intel_sdvo_has_audio(struct intel_encoder *encoder,
1326 const struct intel_crtc_state *crtc_state,
1327 const struct drm_connector_state *conn_state)
1329 struct drm_connector *connector = conn_state->connector;
1330 struct intel_sdvo_connector *intel_sdvo_connector =
1331 to_intel_sdvo_connector(connector);
1332 const struct intel_digital_connector_state *intel_conn_state =
1333 to_intel_digital_connector_state(conn_state);
1335 if (!crtc_state->has_hdmi_sink)
1338 if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
1339 return intel_sdvo_connector->is_hdmi &&
1340 connector->display_info.has_audio;
1342 return intel_conn_state->force_audio == HDMI_AUDIO_ON;
1345 static int intel_sdvo_compute_config(struct intel_encoder *encoder,
1346 struct intel_crtc_state *pipe_config,
1347 struct drm_connector_state *conn_state)
1349 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1350 struct intel_sdvo_connector *intel_sdvo_connector =
1351 to_intel_sdvo_connector(conn_state->connector);
1352 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1353 struct drm_display_mode *mode = &pipe_config->hw.mode;
1355 DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1356 pipe_config->pipe_bpp = 8*3;
1357 pipe_config->sink_format = INTEL_OUTPUT_FORMAT_RGB;
1358 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
1360 if (HAS_PCH_SPLIT(to_i915(encoder->base.dev)))
1361 pipe_config->has_pch_encoder = true;
1364 * We need to construct preferred input timings based on our
1365 * output timings. To do that, we have to set the output
1366 * timings, even though this isn't really the right place in
1367 * the sequence to do it. Oh well.
1369 if (IS_TV(intel_sdvo_connector)) {
1370 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1373 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1374 intel_sdvo_connector,
1377 pipe_config->sdvo_tv_clock = true;
1378 } else if (IS_LVDS(intel_sdvo_connector)) {
1379 const struct drm_display_mode *fixed_mode =
1380 intel_panel_fixed_mode(&intel_sdvo_connector->base, mode);
1383 ret = intel_panel_compute_config(&intel_sdvo_connector->base,
1388 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, fixed_mode))
1391 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1392 intel_sdvo_connector,
1397 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
1401 * Make the CRTC code factor in the SDVO pixel multiplier. The
1402 * SDVO device will factor out the multiplier during mode_set.
1404 pipe_config->pixel_multiplier =
1405 intel_sdvo_get_pixel_multiplier(adjusted_mode);
1407 pipe_config->has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo_connector, conn_state);
1409 pipe_config->has_audio =
1410 intel_sdvo_has_audio(encoder, pipe_config, conn_state) &&
1411 intel_audio_compute_config(encoder, pipe_config, conn_state);
1413 pipe_config->limited_color_range =
1414 intel_sdvo_limited_color_range(encoder, pipe_config,
1417 /* Clock computation needs to happen after pixel multiplier. */
1418 if (IS_TV(intel_sdvo_connector))
1419 i9xx_adjust_sdvo_tv_clock(pipe_config);
1421 if (conn_state->picture_aspect_ratio)
1422 adjusted_mode->picture_aspect_ratio =
1423 conn_state->picture_aspect_ratio;
1425 if (!intel_sdvo_compute_avi_infoframe(intel_sdvo,
1426 pipe_config, conn_state)) {
1427 DRM_DEBUG_KMS("bad AVI infoframe\n");
1434 #define UPDATE_PROPERTY(input, NAME) \
1437 intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_##NAME, &val, sizeof(val)); \
1440 static void intel_sdvo_update_props(struct intel_sdvo *intel_sdvo,
1441 const struct intel_sdvo_connector_state *sdvo_state)
1443 const struct drm_connector_state *conn_state = &sdvo_state->base.base;
1444 struct intel_sdvo_connector *intel_sdvo_conn =
1445 to_intel_sdvo_connector(conn_state->connector);
1448 if (intel_sdvo_conn->left)
1449 UPDATE_PROPERTY(sdvo_state->tv.overscan_h, OVERSCAN_H);
1451 if (intel_sdvo_conn->top)
1452 UPDATE_PROPERTY(sdvo_state->tv.overscan_v, OVERSCAN_V);
1454 if (intel_sdvo_conn->hpos)
1455 UPDATE_PROPERTY(sdvo_state->tv.hpos, HPOS);
1457 if (intel_sdvo_conn->vpos)
1458 UPDATE_PROPERTY(sdvo_state->tv.vpos, VPOS);
1460 if (intel_sdvo_conn->saturation)
1461 UPDATE_PROPERTY(conn_state->tv.saturation, SATURATION);
1463 if (intel_sdvo_conn->contrast)
1464 UPDATE_PROPERTY(conn_state->tv.contrast, CONTRAST);
1466 if (intel_sdvo_conn->hue)
1467 UPDATE_PROPERTY(conn_state->tv.hue, HUE);
1469 if (intel_sdvo_conn->brightness)
1470 UPDATE_PROPERTY(conn_state->tv.brightness, BRIGHTNESS);
1472 if (intel_sdvo_conn->sharpness)
1473 UPDATE_PROPERTY(sdvo_state->tv.sharpness, SHARPNESS);
1475 if (intel_sdvo_conn->flicker_filter)
1476 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter, FLICKER_FILTER);
1478 if (intel_sdvo_conn->flicker_filter_2d)
1479 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_2d, FLICKER_FILTER_2D);
1481 if (intel_sdvo_conn->flicker_filter_adaptive)
1482 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
1484 if (intel_sdvo_conn->tv_chroma_filter)
1485 UPDATE_PROPERTY(sdvo_state->tv.chroma_filter, TV_CHROMA_FILTER);
1487 if (intel_sdvo_conn->tv_luma_filter)
1488 UPDATE_PROPERTY(sdvo_state->tv.luma_filter, TV_LUMA_FILTER);
1490 if (intel_sdvo_conn->dot_crawl)
1491 UPDATE_PROPERTY(sdvo_state->tv.dot_crawl, DOT_CRAWL);
1493 #undef UPDATE_PROPERTY
1496 static void intel_sdvo_pre_enable(struct intel_atomic_state *state,
1497 struct intel_encoder *intel_encoder,
1498 const struct intel_crtc_state *crtc_state,
1499 const struct drm_connector_state *conn_state)
1501 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
1502 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1503 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
1504 const struct intel_sdvo_connector_state *sdvo_state =
1505 to_intel_sdvo_connector_state(conn_state);
1506 struct intel_sdvo_connector *intel_sdvo_connector =
1507 to_intel_sdvo_connector(conn_state->connector);
1508 const struct drm_display_mode *mode = &crtc_state->hw.mode;
1509 struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
1511 struct intel_sdvo_in_out_map in_out;
1512 struct intel_sdvo_dtd input_dtd, output_dtd;
1515 intel_sdvo_update_props(intel_sdvo, sdvo_state);
1518 * First, set the input mapping for the first input to our controlled
1519 * output. This is only correct if we're a single-input device, in
1520 * which case the first input is the output from the appropriate SDVO
1521 * channel on the motherboard. In a two-input device, the first input
1522 * will be SDVOB and the second SDVOC.
1524 in_out.in0 = intel_sdvo->attached_output;
1527 intel_sdvo_set_value(intel_sdvo,
1528 SDVO_CMD_SET_IN_OUT_MAP,
1529 &in_out, sizeof(in_out));
1531 /* Set the output timings to the screen */
1532 if (!intel_sdvo_set_target_output(intel_sdvo,
1533 intel_sdvo->attached_output))
1536 /* lvds has a special fixed output timing. */
1537 if (IS_LVDS(intel_sdvo_connector)) {
1538 const struct drm_display_mode *fixed_mode =
1539 intel_panel_fixed_mode(&intel_sdvo_connector->base, mode);
1541 intel_sdvo_get_dtd_from_mode(&output_dtd, fixed_mode);
1543 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1545 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1546 drm_info(&dev_priv->drm,
1547 "Setting output timings on %s failed\n",
1548 SDVO_NAME(intel_sdvo));
1550 /* Set the input timing to the screen. Assume always input 0. */
1551 if (!intel_sdvo_set_target_input(intel_sdvo))
1554 if (crtc_state->has_hdmi_sink) {
1555 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
1556 intel_sdvo_set_colorimetry(intel_sdvo,
1557 crtc_state->limited_color_range ?
1558 SDVO_COLORIMETRY_RGB220 :
1559 SDVO_COLORIMETRY_RGB256);
1560 intel_sdvo_set_avi_infoframe(intel_sdvo, crtc_state);
1561 intel_sdvo_set_pixel_replication(intel_sdvo,
1562 !!(adjusted_mode->flags &
1563 DRM_MODE_FLAG_DBLCLK));
1565 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
1567 if (IS_TV(intel_sdvo_connector) &&
1568 !intel_sdvo_set_tv_format(intel_sdvo, conn_state))
1571 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1573 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector))
1574 input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1575 if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1576 drm_info(&dev_priv->drm,
1577 "Setting input timings on %s failed\n",
1578 SDVO_NAME(intel_sdvo));
1580 switch (crtc_state->pixel_multiplier) {
1582 drm_WARN(&dev_priv->drm, 1,
1583 "unknown pixel multiplier specified\n");
1585 case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1586 case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1587 case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1589 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1592 /* Set the SDVO control regs. */
1593 if (DISPLAY_VER(dev_priv) >= 4) {
1594 /* The real mode polarity is set by the SDVO commands, using
1595 * struct intel_sdvo_dtd. */
1596 sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
1597 if (DISPLAY_VER(dev_priv) < 5)
1598 sdvox |= SDVO_BORDER_ENABLE;
1600 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1601 if (intel_sdvo->port == PORT_B)
1602 sdvox &= SDVOB_PRESERVE_MASK;
1604 sdvox &= SDVOC_PRESERVE_MASK;
1605 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1608 if (HAS_PCH_CPT(dev_priv))
1609 sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
1611 sdvox |= SDVO_PIPE_SEL(crtc->pipe);
1613 if (DISPLAY_VER(dev_priv) >= 4) {
1614 /* done in crtc_mode_set as the dpll_md reg must be written early */
1615 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
1616 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
1617 /* done in crtc_mode_set as it lives inside the dpll register */
1619 sdvox |= (crtc_state->pixel_multiplier - 1)
1620 << SDVO_PORT_MULTIPLY_SHIFT;
1623 if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
1624 DISPLAY_VER(dev_priv) < 5)
1625 sdvox |= SDVO_STALL_SELECT;
1626 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1629 static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1631 struct intel_sdvo_connector *intel_sdvo_connector =
1632 to_intel_sdvo_connector(&connector->base);
1633 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1634 u16 active_outputs = 0;
1636 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1638 return active_outputs & intel_sdvo_connector->output_flag;
1641 bool intel_sdvo_port_enabled(struct drm_i915_private *dev_priv,
1642 i915_reg_t sdvo_reg, enum pipe *pipe)
1646 val = intel_de_read(dev_priv, sdvo_reg);
1648 /* asserts want to know the pipe even if the port is disabled */
1649 if (HAS_PCH_CPT(dev_priv))
1650 *pipe = (val & SDVO_PIPE_SEL_MASK_CPT) >> SDVO_PIPE_SEL_SHIFT_CPT;
1651 else if (IS_CHERRYVIEW(dev_priv))
1652 *pipe = (val & SDVO_PIPE_SEL_MASK_CHV) >> SDVO_PIPE_SEL_SHIFT_CHV;
1654 *pipe = (val & SDVO_PIPE_SEL_MASK) >> SDVO_PIPE_SEL_SHIFT;
1656 return val & SDVO_ENABLE;
1659 static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1662 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1663 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1664 u16 active_outputs = 0;
1667 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1669 ret = intel_sdvo_port_enabled(dev_priv, intel_sdvo->sdvo_reg, pipe);
1671 return ret || active_outputs;
1674 static void intel_sdvo_get_config(struct intel_encoder *encoder,
1675 struct intel_crtc_state *pipe_config)
1677 struct drm_device *dev = encoder->base.dev;
1678 struct drm_i915_private *dev_priv = to_i915(dev);
1679 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1680 struct intel_sdvo_dtd dtd;
1681 int encoder_pixel_multiplier = 0;
1683 u32 flags = 0, sdvox;
1687 pipe_config->output_types |= BIT(INTEL_OUTPUT_SDVO);
1689 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1691 ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
1694 * Some sdvo encoders are not spec compliant and don't
1695 * implement the mandatory get_timings function.
1697 drm_dbg(&dev_priv->drm, "failed to retrieve SDVO DTD\n");
1698 pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
1700 if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1701 flags |= DRM_MODE_FLAG_PHSYNC;
1703 flags |= DRM_MODE_FLAG_NHSYNC;
1705 if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1706 flags |= DRM_MODE_FLAG_PVSYNC;
1708 flags |= DRM_MODE_FLAG_NVSYNC;
1711 pipe_config->hw.adjusted_mode.flags |= flags;
1714 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1715 * the sdvo port register, on all other platforms it is part of the dpll
1716 * state. Since the general pipe state readout happens before the
1717 * encoder->get_config we so already have a valid pixel multplier on all
1720 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
1721 pipe_config->pixel_multiplier =
1722 ((sdvox & SDVO_PORT_MULTIPLY_MASK)
1723 >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
1726 dotclock = pipe_config->port_clock;
1728 if (pipe_config->pixel_multiplier)
1729 dotclock /= pipe_config->pixel_multiplier;
1731 pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
1733 /* Cross check the port pixel multiplier with the sdvo encoder state. */
1734 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
1737 case SDVO_CLOCK_RATE_MULT_1X:
1738 encoder_pixel_multiplier = 1;
1740 case SDVO_CLOCK_RATE_MULT_2X:
1741 encoder_pixel_multiplier = 2;
1743 case SDVO_CLOCK_RATE_MULT_4X:
1744 encoder_pixel_multiplier = 4;
1750 encoder_pixel_multiplier != pipe_config->pixel_multiplier,
1751 "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1752 pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1754 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_COLORIMETRY,
1756 if (val == SDVO_COLORIMETRY_RGB220)
1757 pipe_config->limited_color_range = true;
1760 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_AUDIO_STAT,
1762 if (val & SDVO_AUDIO_PRESENCE_DETECT)
1763 pipe_config->has_audio = true;
1766 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE,
1768 if (val == SDVO_ENCODE_HDMI)
1769 pipe_config->has_hdmi_sink = true;
1772 intel_sdvo_get_avi_infoframe(intel_sdvo, pipe_config);
1774 intel_sdvo_get_eld(intel_sdvo, pipe_config);
1777 static void intel_sdvo_disable_audio(struct intel_sdvo *intel_sdvo)
1779 intel_sdvo_set_audio_state(intel_sdvo, 0);
1782 static void intel_sdvo_enable_audio(struct intel_sdvo *intel_sdvo,
1783 const struct intel_crtc_state *crtc_state,
1784 const struct drm_connector_state *conn_state)
1786 const u8 *eld = crtc_state->eld;
1788 intel_sdvo_set_audio_state(intel_sdvo, 0);
1790 intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_ELD,
1791 SDVO_HBUF_TX_DISABLED,
1792 eld, drm_eld_size(eld));
1794 intel_sdvo_set_audio_state(intel_sdvo, SDVO_AUDIO_ELD_VALID |
1795 SDVO_AUDIO_PRESENCE_DETECT);
1798 static void intel_disable_sdvo(struct intel_atomic_state *state,
1799 struct intel_encoder *encoder,
1800 const struct intel_crtc_state *old_crtc_state,
1801 const struct drm_connector_state *conn_state)
1803 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1804 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1805 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1808 if (old_crtc_state->has_audio)
1809 intel_sdvo_disable_audio(intel_sdvo);
1811 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1813 intel_sdvo_set_encoder_power_state(intel_sdvo,
1816 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1818 temp &= ~SDVO_ENABLE;
1819 intel_sdvo_write_sdvox(intel_sdvo, temp);
1822 * HW workaround for IBX, we need to move the port
1823 * to transcoder A after disabling it to allow the
1824 * matching DP port to be enabled on transcoder A.
1826 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1828 * We get CPU/PCH FIFO underruns on the other pipe when
1829 * doing the workaround. Sweep them under the rug.
1831 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1832 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1834 temp &= ~SDVO_PIPE_SEL_MASK;
1835 temp |= SDVO_ENABLE | SDVO_PIPE_SEL(PIPE_A);
1836 intel_sdvo_write_sdvox(intel_sdvo, temp);
1838 temp &= ~SDVO_ENABLE;
1839 intel_sdvo_write_sdvox(intel_sdvo, temp);
1841 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1842 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1843 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1847 static void pch_disable_sdvo(struct intel_atomic_state *state,
1848 struct intel_encoder *encoder,
1849 const struct intel_crtc_state *old_crtc_state,
1850 const struct drm_connector_state *old_conn_state)
1854 static void pch_post_disable_sdvo(struct intel_atomic_state *state,
1855 struct intel_encoder *encoder,
1856 const struct intel_crtc_state *old_crtc_state,
1857 const struct drm_connector_state *old_conn_state)
1859 intel_disable_sdvo(state, encoder, old_crtc_state, old_conn_state);
1862 static void intel_enable_sdvo(struct intel_atomic_state *state,
1863 struct intel_encoder *encoder,
1864 const struct intel_crtc_state *pipe_config,
1865 const struct drm_connector_state *conn_state)
1867 struct drm_device *dev = encoder->base.dev;
1868 struct drm_i915_private *dev_priv = to_i915(dev);
1869 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1870 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
1872 bool input1, input2;
1876 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1877 temp |= SDVO_ENABLE;
1878 intel_sdvo_write_sdvox(intel_sdvo, temp);
1880 for (i = 0; i < 2; i++)
1881 intel_crtc_wait_for_next_vblank(crtc);
1883 success = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1885 * Warn if the device reported failure to sync.
1887 * A lot of SDVO devices fail to notify of sync, but it's
1888 * a given it the status is a success, we succeeded.
1890 if (success && !input1) {
1891 drm_dbg_kms(&dev_priv->drm,
1892 "First %s output reported failure to "
1893 "sync\n", SDVO_NAME(intel_sdvo));
1897 intel_sdvo_set_encoder_power_state(intel_sdvo,
1899 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1901 if (pipe_config->has_audio)
1902 intel_sdvo_enable_audio(intel_sdvo, pipe_config, conn_state);
1905 static enum drm_mode_status
1906 intel_sdvo_mode_valid(struct drm_connector *connector,
1907 struct drm_display_mode *mode)
1909 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
1910 struct intel_sdvo_connector *intel_sdvo_connector =
1911 to_intel_sdvo_connector(connector);
1912 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1913 bool has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo_connector, connector->state);
1914 int clock = mode->clock;
1916 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1917 return MODE_NO_DBLESCAN;
1919 if (clock > max_dotclk)
1920 return MODE_CLOCK_HIGH;
1922 if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
1924 return MODE_CLOCK_LOW;
1928 if (intel_sdvo->pixel_clock_min > clock)
1929 return MODE_CLOCK_LOW;
1931 if (intel_sdvo->pixel_clock_max < clock)
1932 return MODE_CLOCK_HIGH;
1934 if (IS_LVDS(intel_sdvo_connector)) {
1935 enum drm_mode_status status;
1937 status = intel_panel_mode_valid(&intel_sdvo_connector->base, mode);
1938 if (status != MODE_OK)
1945 static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1947 BUILD_BUG_ON(sizeof(*caps) != 8);
1948 if (!intel_sdvo_get_value(intel_sdvo,
1949 SDVO_CMD_GET_DEVICE_CAPS,
1950 caps, sizeof(*caps)))
1953 DRM_DEBUG_KMS("SDVO capabilities:\n"
1956 " device_rev_id: %d\n"
1957 " sdvo_version_major: %d\n"
1958 " sdvo_version_minor: %d\n"
1959 " sdvo_inputs_mask: %d\n"
1960 " smooth_scaling: %d\n"
1961 " sharp_scaling: %d\n"
1963 " down_scaling: %d\n"
1964 " stall_support: %d\n"
1965 " output_flags: %d\n",
1968 caps->device_rev_id,
1969 caps->sdvo_version_major,
1970 caps->sdvo_version_minor,
1971 caps->sdvo_inputs_mask,
1972 caps->smooth_scaling,
1973 caps->sharp_scaling,
1976 caps->stall_support,
1977 caps->output_flags);
1982 static u8 intel_sdvo_get_colorimetry_cap(struct intel_sdvo *intel_sdvo)
1986 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_COLORIMETRY_CAP,
1988 return SDVO_COLORIMETRY_RGB256;
1993 static u16 intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1995 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1998 if (!I915_HAS_HOTPLUG(dev_priv))
2002 * HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
2005 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
2008 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
2009 &hotplug, sizeof(hotplug)))
2015 static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
2017 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
2019 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
2020 &intel_sdvo->hotplug_active, 2);
2023 static enum intel_hotplug_state
2024 intel_sdvo_hotplug(struct intel_encoder *encoder,
2025 struct intel_connector *connector)
2027 intel_sdvo_enable_hotplug(encoder);
2029 return intel_encoder_hotplug(encoder, connector);
2033 intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
2035 /* Is there more than one type of output? */
2036 return hweight16(intel_sdvo->caps.output_flags) > 1;
2039 static struct edid *
2040 intel_sdvo_get_edid(struct drm_connector *connector)
2042 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2043 return drm_get_edid(connector, &sdvo->ddc);
2046 /* Mac mini hack -- use the same DDC as the analog connector */
2047 static struct edid *
2048 intel_sdvo_get_analog_edid(struct drm_connector *connector)
2050 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2052 return drm_get_edid(connector,
2053 intel_gmbus_get_adapter(dev_priv,
2054 dev_priv->display.vbt.crt_ddc_pin));
2057 static enum drm_connector_status
2058 intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
2060 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2061 enum drm_connector_status status;
2064 edid = intel_sdvo_get_edid(connector);
2066 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
2067 u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
2070 * Don't use the 1 as the argument of DDC bus switch to get
2071 * the EDID. It is used for SDVO SPD ROM.
2073 for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
2074 intel_sdvo->ddc_bus = ddc;
2075 edid = intel_sdvo_get_edid(connector);
2080 * If we found the EDID on the other bus,
2081 * assume that is the correct DDC bus.
2084 intel_sdvo->ddc_bus = saved_ddc;
2088 * When there is no edid and no monitor is connected with VGA
2089 * port, try to use the CRT ddc to read the EDID for DVI-connector.
2092 edid = intel_sdvo_get_analog_edid(connector);
2094 status = connector_status_unknown;
2096 /* DDC bus is shared, match EDID to connector type */
2097 if (edid->input & DRM_EDID_INPUT_DIGITAL)
2098 status = connector_status_connected;
2100 status = connector_status_disconnected;
2108 intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
2111 bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
2112 bool connector_is_digital = !!IS_DIGITAL(sdvo);
2114 DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
2115 connector_is_digital, monitor_is_digital);
2116 return connector_is_digital == monitor_is_digital;
2119 static enum drm_connector_status
2120 intel_sdvo_detect(struct drm_connector *connector, bool force)
2122 struct drm_i915_private *i915 = to_i915(connector->dev);
2123 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2124 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2125 enum drm_connector_status ret;
2128 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2129 connector->base.id, connector->name);
2131 if (!INTEL_DISPLAY_ENABLED(i915))
2132 return connector_status_disconnected;
2134 if (!intel_sdvo_get_value(intel_sdvo,
2135 SDVO_CMD_GET_ATTACHED_DISPLAYS,
2137 return connector_status_unknown;
2139 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
2140 response & 0xff, response >> 8,
2141 intel_sdvo_connector->output_flag);
2144 return connector_status_disconnected;
2146 intel_sdvo->attached_output = response;
2148 if ((intel_sdvo_connector->output_flag & response) == 0)
2149 ret = connector_status_disconnected;
2150 else if (IS_TMDS(intel_sdvo_connector))
2151 ret = intel_sdvo_tmds_sink_detect(connector);
2155 /* if we have an edid check it matches the connection */
2156 edid = intel_sdvo_get_edid(connector);
2158 edid = intel_sdvo_get_analog_edid(connector);
2160 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
2162 ret = connector_status_connected;
2164 ret = connector_status_disconnected;
2168 ret = connector_status_connected;
2174 static int intel_sdvo_get_ddc_modes(struct drm_connector *connector)
2179 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2180 connector->base.id, connector->name);
2182 /* set the bus switch and get the modes */
2183 edid = intel_sdvo_get_edid(connector);
2186 * Mac mini hack. On this device, the DVI-I connector shares one DDC
2187 * link between analog and digital outputs. So, if the regular SDVO
2188 * DDC fails, check to see if the analog output is disconnected, in
2189 * which case we'll look there for the digital DDC data.
2192 edid = intel_sdvo_get_analog_edid(connector);
2197 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
2199 num_modes += intel_connector_update_modes(connector, edid);
2207 * Set of SDVO TV modes.
2208 * Note! This is in reply order (see loop in get_tv_modes).
2209 * XXX: all 60Hz refresh?
2211 static const struct drm_display_mode sdvo_tv_modes[] = {
2212 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
2213 416, 0, 200, 201, 232, 233, 0,
2214 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2215 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
2216 416, 0, 240, 241, 272, 273, 0,
2217 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2218 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
2219 496, 0, 300, 301, 332, 333, 0,
2220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2221 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
2222 736, 0, 350, 351, 382, 383, 0,
2223 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2224 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
2225 736, 0, 400, 401, 432, 433, 0,
2226 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2227 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
2228 736, 0, 480, 481, 512, 513, 0,
2229 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2230 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
2231 800, 0, 480, 481, 512, 513, 0,
2232 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2233 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
2234 800, 0, 576, 577, 608, 609, 0,
2235 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2236 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
2237 816, 0, 350, 351, 382, 383, 0,
2238 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2239 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
2240 816, 0, 400, 401, 432, 433, 0,
2241 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2242 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
2243 816, 0, 480, 481, 512, 513, 0,
2244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2245 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
2246 816, 0, 540, 541, 572, 573, 0,
2247 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2248 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
2249 816, 0, 576, 577, 608, 609, 0,
2250 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2251 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
2252 864, 0, 576, 577, 608, 609, 0,
2253 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2254 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
2255 896, 0, 600, 601, 632, 633, 0,
2256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2257 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
2258 928, 0, 624, 625, 656, 657, 0,
2259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2260 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
2261 1016, 0, 766, 767, 798, 799, 0,
2262 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2263 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
2264 1120, 0, 768, 769, 800, 801, 0,
2265 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2266 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
2267 1376, 0, 1024, 1025, 1056, 1057, 0,
2268 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2271 static int intel_sdvo_get_tv_modes(struct drm_connector *connector)
2273 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2274 const struct drm_connector_state *conn_state = connector->state;
2275 struct intel_sdvo_sdtv_resolution_request tv_res;
2276 u32 reply = 0, format_map = 0;
2280 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2281 connector->base.id, connector->name);
2284 * Read the list of supported input resolutions for the selected TV
2287 format_map = 1 << conn_state->tv.mode;
2288 memcpy(&tv_res, &format_map,
2289 min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
2291 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
2294 BUILD_BUG_ON(sizeof(tv_res) != 3);
2295 if (!intel_sdvo_write_cmd(intel_sdvo,
2296 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
2297 &tv_res, sizeof(tv_res)))
2299 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
2302 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++) {
2303 if (reply & (1 << i)) {
2304 struct drm_display_mode *nmode;
2305 nmode = drm_mode_duplicate(connector->dev,
2308 drm_mode_probed_add(connector, nmode);
2317 static int intel_sdvo_get_lvds_modes(struct drm_connector *connector)
2319 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2321 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s]\n",
2322 connector->base.id, connector->name);
2324 return intel_panel_get_modes(to_intel_connector(connector));
2327 static int intel_sdvo_get_modes(struct drm_connector *connector)
2329 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2331 if (IS_TV(intel_sdvo_connector))
2332 return intel_sdvo_get_tv_modes(connector);
2333 else if (IS_LVDS(intel_sdvo_connector))
2334 return intel_sdvo_get_lvds_modes(connector);
2336 return intel_sdvo_get_ddc_modes(connector);
2340 intel_sdvo_connector_atomic_get_property(struct drm_connector *connector,
2341 const struct drm_connector_state *state,
2342 struct drm_property *property,
2345 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2346 const struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state((void *)state);
2348 if (property == intel_sdvo_connector->tv_format) {
2351 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2352 if (state->tv.mode == intel_sdvo_connector->tv_format_supported[i]) {
2358 drm_WARN_ON(connector->dev, 1);
2360 } else if (property == intel_sdvo_connector->top ||
2361 property == intel_sdvo_connector->bottom)
2362 *val = intel_sdvo_connector->max_vscan - sdvo_state->tv.overscan_v;
2363 else if (property == intel_sdvo_connector->left ||
2364 property == intel_sdvo_connector->right)
2365 *val = intel_sdvo_connector->max_hscan - sdvo_state->tv.overscan_h;
2366 else if (property == intel_sdvo_connector->hpos)
2367 *val = sdvo_state->tv.hpos;
2368 else if (property == intel_sdvo_connector->vpos)
2369 *val = sdvo_state->tv.vpos;
2370 else if (property == intel_sdvo_connector->saturation)
2371 *val = state->tv.saturation;
2372 else if (property == intel_sdvo_connector->contrast)
2373 *val = state->tv.contrast;
2374 else if (property == intel_sdvo_connector->hue)
2375 *val = state->tv.hue;
2376 else if (property == intel_sdvo_connector->brightness)
2377 *val = state->tv.brightness;
2378 else if (property == intel_sdvo_connector->sharpness)
2379 *val = sdvo_state->tv.sharpness;
2380 else if (property == intel_sdvo_connector->flicker_filter)
2381 *val = sdvo_state->tv.flicker_filter;
2382 else if (property == intel_sdvo_connector->flicker_filter_2d)
2383 *val = sdvo_state->tv.flicker_filter_2d;
2384 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2385 *val = sdvo_state->tv.flicker_filter_adaptive;
2386 else if (property == intel_sdvo_connector->tv_chroma_filter)
2387 *val = sdvo_state->tv.chroma_filter;
2388 else if (property == intel_sdvo_connector->tv_luma_filter)
2389 *val = sdvo_state->tv.luma_filter;
2390 else if (property == intel_sdvo_connector->dot_crawl)
2391 *val = sdvo_state->tv.dot_crawl;
2393 return intel_digital_connector_atomic_get_property(connector, state, property, val);
2399 intel_sdvo_connector_atomic_set_property(struct drm_connector *connector,
2400 struct drm_connector_state *state,
2401 struct drm_property *property,
2404 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2405 struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state(state);
2407 if (property == intel_sdvo_connector->tv_format) {
2408 state->tv.mode = intel_sdvo_connector->tv_format_supported[val];
2411 struct drm_crtc_state *crtc_state =
2412 drm_atomic_get_new_crtc_state(state->state, state->crtc);
2414 crtc_state->connectors_changed = true;
2416 } else if (property == intel_sdvo_connector->top ||
2417 property == intel_sdvo_connector->bottom)
2418 /* Cannot set these independent from each other */
2419 sdvo_state->tv.overscan_v = intel_sdvo_connector->max_vscan - val;
2420 else if (property == intel_sdvo_connector->left ||
2421 property == intel_sdvo_connector->right)
2422 /* Cannot set these independent from each other */
2423 sdvo_state->tv.overscan_h = intel_sdvo_connector->max_hscan - val;
2424 else if (property == intel_sdvo_connector->hpos)
2425 sdvo_state->tv.hpos = val;
2426 else if (property == intel_sdvo_connector->vpos)
2427 sdvo_state->tv.vpos = val;
2428 else if (property == intel_sdvo_connector->saturation)
2429 state->tv.saturation = val;
2430 else if (property == intel_sdvo_connector->contrast)
2431 state->tv.contrast = val;
2432 else if (property == intel_sdvo_connector->hue)
2433 state->tv.hue = val;
2434 else if (property == intel_sdvo_connector->brightness)
2435 state->tv.brightness = val;
2436 else if (property == intel_sdvo_connector->sharpness)
2437 sdvo_state->tv.sharpness = val;
2438 else if (property == intel_sdvo_connector->flicker_filter)
2439 sdvo_state->tv.flicker_filter = val;
2440 else if (property == intel_sdvo_connector->flicker_filter_2d)
2441 sdvo_state->tv.flicker_filter_2d = val;
2442 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2443 sdvo_state->tv.flicker_filter_adaptive = val;
2444 else if (property == intel_sdvo_connector->tv_chroma_filter)
2445 sdvo_state->tv.chroma_filter = val;
2446 else if (property == intel_sdvo_connector->tv_luma_filter)
2447 sdvo_state->tv.luma_filter = val;
2448 else if (property == intel_sdvo_connector->dot_crawl)
2449 sdvo_state->tv.dot_crawl = val;
2451 return intel_digital_connector_atomic_set_property(connector, state, property, val);
2457 intel_sdvo_connector_register(struct drm_connector *connector)
2459 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2462 ret = intel_connector_register(connector);
2466 return sysfs_create_link(&connector->kdev->kobj,
2467 &sdvo->ddc.dev.kobj,
2468 sdvo->ddc.dev.kobj.name);
2472 intel_sdvo_connector_unregister(struct drm_connector *connector)
2474 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2476 sysfs_remove_link(&connector->kdev->kobj,
2477 sdvo->ddc.dev.kobj.name);
2478 intel_connector_unregister(connector);
2481 static struct drm_connector_state *
2482 intel_sdvo_connector_duplicate_state(struct drm_connector *connector)
2484 struct intel_sdvo_connector_state *state;
2486 state = kmemdup(connector->state, sizeof(*state), GFP_KERNEL);
2490 __drm_atomic_helper_connector_duplicate_state(connector, &state->base.base);
2491 return &state->base.base;
2494 static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
2495 .detect = intel_sdvo_detect,
2496 .fill_modes = drm_helper_probe_single_connector_modes,
2497 .atomic_get_property = intel_sdvo_connector_atomic_get_property,
2498 .atomic_set_property = intel_sdvo_connector_atomic_set_property,
2499 .late_register = intel_sdvo_connector_register,
2500 .early_unregister = intel_sdvo_connector_unregister,
2501 .destroy = intel_connector_destroy,
2502 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
2503 .atomic_duplicate_state = intel_sdvo_connector_duplicate_state,
2506 static int intel_sdvo_atomic_check(struct drm_connector *conn,
2507 struct drm_atomic_state *state)
2509 struct drm_connector_state *new_conn_state =
2510 drm_atomic_get_new_connector_state(state, conn);
2511 struct drm_connector_state *old_conn_state =
2512 drm_atomic_get_old_connector_state(state, conn);
2513 struct intel_sdvo_connector_state *old_state =
2514 to_intel_sdvo_connector_state(old_conn_state);
2515 struct intel_sdvo_connector_state *new_state =
2516 to_intel_sdvo_connector_state(new_conn_state);
2518 if (new_conn_state->crtc &&
2519 (memcmp(&old_state->tv, &new_state->tv, sizeof(old_state->tv)) ||
2520 memcmp(&old_conn_state->tv, &new_conn_state->tv, sizeof(old_conn_state->tv)))) {
2521 struct drm_crtc_state *crtc_state =
2522 drm_atomic_get_new_crtc_state(state,
2523 new_conn_state->crtc);
2525 crtc_state->connectors_changed = true;
2528 return intel_digital_connector_atomic_check(conn, state);
2531 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2532 .get_modes = intel_sdvo_get_modes,
2533 .mode_valid = intel_sdvo_mode_valid,
2534 .atomic_check = intel_sdvo_atomic_check,
2537 static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2539 struct intel_sdvo *intel_sdvo = to_sdvo(to_intel_encoder(encoder));
2541 i2c_del_adapter(&intel_sdvo->ddc);
2542 intel_encoder_destroy(encoder);
2545 static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2546 .destroy = intel_sdvo_enc_destroy,
2550 intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
2553 unsigned int num_bits;
2556 * Make a mask of outputs less than or equal to our own priority in the
2559 switch (sdvo->controlled_output) {
2560 case SDVO_OUTPUT_LVDS1:
2561 mask |= SDVO_OUTPUT_LVDS1;
2563 case SDVO_OUTPUT_LVDS0:
2564 mask |= SDVO_OUTPUT_LVDS0;
2566 case SDVO_OUTPUT_TMDS1:
2567 mask |= SDVO_OUTPUT_TMDS1;
2569 case SDVO_OUTPUT_TMDS0:
2570 mask |= SDVO_OUTPUT_TMDS0;
2572 case SDVO_OUTPUT_RGB1:
2573 mask |= SDVO_OUTPUT_RGB1;
2575 case SDVO_OUTPUT_RGB0:
2576 mask |= SDVO_OUTPUT_RGB0;
2580 /* Count bits to find what number we are in the priority list. */
2581 mask &= sdvo->caps.output_flags;
2582 num_bits = hweight16(mask);
2583 /* If more than 3 outputs, default to DDC bus 3 for now. */
2587 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2588 sdvo->ddc_bus = 1 << num_bits;
2592 * Choose the appropriate DDC bus for control bus switch command for this
2593 * SDVO output based on the controlled output.
2595 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2596 * outputs, then LVDS outputs.
2599 intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
2600 struct intel_sdvo *sdvo)
2602 struct sdvo_device_mapping *mapping;
2604 if (sdvo->port == PORT_B)
2605 mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2607 mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2609 if (mapping->initialized)
2610 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
2612 intel_sdvo_guess_ddc_bus(sdvo);
2616 intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
2617 struct intel_sdvo *sdvo)
2619 struct sdvo_device_mapping *mapping;
2622 if (sdvo->port == PORT_B)
2623 mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2625 mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2627 if (mapping->initialized &&
2628 intel_gmbus_is_valid_pin(dev_priv, mapping->i2c_pin))
2629 pin = mapping->i2c_pin;
2631 pin = GMBUS_PIN_DPB;
2633 sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
2636 * With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
2637 * our code totally fails once we start using gmbus. Hence fall back to
2638 * bit banging for now.
2640 intel_gmbus_force_bit(sdvo->i2c, true);
2643 /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
2645 intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
2647 intel_gmbus_force_bit(sdvo->i2c, false);
2651 intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo)
2653 return intel_sdvo_check_supp_encode(intel_sdvo);
2657 intel_sdvo_get_slave_addr(struct drm_i915_private *dev_priv,
2658 struct intel_sdvo *sdvo)
2660 struct sdvo_device_mapping *my_mapping, *other_mapping;
2662 if (sdvo->port == PORT_B) {
2663 my_mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2664 other_mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2666 my_mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2667 other_mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2670 /* If the BIOS described our SDVO device, take advantage of it. */
2671 if (my_mapping->slave_addr)
2672 return my_mapping->slave_addr;
2675 * If the BIOS only described a different SDVO device, use the
2676 * address that it isn't using.
2678 if (other_mapping->slave_addr) {
2679 if (other_mapping->slave_addr == 0x70)
2686 * No SDVO device info is found for another DVO port,
2687 * so use mapping assumption we had before BIOS parsing.
2689 if (sdvo->port == PORT_B)
2696 intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2697 struct intel_sdvo *encoder)
2699 struct drm_connector *drm_connector;
2702 drm_connector = &connector->base.base;
2703 ret = drm_connector_init(encoder->base.base.dev,
2705 &intel_sdvo_connector_funcs,
2706 connector->base.base.connector_type);
2710 drm_connector_helper_add(drm_connector,
2711 &intel_sdvo_connector_helper_funcs);
2713 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2714 connector->base.base.interlace_allowed = true;
2715 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2717 intel_connector_attach_encoder(&connector->base, &encoder->base);
2723 intel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
2724 struct intel_sdvo_connector *connector)
2726 intel_attach_force_audio_property(&connector->base.base);
2727 if (intel_sdvo->colorimetry_cap & SDVO_COLORIMETRY_RGB220)
2728 intel_attach_broadcast_rgb_property(&connector->base.base);
2729 intel_attach_aspect_ratio_property(&connector->base.base);
2732 static struct intel_sdvo_connector *intel_sdvo_connector_alloc(void)
2734 struct intel_sdvo_connector *sdvo_connector;
2735 struct intel_sdvo_connector_state *conn_state;
2737 sdvo_connector = kzalloc(sizeof(*sdvo_connector), GFP_KERNEL);
2738 if (!sdvo_connector)
2741 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
2743 kfree(sdvo_connector);
2747 __drm_atomic_helper_connector_reset(&sdvo_connector->base.base,
2748 &conn_state->base.base);
2750 INIT_LIST_HEAD(&sdvo_connector->base.panel.fixed_modes);
2752 return sdvo_connector;
2756 intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, u16 type)
2758 struct drm_encoder *encoder = &intel_sdvo->base.base;
2759 struct drm_connector *connector;
2760 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2761 struct intel_connector *intel_connector;
2762 struct intel_sdvo_connector *intel_sdvo_connector;
2764 DRM_DEBUG_KMS("initialising DVI type 0x%x\n", type);
2766 intel_sdvo_connector = intel_sdvo_connector_alloc();
2767 if (!intel_sdvo_connector)
2770 intel_sdvo_connector->output_flag = type;
2772 intel_connector = &intel_sdvo_connector->base;
2773 connector = &intel_connector->base;
2774 if (intel_sdvo_get_hotplug_support(intel_sdvo) &
2775 intel_sdvo_connector->output_flag) {
2776 intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
2778 * Some SDVO devices have one-shot hotplug interrupts.
2779 * Ensure that they get re-enabled when an interrupt happens.
2781 intel_connector->polled = DRM_CONNECTOR_POLL_HPD;
2782 intel_encoder->hotplug = intel_sdvo_hotplug;
2783 intel_sdvo_enable_hotplug(intel_encoder);
2785 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2787 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2788 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2790 if (intel_sdvo_is_hdmi_connector(intel_sdvo)) {
2791 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2792 intel_sdvo_connector->is_hdmi = true;
2795 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2796 kfree(intel_sdvo_connector);
2800 if (intel_sdvo_connector->is_hdmi)
2801 intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
2807 intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, u16 type)
2809 struct drm_encoder *encoder = &intel_sdvo->base.base;
2810 struct drm_connector *connector;
2811 struct intel_connector *intel_connector;
2812 struct intel_sdvo_connector *intel_sdvo_connector;
2814 DRM_DEBUG_KMS("initialising TV type 0x%x\n", type);
2816 intel_sdvo_connector = intel_sdvo_connector_alloc();
2817 if (!intel_sdvo_connector)
2820 intel_connector = &intel_sdvo_connector->base;
2821 connector = &intel_connector->base;
2822 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2823 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2825 intel_sdvo_connector->output_flag = type;
2827 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2828 kfree(intel_sdvo_connector);
2832 if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
2835 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2841 intel_connector_destroy(connector);
2846 intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, u16 type)
2848 struct drm_encoder *encoder = &intel_sdvo->base.base;
2849 struct drm_connector *connector;
2850 struct intel_connector *intel_connector;
2851 struct intel_sdvo_connector *intel_sdvo_connector;
2853 DRM_DEBUG_KMS("initialising analog type 0x%x\n", type);
2855 intel_sdvo_connector = intel_sdvo_connector_alloc();
2856 if (!intel_sdvo_connector)
2859 intel_connector = &intel_sdvo_connector->base;
2860 connector = &intel_connector->base;
2861 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2862 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2863 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2865 intel_sdvo_connector->output_flag = type;
2867 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2868 kfree(intel_sdvo_connector);
2876 intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, u16 type)
2878 struct drm_encoder *encoder = &intel_sdvo->base.base;
2879 struct drm_i915_private *i915 = to_i915(encoder->dev);
2880 struct drm_connector *connector;
2881 struct intel_connector *intel_connector;
2882 struct intel_sdvo_connector *intel_sdvo_connector;
2884 DRM_DEBUG_KMS("initialising LVDS type 0x%x\n", type);
2886 intel_sdvo_connector = intel_sdvo_connector_alloc();
2887 if (!intel_sdvo_connector)
2890 intel_connector = &intel_sdvo_connector->base;
2891 connector = &intel_connector->base;
2892 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2893 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2895 intel_sdvo_connector->output_flag = type;
2897 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2898 kfree(intel_sdvo_connector);
2902 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2905 intel_bios_init_panel_late(i915, &intel_connector->panel, NULL, NULL);
2908 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
2909 * SDVO->LVDS transcoders can't cope with the EDID mode.
2911 intel_panel_add_vbt_sdvo_fixed_mode(intel_connector);
2913 if (!intel_panel_preferred_fixed_mode(intel_connector)) {
2914 mutex_lock(&i915->drm.mode_config.mutex);
2916 intel_ddc_get_modes(connector, &intel_sdvo->ddc);
2917 intel_panel_add_edid_fixed_modes(intel_connector, false);
2919 mutex_unlock(&i915->drm.mode_config.mutex);
2922 intel_panel_init(intel_connector, NULL);
2924 if (!intel_panel_preferred_fixed_mode(intel_connector))
2930 intel_connector_destroy(connector);
2934 static u16 intel_sdvo_filter_output_flags(u16 flags)
2936 flags &= SDVO_OUTPUT_MASK;
2938 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2939 if (!(flags & SDVO_OUTPUT_TMDS0))
2940 flags &= ~SDVO_OUTPUT_TMDS1;
2942 if (!(flags & SDVO_OUTPUT_RGB0))
2943 flags &= ~SDVO_OUTPUT_RGB1;
2945 if (!(flags & SDVO_OUTPUT_LVDS0))
2946 flags &= ~SDVO_OUTPUT_LVDS1;
2951 static bool intel_sdvo_output_init(struct intel_sdvo *sdvo, u16 type)
2953 if (type & SDVO_TMDS_MASK)
2954 return intel_sdvo_dvi_init(sdvo, type);
2955 else if (type & SDVO_TV_MASK)
2956 return intel_sdvo_tv_init(sdvo, type);
2957 else if (type & SDVO_RGB_MASK)
2958 return intel_sdvo_analog_init(sdvo, type);
2959 else if (type & SDVO_LVDS_MASK)
2960 return intel_sdvo_lvds_init(sdvo, type);
2966 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo)
2968 static const u16 probe_order[] = {
2971 /* TV has no XXX1 function block */
2980 struct drm_i915_private *i915 = to_i915(intel_sdvo->base.base.dev);
2984 flags = intel_sdvo_filter_output_flags(intel_sdvo->caps.output_flags);
2987 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%04x)\n",
2988 SDVO_NAME(intel_sdvo), intel_sdvo->caps.output_flags);
2992 intel_sdvo->controlled_output = flags;
2994 intel_sdvo_select_ddc_bus(i915, intel_sdvo);
2996 for (i = 0; i < ARRAY_SIZE(probe_order); i++) {
2997 u16 type = flags & probe_order[i];
3002 if (!intel_sdvo_output_init(intel_sdvo, type))
3006 intel_sdvo->base.pipe_mask = ~0;
3011 static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
3013 struct drm_device *dev = intel_sdvo->base.base.dev;
3014 struct drm_connector *connector, *tmp;
3016 list_for_each_entry_safe(connector, tmp,
3017 &dev->mode_config.connector_list, head) {
3018 if (intel_attached_encoder(to_intel_connector(connector)) == &intel_sdvo->base) {
3019 drm_connector_unregister(connector);
3020 intel_connector_destroy(connector);
3025 static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
3026 struct intel_sdvo_connector *intel_sdvo_connector,
3029 struct drm_device *dev = intel_sdvo->base.base.dev;
3030 struct intel_sdvo_tv_format format;
3033 if (!intel_sdvo_set_target_output(intel_sdvo, type))
3036 BUILD_BUG_ON(sizeof(format) != 6);
3037 if (!intel_sdvo_get_value(intel_sdvo,
3038 SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
3039 &format, sizeof(format)))
3042 memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
3044 if (format_map == 0)
3047 intel_sdvo_connector->format_supported_num = 0;
3048 for (i = 0 ; i < TV_FORMAT_NUM; i++)
3049 if (format_map & (1 << i))
3050 intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
3053 intel_sdvo_connector->tv_format =
3054 drm_property_create(dev, DRM_MODE_PROP_ENUM,
3055 "mode", intel_sdvo_connector->format_supported_num);
3056 if (!intel_sdvo_connector->tv_format)
3059 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
3060 drm_property_add_enum(intel_sdvo_connector->tv_format, i,
3061 tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
3063 intel_sdvo_connector->base.base.state->tv.mode = intel_sdvo_connector->tv_format_supported[0];
3064 drm_object_attach_property(&intel_sdvo_connector->base.base.base,
3065 intel_sdvo_connector->tv_format, 0);
3070 #define _ENHANCEMENT(state_assignment, name, NAME) do { \
3071 if (enhancements.name) { \
3072 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
3073 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
3075 intel_sdvo_connector->name = \
3076 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
3077 if (!intel_sdvo_connector->name) return false; \
3078 state_assignment = response; \
3079 drm_object_attach_property(&connector->base, \
3080 intel_sdvo_connector->name, 0); \
3081 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
3082 data_value[0], data_value[1], response); \
3086 #define ENHANCEMENT(state, name, NAME) _ENHANCEMENT((state)->name, name, NAME)
3089 intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
3090 struct intel_sdvo_connector *intel_sdvo_connector,
3091 struct intel_sdvo_enhancements_reply enhancements)
3093 struct drm_device *dev = intel_sdvo->base.base.dev;
3094 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3095 struct drm_connector_state *conn_state = connector->state;
3096 struct intel_sdvo_connector_state *sdvo_state =
3097 to_intel_sdvo_connector_state(conn_state);
3098 u16 response, data_value[2];
3100 /* when horizontal overscan is supported, Add the left/right property */
3101 if (enhancements.overscan_h) {
3102 if (!intel_sdvo_get_value(intel_sdvo,
3103 SDVO_CMD_GET_MAX_OVERSCAN_H,
3107 if (!intel_sdvo_get_value(intel_sdvo,
3108 SDVO_CMD_GET_OVERSCAN_H,
3112 sdvo_state->tv.overscan_h = response;
3114 intel_sdvo_connector->max_hscan = data_value[0];
3115 intel_sdvo_connector->left =
3116 drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
3117 if (!intel_sdvo_connector->left)
3120 drm_object_attach_property(&connector->base,
3121 intel_sdvo_connector->left, 0);
3123 intel_sdvo_connector->right =
3124 drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
3125 if (!intel_sdvo_connector->right)
3128 drm_object_attach_property(&connector->base,
3129 intel_sdvo_connector->right, 0);
3130 DRM_DEBUG_KMS("h_overscan: max %d, "
3131 "default %d, current %d\n",
3132 data_value[0], data_value[1], response);
3135 if (enhancements.overscan_v) {
3136 if (!intel_sdvo_get_value(intel_sdvo,
3137 SDVO_CMD_GET_MAX_OVERSCAN_V,
3141 if (!intel_sdvo_get_value(intel_sdvo,
3142 SDVO_CMD_GET_OVERSCAN_V,
3146 sdvo_state->tv.overscan_v = response;
3148 intel_sdvo_connector->max_vscan = data_value[0];
3149 intel_sdvo_connector->top =
3150 drm_property_create_range(dev, 0,
3151 "top_margin", 0, data_value[0]);
3152 if (!intel_sdvo_connector->top)
3155 drm_object_attach_property(&connector->base,
3156 intel_sdvo_connector->top, 0);
3158 intel_sdvo_connector->bottom =
3159 drm_property_create_range(dev, 0,
3160 "bottom_margin", 0, data_value[0]);
3161 if (!intel_sdvo_connector->bottom)
3164 drm_object_attach_property(&connector->base,
3165 intel_sdvo_connector->bottom, 0);
3166 DRM_DEBUG_KMS("v_overscan: max %d, "
3167 "default %d, current %d\n",
3168 data_value[0], data_value[1], response);
3171 ENHANCEMENT(&sdvo_state->tv, hpos, HPOS);
3172 ENHANCEMENT(&sdvo_state->tv, vpos, VPOS);
3173 ENHANCEMENT(&conn_state->tv, saturation, SATURATION);
3174 ENHANCEMENT(&conn_state->tv, contrast, CONTRAST);
3175 ENHANCEMENT(&conn_state->tv, hue, HUE);
3176 ENHANCEMENT(&conn_state->tv, brightness, BRIGHTNESS);
3177 ENHANCEMENT(&sdvo_state->tv, sharpness, SHARPNESS);
3178 ENHANCEMENT(&sdvo_state->tv, flicker_filter, FLICKER_FILTER);
3179 ENHANCEMENT(&sdvo_state->tv, flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
3180 ENHANCEMENT(&sdvo_state->tv, flicker_filter_2d, FLICKER_FILTER_2D);
3181 _ENHANCEMENT(sdvo_state->tv.chroma_filter, tv_chroma_filter, TV_CHROMA_FILTER);
3182 _ENHANCEMENT(sdvo_state->tv.luma_filter, tv_luma_filter, TV_LUMA_FILTER);
3184 if (enhancements.dot_crawl) {
3185 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
3188 sdvo_state->tv.dot_crawl = response & 0x1;
3189 intel_sdvo_connector->dot_crawl =
3190 drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
3191 if (!intel_sdvo_connector->dot_crawl)
3194 drm_object_attach_property(&connector->base,
3195 intel_sdvo_connector->dot_crawl, 0);
3196 DRM_DEBUG_KMS("dot crawl: current %d\n", response);
3203 intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
3204 struct intel_sdvo_connector *intel_sdvo_connector,
3205 struct intel_sdvo_enhancements_reply enhancements)
3207 struct drm_device *dev = intel_sdvo->base.base.dev;
3208 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3209 u16 response, data_value[2];
3211 ENHANCEMENT(&connector->state->tv, brightness, BRIGHTNESS);
3218 static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
3219 struct intel_sdvo_connector *intel_sdvo_connector)
3222 struct intel_sdvo_enhancements_reply reply;
3226 BUILD_BUG_ON(sizeof(enhancements) != 2);
3228 if (!intel_sdvo_get_value(intel_sdvo,
3229 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
3230 &enhancements, sizeof(enhancements)) ||
3231 enhancements.response == 0) {
3232 DRM_DEBUG_KMS("No enhancement is supported\n");
3236 if (IS_TV(intel_sdvo_connector))
3237 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3238 else if (IS_LVDS(intel_sdvo_connector))
3239 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3244 static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
3245 struct i2c_msg *msgs,
3248 struct intel_sdvo *sdvo = adapter->algo_data;
3250 if (!__intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
3253 return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
3256 static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
3258 struct intel_sdvo *sdvo = adapter->algo_data;
3259 return sdvo->i2c->algo->functionality(sdvo->i2c);
3262 static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
3263 .master_xfer = intel_sdvo_ddc_proxy_xfer,
3264 .functionality = intel_sdvo_ddc_proxy_func
3267 static void proxy_lock_bus(struct i2c_adapter *adapter,
3270 struct intel_sdvo *sdvo = adapter->algo_data;
3271 sdvo->i2c->lock_ops->lock_bus(sdvo->i2c, flags);
3274 static int proxy_trylock_bus(struct i2c_adapter *adapter,
3277 struct intel_sdvo *sdvo = adapter->algo_data;
3278 return sdvo->i2c->lock_ops->trylock_bus(sdvo->i2c, flags);
3281 static void proxy_unlock_bus(struct i2c_adapter *adapter,
3284 struct intel_sdvo *sdvo = adapter->algo_data;
3285 sdvo->i2c->lock_ops->unlock_bus(sdvo->i2c, flags);
3288 static const struct i2c_lock_operations proxy_lock_ops = {
3289 .lock_bus = proxy_lock_bus,
3290 .trylock_bus = proxy_trylock_bus,
3291 .unlock_bus = proxy_unlock_bus,
3295 intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
3296 struct drm_i915_private *dev_priv)
3298 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
3300 sdvo->ddc.owner = THIS_MODULE;
3301 sdvo->ddc.class = I2C_CLASS_DDC;
3302 snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
3303 sdvo->ddc.dev.parent = &pdev->dev;
3304 sdvo->ddc.algo_data = sdvo;
3305 sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
3306 sdvo->ddc.lock_ops = &proxy_lock_ops;
3308 return i2c_add_adapter(&sdvo->ddc) == 0;
3311 static void assert_sdvo_port_valid(const struct drm_i915_private *dev_priv,
3314 if (HAS_PCH_SPLIT(dev_priv))
3315 drm_WARN_ON(&dev_priv->drm, port != PORT_B);
3317 drm_WARN_ON(&dev_priv->drm, port != PORT_B && port != PORT_C);
3320 bool intel_sdvo_init(struct drm_i915_private *dev_priv,
3321 i915_reg_t sdvo_reg, enum port port)
3323 struct intel_encoder *intel_encoder;
3324 struct intel_sdvo *intel_sdvo;
3327 assert_sdvo_port_valid(dev_priv, port);
3329 intel_sdvo = kzalloc(sizeof(*intel_sdvo), GFP_KERNEL);
3333 intel_sdvo->sdvo_reg = sdvo_reg;
3334 intel_sdvo->port = port;
3335 intel_sdvo->slave_addr =
3336 intel_sdvo_get_slave_addr(dev_priv, intel_sdvo) >> 1;
3337 intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo);
3338 if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev_priv))
3341 /* encoder type will be decided later */
3342 intel_encoder = &intel_sdvo->base;
3343 intel_encoder->type = INTEL_OUTPUT_SDVO;
3344 intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
3345 intel_encoder->port = port;
3346 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
3347 &intel_sdvo_enc_funcs, 0,
3348 "SDVO %c", port_name(port));
3350 /* Read the regs to test if we can talk to the device */
3351 for (i = 0; i < 0x40; i++) {
3354 if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
3355 drm_dbg_kms(&dev_priv->drm,
3356 "No SDVO device found on %s\n",
3357 SDVO_NAME(intel_sdvo));
3362 intel_encoder->compute_config = intel_sdvo_compute_config;
3363 if (HAS_PCH_SPLIT(dev_priv)) {
3364 intel_encoder->disable = pch_disable_sdvo;
3365 intel_encoder->post_disable = pch_post_disable_sdvo;
3367 intel_encoder->disable = intel_disable_sdvo;
3369 intel_encoder->pre_enable = intel_sdvo_pre_enable;
3370 intel_encoder->enable = intel_enable_sdvo;
3371 intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
3372 intel_encoder->get_config = intel_sdvo_get_config;
3374 /* In default case sdvo lvds is false */
3375 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
3378 intel_sdvo->colorimetry_cap =
3379 intel_sdvo_get_colorimetry_cap(intel_sdvo);
3381 if (!intel_sdvo_output_setup(intel_sdvo)) {
3382 drm_dbg_kms(&dev_priv->drm,
3383 "SDVO output failed to setup on %s\n",
3384 SDVO_NAME(intel_sdvo));
3385 /* Output_setup can leave behind connectors! */
3390 * Only enable the hotplug irq if we need it, to work around noisy
3393 if (intel_sdvo->hotplug_active) {
3394 if (intel_sdvo->port == PORT_B)
3395 intel_encoder->hpd_pin = HPD_SDVO_B;
3397 intel_encoder->hpd_pin = HPD_SDVO_C;
3401 * Cloning SDVO with anything is often impossible, since the SDVO
3402 * encoder can request a special input timing mode. And even if that's
3403 * not the case we have evidence that cloning a plain unscaled mode with
3404 * VGA doesn't really work. Furthermore the cloning flags are way too
3405 * simplistic anyway to express such constraints, so just give up on
3406 * cloning for SDVO encoders.
3408 intel_sdvo->base.cloneable = 0;
3410 /* Set the input timing to the screen. Assume always input 0. */
3411 if (!intel_sdvo_set_target_input(intel_sdvo))
3414 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
3415 &intel_sdvo->pixel_clock_min,
3416 &intel_sdvo->pixel_clock_max))
3419 drm_dbg_kms(&dev_priv->drm, "%s device VID/DID: %02X:%02X.%02X, "
3420 "clock range %dMHz - %dMHz, "
3421 "input 1: %c, input 2: %c, "
3422 "output 1: %c, output 2: %c\n",
3423 SDVO_NAME(intel_sdvo),
3424 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
3425 intel_sdvo->caps.device_rev_id,
3426 intel_sdvo->pixel_clock_min / 1000,
3427 intel_sdvo->pixel_clock_max / 1000,
3428 (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
3429 (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
3430 /* check currently supported outputs */
3431 intel_sdvo->caps.output_flags &
3432 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0 |
3433 SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_SVID0 |
3434 SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_YPRPB0) ? 'Y' : 'N',
3435 intel_sdvo->caps.output_flags &
3436 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1 |
3437 SDVO_OUTPUT_LVDS1) ? 'Y' : 'N');
3441 intel_sdvo_output_cleanup(intel_sdvo);
3444 drm_encoder_cleanup(&intel_encoder->base);
3445 i2c_del_adapter(&intel_sdvo->ddc);
3447 intel_sdvo_unselect_i2c_bus(intel_sdvo);