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 | SDVO_TV_MASK)
62 #define IS_TV(c) ((c)->output_flag & SDVO_TV_MASK)
63 #define IS_TMDS(c) ((c)->output_flag & SDVO_TMDS_MASK)
64 #define IS_LVDS(c) ((c)->output_flag & SDVO_LVDS_MASK)
65 #define IS_TV_OR_LVDS(c) ((c)->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
66 #define IS_DIGITAL(c) ((c)->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
68 #define HAS_DDC(c) ((c)->output_flag & (SDVO_RGB_MASK | SDVO_TMDS_MASK | \
71 static const char * const tv_format_names[] = {
72 "NTSC_M" , "NTSC_J" , "NTSC_443",
73 "PAL_B" , "PAL_D" , "PAL_G" ,
74 "PAL_H" , "PAL_I" , "PAL_M" ,
75 "PAL_N" , "PAL_NC" , "PAL_60" ,
76 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
77 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
81 #define TV_FORMAT_NUM ARRAY_SIZE(tv_format_names)
85 struct intel_sdvo_ddc {
86 struct i2c_adapter ddc;
87 struct intel_sdvo *sdvo;
92 struct intel_encoder base;
94 struct i2c_adapter *i2c;
97 struct intel_sdvo_ddc ddc[3];
99 /* Register for the SDVO device: SDVOB or SDVOC */
103 * Capabilities of the SDVO device returned by
104 * intel_sdvo_get_capabilities()
106 struct intel_sdvo_caps caps;
110 /* Pixel clock limitations reported by the SDVO device, in kHz */
111 int pixel_clock_min, pixel_clock_max;
114 * Hotplug activation bits for this device
119 * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
124 struct intel_sdvo_connector {
125 struct intel_connector base;
127 /* Mark the type of connector */
130 /* This contains all current supported TV format */
131 u8 tv_format_supported[TV_FORMAT_NUM];
132 int format_supported_num;
133 struct drm_property *tv_format;
135 /* add the property for the SDVO-TV */
136 struct drm_property *left;
137 struct drm_property *right;
138 struct drm_property *top;
139 struct drm_property *bottom;
140 struct drm_property *hpos;
141 struct drm_property *vpos;
142 struct drm_property *contrast;
143 struct drm_property *saturation;
144 struct drm_property *hue;
145 struct drm_property *sharpness;
146 struct drm_property *flicker_filter;
147 struct drm_property *flicker_filter_adaptive;
148 struct drm_property *flicker_filter_2d;
149 struct drm_property *tv_chroma_filter;
150 struct drm_property *tv_luma_filter;
151 struct drm_property *dot_crawl;
153 /* add the property for the SDVO-TV/LVDS */
154 struct drm_property *brightness;
156 /* this is to get the range of margin.*/
157 u32 max_hscan, max_vscan;
160 * This is set if we treat the device as HDMI, instead of DVI.
165 struct intel_sdvo_connector_state {
166 /* base.base: tv.saturation/contrast/hue/brightness */
167 struct intel_digital_connector_state base;
170 unsigned overscan_h, overscan_v, hpos, vpos, sharpness;
171 unsigned flicker_filter, flicker_filter_2d, flicker_filter_adaptive;
172 unsigned chroma_filter, luma_filter, dot_crawl;
176 static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
178 return container_of(encoder, struct intel_sdvo, base);
181 static struct intel_sdvo *intel_attached_sdvo(struct intel_connector *connector)
183 return to_sdvo(intel_attached_encoder(connector));
186 static struct intel_sdvo_connector *
187 to_intel_sdvo_connector(struct drm_connector *connector)
189 return container_of(connector, struct intel_sdvo_connector, base.base);
192 #define to_intel_sdvo_connector_state(conn_state) \
193 container_of((conn_state), struct intel_sdvo_connector_state, base.base)
196 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo);
198 intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
199 struct intel_sdvo_connector *intel_sdvo_connector,
202 intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
203 struct intel_sdvo_connector *intel_sdvo_connector);
206 * Writes the SDVOB or SDVOC with the given value, but always writes both
207 * SDVOB and SDVOC to work around apparent hardware issues (according to
208 * comments in the BIOS).
210 static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
212 struct drm_device *dev = intel_sdvo->base.base.dev;
213 struct drm_i915_private *dev_priv = to_i915(dev);
214 u32 bval = val, cval = val;
217 if (HAS_PCH_SPLIT(dev_priv)) {
218 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
219 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
221 * HW workaround, need to write this twice for issue
222 * that may result in first write getting masked.
224 if (HAS_PCH_IBX(dev_priv)) {
225 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
226 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
231 if (intel_sdvo->base.port == PORT_B)
232 cval = intel_de_read(dev_priv, GEN3_SDVOC);
234 bval = intel_de_read(dev_priv, GEN3_SDVOB);
237 * Write the registers twice for luck. Sometimes,
238 * writing them only once doesn't appear to 'stick'.
239 * The BIOS does this too. Yay, magic
241 for (i = 0; i < 2; i++) {
242 intel_de_write(dev_priv, GEN3_SDVOB, bval);
243 intel_de_posting_read(dev_priv, GEN3_SDVOB);
245 intel_de_write(dev_priv, GEN3_SDVOC, cval);
246 intel_de_posting_read(dev_priv, GEN3_SDVOC);
250 static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
252 struct i2c_msg msgs[] = {
254 .addr = intel_sdvo->slave_addr,
260 .addr = intel_sdvo->slave_addr,
268 if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
271 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
275 #define SDVO_CMD_NAME_ENTRY(cmd_) { .cmd = SDVO_CMD_ ## cmd_, .name = #cmd_ }
277 /** Mapping of command numbers to names, for debug output */
278 static const struct {
281 } __packed sdvo_cmd_names[] = {
282 SDVO_CMD_NAME_ENTRY(RESET),
283 SDVO_CMD_NAME_ENTRY(GET_DEVICE_CAPS),
284 SDVO_CMD_NAME_ENTRY(GET_FIRMWARE_REV),
285 SDVO_CMD_NAME_ENTRY(GET_TRAINED_INPUTS),
286 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_OUTPUTS),
287 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_OUTPUTS),
288 SDVO_CMD_NAME_ENTRY(GET_IN_OUT_MAP),
289 SDVO_CMD_NAME_ENTRY(SET_IN_OUT_MAP),
290 SDVO_CMD_NAME_ENTRY(GET_ATTACHED_DISPLAYS),
291 SDVO_CMD_NAME_ENTRY(GET_HOT_PLUG_SUPPORT),
292 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_HOT_PLUG),
293 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_HOT_PLUG),
294 SDVO_CMD_NAME_ENTRY(GET_INTERRUPT_EVENT_SOURCE),
295 SDVO_CMD_NAME_ENTRY(SET_TARGET_INPUT),
296 SDVO_CMD_NAME_ENTRY(SET_TARGET_OUTPUT),
297 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART1),
298 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART2),
299 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART1),
300 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART2),
301 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART1),
302 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART2),
303 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART1),
304 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART2),
305 SDVO_CMD_NAME_ENTRY(CREATE_PREFERRED_INPUT_TIMING),
306 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART1),
307 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART2),
308 SDVO_CMD_NAME_ENTRY(GET_INPUT_PIXEL_CLOCK_RANGE),
309 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_PIXEL_CLOCK_RANGE),
310 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_CLOCK_RATE_MULTS),
311 SDVO_CMD_NAME_ENTRY(GET_CLOCK_RATE_MULT),
312 SDVO_CMD_NAME_ENTRY(SET_CLOCK_RATE_MULT),
313 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_TV_FORMATS),
314 SDVO_CMD_NAME_ENTRY(GET_TV_FORMAT),
315 SDVO_CMD_NAME_ENTRY(SET_TV_FORMAT),
316 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_POWER_STATES),
317 SDVO_CMD_NAME_ENTRY(GET_POWER_STATE),
318 SDVO_CMD_NAME_ENTRY(SET_ENCODER_POWER_STATE),
319 SDVO_CMD_NAME_ENTRY(SET_DISPLAY_POWER_STATE),
320 SDVO_CMD_NAME_ENTRY(SET_CONTROL_BUS_SWITCH),
321 SDVO_CMD_NAME_ENTRY(GET_SDTV_RESOLUTION_SUPPORT),
322 SDVO_CMD_NAME_ENTRY(GET_SCALED_HDTV_RESOLUTION_SUPPORT),
323 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_ENHANCEMENTS),
325 /* Add the op code for SDVO enhancements */
326 SDVO_CMD_NAME_ENTRY(GET_MAX_HPOS),
327 SDVO_CMD_NAME_ENTRY(GET_HPOS),
328 SDVO_CMD_NAME_ENTRY(SET_HPOS),
329 SDVO_CMD_NAME_ENTRY(GET_MAX_VPOS),
330 SDVO_CMD_NAME_ENTRY(GET_VPOS),
331 SDVO_CMD_NAME_ENTRY(SET_VPOS),
332 SDVO_CMD_NAME_ENTRY(GET_MAX_SATURATION),
333 SDVO_CMD_NAME_ENTRY(GET_SATURATION),
334 SDVO_CMD_NAME_ENTRY(SET_SATURATION),
335 SDVO_CMD_NAME_ENTRY(GET_MAX_HUE),
336 SDVO_CMD_NAME_ENTRY(GET_HUE),
337 SDVO_CMD_NAME_ENTRY(SET_HUE),
338 SDVO_CMD_NAME_ENTRY(GET_MAX_CONTRAST),
339 SDVO_CMD_NAME_ENTRY(GET_CONTRAST),
340 SDVO_CMD_NAME_ENTRY(SET_CONTRAST),
341 SDVO_CMD_NAME_ENTRY(GET_MAX_BRIGHTNESS),
342 SDVO_CMD_NAME_ENTRY(GET_BRIGHTNESS),
343 SDVO_CMD_NAME_ENTRY(SET_BRIGHTNESS),
344 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_H),
345 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_H),
346 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_H),
347 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_V),
348 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_V),
349 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_V),
350 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER),
351 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER),
352 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER),
353 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_ADAPTIVE),
354 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_ADAPTIVE),
355 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_ADAPTIVE),
356 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_2D),
357 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_2D),
358 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_2D),
359 SDVO_CMD_NAME_ENTRY(GET_MAX_SHARPNESS),
360 SDVO_CMD_NAME_ENTRY(GET_SHARPNESS),
361 SDVO_CMD_NAME_ENTRY(SET_SHARPNESS),
362 SDVO_CMD_NAME_ENTRY(GET_DOT_CRAWL),
363 SDVO_CMD_NAME_ENTRY(SET_DOT_CRAWL),
364 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_CHROMA_FILTER),
365 SDVO_CMD_NAME_ENTRY(GET_TV_CHROMA_FILTER),
366 SDVO_CMD_NAME_ENTRY(SET_TV_CHROMA_FILTER),
367 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_LUMA_FILTER),
368 SDVO_CMD_NAME_ENTRY(GET_TV_LUMA_FILTER),
369 SDVO_CMD_NAME_ENTRY(SET_TV_LUMA_FILTER),
372 SDVO_CMD_NAME_ENTRY(GET_SUPP_ENCODE),
373 SDVO_CMD_NAME_ENTRY(GET_ENCODE),
374 SDVO_CMD_NAME_ENTRY(SET_ENCODE),
375 SDVO_CMD_NAME_ENTRY(SET_PIXEL_REPLI),
376 SDVO_CMD_NAME_ENTRY(GET_PIXEL_REPLI),
377 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY_CAP),
378 SDVO_CMD_NAME_ENTRY(SET_COLORIMETRY),
379 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY),
380 SDVO_CMD_NAME_ENTRY(GET_AUDIO_ENCRYPT_PREFER),
381 SDVO_CMD_NAME_ENTRY(SET_AUDIO_STAT),
382 SDVO_CMD_NAME_ENTRY(GET_AUDIO_STAT),
383 SDVO_CMD_NAME_ENTRY(GET_HBUF_INDEX),
384 SDVO_CMD_NAME_ENTRY(SET_HBUF_INDEX),
385 SDVO_CMD_NAME_ENTRY(GET_HBUF_INFO),
386 SDVO_CMD_NAME_ENTRY(GET_HBUF_AV_SPLIT),
387 SDVO_CMD_NAME_ENTRY(SET_HBUF_AV_SPLIT),
388 SDVO_CMD_NAME_ENTRY(GET_HBUF_TXRATE),
389 SDVO_CMD_NAME_ENTRY(SET_HBUF_TXRATE),
390 SDVO_CMD_NAME_ENTRY(SET_HBUF_DATA),
391 SDVO_CMD_NAME_ENTRY(GET_HBUF_DATA),
394 #undef SDVO_CMD_NAME_ENTRY
396 static const char *sdvo_cmd_name(u8 cmd)
400 for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
401 if (cmd == sdvo_cmd_names[i].cmd)
402 return sdvo_cmd_names[i].name;
408 #define SDVO_NAME(svdo) ((svdo)->base.port == PORT_B ? "SDVOB" : "SDVOC")
410 static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
411 const void *args, int args_len)
413 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
414 const char *cmd_name;
418 #define BUF_PRINT(args...) \
419 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
421 for (i = 0; i < args_len; i++) {
422 BUF_PRINT("%02X ", ((u8 *)args)[i]);
428 cmd_name = sdvo_cmd_name(cmd);
430 BUF_PRINT("(%s)", cmd_name);
432 BUF_PRINT("(%02X)", cmd);
434 drm_WARN_ON(&dev_priv->drm, pos >= sizeof(buffer) - 1);
437 DRM_DEBUG_KMS("%s: W: %02X %s\n", SDVO_NAME(intel_sdvo), cmd, buffer);
440 static const char * const cmd_status_names[] = {
441 [SDVO_CMD_STATUS_POWER_ON] = "Power on",
442 [SDVO_CMD_STATUS_SUCCESS] = "Success",
443 [SDVO_CMD_STATUS_NOTSUPP] = "Not supported",
444 [SDVO_CMD_STATUS_INVALID_ARG] = "Invalid arg",
445 [SDVO_CMD_STATUS_PENDING] = "Pending",
446 [SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED] = "Target not specified",
447 [SDVO_CMD_STATUS_SCALING_NOT_SUPP] = "Scaling not supported",
450 static const char *sdvo_cmd_status(u8 status)
452 if (status < ARRAY_SIZE(cmd_status_names))
453 return cmd_status_names[status];
458 static bool __intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
459 const void *args, int args_len,
463 struct i2c_msg *msgs;
466 /* Would be simpler to allocate both in one go ? */
467 buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
471 msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
477 intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
479 for (i = 0; i < args_len; i++) {
480 msgs[i].addr = intel_sdvo->slave_addr;
483 msgs[i].buf = buf + 2 *i;
484 buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
485 buf[2*i + 1] = ((u8*)args)[i];
487 msgs[i].addr = intel_sdvo->slave_addr;
490 msgs[i].buf = buf + 2*i;
491 buf[2*i + 0] = SDVO_I2C_OPCODE;
494 /* the following two are to read the response */
495 status = SDVO_I2C_CMD_STATUS;
496 msgs[i+1].addr = intel_sdvo->slave_addr;
499 msgs[i+1].buf = &status;
501 msgs[i+2].addr = intel_sdvo->slave_addr;
502 msgs[i+2].flags = I2C_M_RD;
504 msgs[i+2].buf = &status;
507 ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
509 ret = __i2c_transfer(intel_sdvo->i2c, msgs, i+3);
511 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
516 /* failure in I2C transfer */
517 DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
527 static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
528 const void *args, int args_len)
530 return __intel_sdvo_write_cmd(intel_sdvo, cmd, args, args_len, true);
533 static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
534 void *response, int response_len)
536 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
537 const char *cmd_status;
538 u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
546 * The documentation states that all commands will be
547 * processed within 15µs, and that we need only poll
548 * the status byte a maximum of 3 times in order for the
549 * command to be complete.
551 * Check 5 times in case the hardware failed to read the docs.
553 * Also beware that the first response by many devices is to
554 * reply PENDING and stall for time. TVs are notorious for
555 * requiring longer than specified to complete their replies.
556 * Originally (in the DDX long ago), the delay was only ever 15ms
557 * with an additional delay of 30ms applied for TVs added later after
558 * many experiments. To accommodate both sets of delays, we do a
559 * sequence of slow checks if the device is falling behind and fails
560 * to reply within 5*15µs.
562 if (!intel_sdvo_read_byte(intel_sdvo,
567 while ((status == SDVO_CMD_STATUS_PENDING ||
568 status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
574 if (!intel_sdvo_read_byte(intel_sdvo,
580 #define BUF_PRINT(args...) \
581 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
583 cmd_status = sdvo_cmd_status(status);
585 BUF_PRINT("(%s)", cmd_status);
587 BUF_PRINT("(??? %d)", status);
589 if (status != SDVO_CMD_STATUS_SUCCESS)
592 /* Read the command response */
593 for (i = 0; i < response_len; i++) {
594 if (!intel_sdvo_read_byte(intel_sdvo,
595 SDVO_I2C_RETURN_0 + i,
596 &((u8 *)response)[i]))
598 BUF_PRINT(" %02X", ((u8 *)response)[i]);
601 drm_WARN_ON(&dev_priv->drm, pos >= sizeof(buffer) - 1);
604 DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo), buffer);
608 DRM_DEBUG_KMS("%s: R: ... failed %s\n",
609 SDVO_NAME(intel_sdvo), buffer);
613 static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode *adjusted_mode)
615 if (adjusted_mode->crtc_clock >= 100000)
617 else if (adjusted_mode->crtc_clock >= 50000)
623 static bool __intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
626 /* This must be the immediately preceding write before the i2c xfer */
627 return __intel_sdvo_write_cmd(intel_sdvo,
628 SDVO_CMD_SET_CONTROL_BUS_SWITCH,
632 static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
634 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
637 return intel_sdvo_read_response(intel_sdvo, NULL, 0);
641 intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
643 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
646 return intel_sdvo_read_response(intel_sdvo, value, len);
649 static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
651 struct intel_sdvo_set_target_input_args targets = {0};
652 return intel_sdvo_set_value(intel_sdvo,
653 SDVO_CMD_SET_TARGET_INPUT,
654 &targets, sizeof(targets));
658 * Return whether each input is trained.
660 * This function is making an assumption about the layout of the response,
661 * which should be checked against the docs.
663 static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
665 struct intel_sdvo_get_trained_inputs_response response;
667 BUILD_BUG_ON(sizeof(response) != 1);
668 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
669 &response, sizeof(response)))
672 *input_1 = response.input0_trained;
673 *input_2 = response.input1_trained;
677 static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
680 return intel_sdvo_set_value(intel_sdvo,
681 SDVO_CMD_SET_ACTIVE_OUTPUTS,
682 &outputs, sizeof(outputs));
685 static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
688 return intel_sdvo_get_value(intel_sdvo,
689 SDVO_CMD_GET_ACTIVE_OUTPUTS,
690 outputs, sizeof(*outputs));
693 static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
696 u8 state = SDVO_ENCODER_STATE_ON;
699 case DRM_MODE_DPMS_ON:
700 state = SDVO_ENCODER_STATE_ON;
702 case DRM_MODE_DPMS_STANDBY:
703 state = SDVO_ENCODER_STATE_STANDBY;
705 case DRM_MODE_DPMS_SUSPEND:
706 state = SDVO_ENCODER_STATE_SUSPEND;
708 case DRM_MODE_DPMS_OFF:
709 state = SDVO_ENCODER_STATE_OFF;
713 return intel_sdvo_set_value(intel_sdvo,
714 SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
717 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
721 struct intel_sdvo_pixel_clock_range clocks;
723 BUILD_BUG_ON(sizeof(clocks) != 4);
724 if (!intel_sdvo_get_value(intel_sdvo,
725 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
726 &clocks, sizeof(clocks)))
729 /* Convert the values from units of 10 kHz to kHz. */
730 *clock_min = clocks.min * 10;
731 *clock_max = clocks.max * 10;
735 static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
738 return intel_sdvo_set_value(intel_sdvo,
739 SDVO_CMD_SET_TARGET_OUTPUT,
740 &outputs, sizeof(outputs));
743 static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
744 struct intel_sdvo_dtd *dtd)
746 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
747 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
750 static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
751 struct intel_sdvo_dtd *dtd)
753 return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
754 intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
757 static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
758 struct intel_sdvo_dtd *dtd)
760 return intel_sdvo_set_timing(intel_sdvo,
761 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
764 static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
765 struct intel_sdvo_dtd *dtd)
767 return intel_sdvo_set_timing(intel_sdvo,
768 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
771 static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
772 struct intel_sdvo_dtd *dtd)
774 return intel_sdvo_get_timing(intel_sdvo,
775 SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
779 intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
780 struct intel_sdvo_connector *intel_sdvo_connector,
781 const struct drm_display_mode *mode)
783 struct intel_sdvo_preferred_input_timing_args args;
785 memset(&args, 0, sizeof(args));
786 args.clock = mode->clock / 10;
787 args.width = mode->hdisplay;
788 args.height = mode->vdisplay;
791 if (IS_LVDS(intel_sdvo_connector)) {
792 const struct drm_display_mode *fixed_mode =
793 intel_panel_fixed_mode(&intel_sdvo_connector->base, mode);
795 if (fixed_mode->hdisplay != args.width ||
796 fixed_mode->vdisplay != args.height)
800 return intel_sdvo_set_value(intel_sdvo,
801 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
802 &args, sizeof(args));
805 static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
806 struct intel_sdvo_dtd *dtd)
808 BUILD_BUG_ON(sizeof(dtd->part1) != 8);
809 BUILD_BUG_ON(sizeof(dtd->part2) != 8);
810 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
811 &dtd->part1, sizeof(dtd->part1)) &&
812 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
813 &dtd->part2, sizeof(dtd->part2));
816 static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
818 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
821 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
822 const struct drm_display_mode *mode)
825 u16 h_blank_len, h_sync_len, v_blank_len, v_sync_len;
826 u16 h_sync_offset, v_sync_offset;
829 memset(dtd, 0, sizeof(*dtd));
831 width = mode->hdisplay;
832 height = mode->vdisplay;
834 /* do some mode translations */
835 h_blank_len = mode->htotal - mode->hdisplay;
836 h_sync_len = mode->hsync_end - mode->hsync_start;
838 v_blank_len = mode->vtotal - mode->vdisplay;
839 v_sync_len = mode->vsync_end - mode->vsync_start;
841 h_sync_offset = mode->hsync_start - mode->hdisplay;
842 v_sync_offset = mode->vsync_start - mode->vdisplay;
844 mode_clock = mode->clock;
846 dtd->part1.clock = mode_clock;
848 dtd->part1.h_active = width & 0xff;
849 dtd->part1.h_blank = h_blank_len & 0xff;
850 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
851 ((h_blank_len >> 8) & 0xf);
852 dtd->part1.v_active = height & 0xff;
853 dtd->part1.v_blank = v_blank_len & 0xff;
854 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
855 ((v_blank_len >> 8) & 0xf);
857 dtd->part2.h_sync_off = h_sync_offset & 0xff;
858 dtd->part2.h_sync_width = h_sync_len & 0xff;
859 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
861 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
862 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
863 ((v_sync_len & 0x30) >> 4);
865 dtd->part2.dtd_flags = 0x18;
866 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
867 dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
868 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
869 dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
870 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
871 dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
873 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
876 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode *pmode,
877 const struct intel_sdvo_dtd *dtd)
879 struct drm_display_mode mode = {};
881 mode.hdisplay = dtd->part1.h_active;
882 mode.hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
883 mode.hsync_start = mode.hdisplay + dtd->part2.h_sync_off;
884 mode.hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
885 mode.hsync_end = mode.hsync_start + dtd->part2.h_sync_width;
886 mode.hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
887 mode.htotal = mode.hdisplay + dtd->part1.h_blank;
888 mode.htotal += (dtd->part1.h_high & 0xf) << 8;
890 mode.vdisplay = dtd->part1.v_active;
891 mode.vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
892 mode.vsync_start = mode.vdisplay;
893 mode.vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
894 mode.vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
895 mode.vsync_start += dtd->part2.v_sync_off_high & 0xc0;
896 mode.vsync_end = mode.vsync_start +
897 (dtd->part2.v_sync_off_width & 0xf);
898 mode.vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
899 mode.vtotal = mode.vdisplay + dtd->part1.v_blank;
900 mode.vtotal += (dtd->part1.v_high & 0xf) << 8;
902 mode.clock = dtd->part1.clock * 10;
904 if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
905 mode.flags |= DRM_MODE_FLAG_INTERLACE;
906 if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
907 mode.flags |= DRM_MODE_FLAG_PHSYNC;
909 mode.flags |= DRM_MODE_FLAG_NHSYNC;
910 if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
911 mode.flags |= DRM_MODE_FLAG_PVSYNC;
913 mode.flags |= DRM_MODE_FLAG_NVSYNC;
915 drm_mode_set_crtcinfo(&mode, 0);
917 drm_mode_copy(pmode, &mode);
920 static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
922 struct intel_sdvo_encode encode;
924 BUILD_BUG_ON(sizeof(encode) != 2);
925 return intel_sdvo_get_value(intel_sdvo,
926 SDVO_CMD_GET_SUPP_ENCODE,
927 &encode, sizeof(encode));
930 static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
933 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
936 static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
939 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
942 static bool intel_sdvo_set_pixel_replication(struct intel_sdvo *intel_sdvo,
945 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_PIXEL_REPLI,
949 static bool intel_sdvo_set_audio_state(struct intel_sdvo *intel_sdvo,
952 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_AUDIO_STAT,
956 static bool intel_sdvo_get_hbuf_size(struct intel_sdvo *intel_sdvo,
959 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
963 /* Buffer size is 0 based, hooray! However zero means zero. */
971 static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
980 intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
982 for (i = 0; i <= av_split; i++) {
983 set_buf_index[0] = i; set_buf_index[1] = 0;
984 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
986 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
987 intel_sdvo_read_response(encoder, &buf_size, 1);
990 for (j = 0; j <= buf_size; j += 8) {
991 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
993 intel_sdvo_read_response(encoder, pos, 8);
1000 static bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
1001 unsigned int if_index, u8 tx_rate,
1002 const u8 *data, unsigned int length)
1004 u8 set_buf_index[2] = { if_index, 0 };
1005 u8 hbuf_size, tmp[8];
1008 if (!intel_sdvo_set_value(intel_sdvo,
1009 SDVO_CMD_SET_HBUF_INDEX,
1013 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1016 DRM_DEBUG_KMS("writing sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1017 if_index, length, hbuf_size);
1019 if (hbuf_size < length)
1022 for (i = 0; i < hbuf_size; i += 8) {
1025 memcpy(tmp, data + i, min_t(unsigned, 8, length - i));
1027 if (!intel_sdvo_set_value(intel_sdvo,
1028 SDVO_CMD_SET_HBUF_DATA,
1033 return intel_sdvo_set_value(intel_sdvo,
1034 SDVO_CMD_SET_HBUF_TXRATE,
1038 static ssize_t intel_sdvo_read_infoframe(struct intel_sdvo *intel_sdvo,
1039 unsigned int if_index,
1040 u8 *data, unsigned int length)
1042 u8 set_buf_index[2] = { if_index, 0 };
1043 u8 hbuf_size, tx_rate, av_split;
1046 if (!intel_sdvo_get_value(intel_sdvo,
1047 SDVO_CMD_GET_HBUF_AV_SPLIT,
1051 if (av_split < if_index)
1054 if (!intel_sdvo_set_value(intel_sdvo,
1055 SDVO_CMD_SET_HBUF_INDEX,
1059 if (!intel_sdvo_get_value(intel_sdvo,
1060 SDVO_CMD_GET_HBUF_TXRATE,
1064 /* TX_DISABLED doesn't mean disabled for ELD */
1065 if (if_index != SDVO_HBUF_INDEX_ELD && tx_rate == SDVO_HBUF_TX_DISABLED)
1068 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1071 DRM_DEBUG_KMS("reading sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1072 if_index, length, hbuf_size);
1074 hbuf_size = min_t(unsigned int, length, hbuf_size);
1076 for (i = 0; i < hbuf_size; i += 8) {
1077 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HBUF_DATA, NULL, 0))
1079 if (!intel_sdvo_read_response(intel_sdvo, &data[i],
1080 min_t(unsigned int, 8, hbuf_size - i)))
1087 static bool intel_sdvo_compute_avi_infoframe(struct intel_sdvo *intel_sdvo,
1088 struct intel_crtc_state *crtc_state,
1089 struct drm_connector_state *conn_state)
1091 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1092 struct hdmi_avi_infoframe *frame = &crtc_state->infoframes.avi.avi;
1093 const struct drm_display_mode *adjusted_mode =
1094 &crtc_state->hw.adjusted_mode;
1097 if (!crtc_state->has_hdmi_sink)
1100 crtc_state->infoframes.enable |=
1101 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1103 ret = drm_hdmi_avi_infoframe_from_display_mode(frame,
1104 conn_state->connector,
1109 drm_hdmi_avi_infoframe_quant_range(frame,
1110 conn_state->connector,
1112 crtc_state->limited_color_range ?
1113 HDMI_QUANTIZATION_RANGE_LIMITED :
1114 HDMI_QUANTIZATION_RANGE_FULL);
1116 ret = hdmi_avi_infoframe_check(frame);
1117 if (drm_WARN_ON(&dev_priv->drm, ret))
1123 static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1124 const struct intel_crtc_state *crtc_state)
1126 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1127 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1128 const union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1131 if ((crtc_state->infoframes.enable &
1132 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI)) == 0)
1135 if (drm_WARN_ON(&dev_priv->drm,
1136 frame->any.type != HDMI_INFOFRAME_TYPE_AVI))
1139 len = hdmi_infoframe_pack_only(frame, sdvo_data, sizeof(sdvo_data));
1140 if (drm_WARN_ON(&dev_priv->drm, len < 0))
1143 return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1148 static void intel_sdvo_get_avi_infoframe(struct intel_sdvo *intel_sdvo,
1149 struct intel_crtc_state *crtc_state)
1151 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1152 union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1156 if (!crtc_state->has_hdmi_sink)
1159 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1160 sdvo_data, sizeof(sdvo_data));
1162 DRM_DEBUG_KMS("failed to read AVI infoframe\n");
1164 } else if (len == 0) {
1168 crtc_state->infoframes.enable |=
1169 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1171 ret = hdmi_infoframe_unpack(frame, sdvo_data, len);
1173 DRM_DEBUG_KMS("Failed to unpack AVI infoframe\n");
1177 if (frame->any.type != HDMI_INFOFRAME_TYPE_AVI)
1178 DRM_DEBUG_KMS("Found the wrong infoframe type 0x%x (expected 0x%02x)\n",
1179 frame->any.type, HDMI_INFOFRAME_TYPE_AVI);
1182 static void intel_sdvo_get_eld(struct intel_sdvo *intel_sdvo,
1183 struct intel_crtc_state *crtc_state)
1185 struct drm_i915_private *i915 = to_i915(intel_sdvo->base.base.dev);
1189 if (!crtc_state->has_audio)
1192 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_AUDIO_STAT, &val, 1))
1195 if ((val & SDVO_AUDIO_ELD_VALID) == 0)
1198 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_ELD,
1199 crtc_state->eld, sizeof(crtc_state->eld));
1201 drm_dbg_kms(&i915->drm, "failed to read ELD\n");
1204 static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo,
1205 const struct drm_connector_state *conn_state)
1207 struct intel_sdvo_tv_format format;
1210 format_map = 1 << conn_state->tv.mode;
1211 memset(&format, 0, sizeof(format));
1212 memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1214 BUILD_BUG_ON(sizeof(format) != 6);
1215 return intel_sdvo_set_value(intel_sdvo,
1216 SDVO_CMD_SET_TV_FORMAT,
1217 &format, sizeof(format));
1221 intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1222 struct intel_sdvo_connector *intel_sdvo_connector,
1223 const struct drm_display_mode *mode)
1225 struct intel_sdvo_dtd output_dtd;
1227 if (!intel_sdvo_set_target_output(intel_sdvo,
1228 intel_sdvo_connector->output_flag))
1231 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1232 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1239 * Asks the sdvo controller for the preferred input mode given the output mode.
1240 * Unfortunately we have to set up the full output mode to do that.
1243 intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
1244 struct intel_sdvo_connector *intel_sdvo_connector,
1245 const struct drm_display_mode *mode,
1246 struct drm_display_mode *adjusted_mode)
1248 struct intel_sdvo_dtd input_dtd;
1250 /* Reset the input timing to the screen. Assume always input 0. */
1251 if (!intel_sdvo_set_target_input(intel_sdvo))
1254 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1255 intel_sdvo_connector,
1259 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1263 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1264 intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1269 static int i9xx_adjust_sdvo_tv_clock(struct intel_crtc_state *pipe_config)
1271 struct drm_i915_private *dev_priv = to_i915(pipe_config->uapi.crtc->dev);
1272 unsigned int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
1273 struct dpll *clock = &pipe_config->dpll;
1276 * SDVO TV has fixed PLL values depend on its clock range,
1277 * this mirrors vbios setting.
1279 if (dotclock >= 100000 && dotclock < 140500) {
1285 } else if (dotclock >= 140500 && dotclock <= 200000) {
1292 drm_dbg_kms(&dev_priv->drm,
1293 "SDVO TV clock out of range: %i\n", dotclock);
1297 pipe_config->clock_set = true;
1302 static bool intel_has_hdmi_sink(struct intel_sdvo_connector *intel_sdvo_connector,
1303 const struct drm_connector_state *conn_state)
1305 struct drm_connector *connector = conn_state->connector;
1307 return intel_sdvo_connector->is_hdmi &&
1308 connector->display_info.is_hdmi &&
1309 READ_ONCE(to_intel_digital_connector_state(conn_state)->force_audio) != HDMI_AUDIO_OFF_DVI;
1312 static bool intel_sdvo_limited_color_range(struct intel_encoder *encoder,
1313 const struct intel_crtc_state *crtc_state,
1314 const struct drm_connector_state *conn_state)
1316 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1318 if ((intel_sdvo->colorimetry_cap & SDVO_COLORIMETRY_RGB220) == 0)
1321 return intel_hdmi_limited_color_range(crtc_state, conn_state);
1324 static bool intel_sdvo_has_audio(struct intel_encoder *encoder,
1325 const struct intel_crtc_state *crtc_state,
1326 const struct drm_connector_state *conn_state)
1328 struct drm_connector *connector = conn_state->connector;
1329 struct intel_sdvo_connector *intel_sdvo_connector =
1330 to_intel_sdvo_connector(connector);
1331 const struct intel_digital_connector_state *intel_conn_state =
1332 to_intel_digital_connector_state(conn_state);
1334 if (!crtc_state->has_hdmi_sink)
1337 if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
1338 return intel_sdvo_connector->is_hdmi &&
1339 connector->display_info.has_audio;
1341 return intel_conn_state->force_audio == HDMI_AUDIO_ON;
1344 static int intel_sdvo_compute_config(struct intel_encoder *encoder,
1345 struct intel_crtc_state *pipe_config,
1346 struct drm_connector_state *conn_state)
1348 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1349 struct intel_sdvo_connector *intel_sdvo_connector =
1350 to_intel_sdvo_connector(conn_state->connector);
1351 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1352 struct drm_display_mode *mode = &pipe_config->hw.mode;
1354 DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1355 pipe_config->pipe_bpp = 8*3;
1356 pipe_config->sink_format = INTEL_OUTPUT_FORMAT_RGB;
1357 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
1359 if (HAS_PCH_SPLIT(to_i915(encoder->base.dev)))
1360 pipe_config->has_pch_encoder = true;
1363 * We need to construct preferred input timings based on our
1364 * output timings. To do that, we have to set the output
1365 * timings, even though this isn't really the right place in
1366 * the sequence to do it. Oh well.
1368 if (IS_TV(intel_sdvo_connector)) {
1369 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1370 intel_sdvo_connector,
1374 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1375 intel_sdvo_connector,
1378 pipe_config->sdvo_tv_clock = true;
1379 } else if (IS_LVDS(intel_sdvo_connector)) {
1380 const struct drm_display_mode *fixed_mode =
1381 intel_panel_fixed_mode(&intel_sdvo_connector->base, mode);
1384 ret = intel_panel_compute_config(&intel_sdvo_connector->base,
1389 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1390 intel_sdvo_connector,
1394 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1395 intel_sdvo_connector,
1400 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
1404 * Make the CRTC code factor in the SDVO pixel multiplier. The
1405 * SDVO device will factor out the multiplier during mode_set.
1407 pipe_config->pixel_multiplier =
1408 intel_sdvo_get_pixel_multiplier(adjusted_mode);
1410 pipe_config->has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo_connector, conn_state);
1412 pipe_config->has_audio =
1413 intel_sdvo_has_audio(encoder, pipe_config, conn_state) &&
1414 intel_audio_compute_config(encoder, pipe_config, conn_state);
1416 pipe_config->limited_color_range =
1417 intel_sdvo_limited_color_range(encoder, pipe_config,
1420 /* Clock computation needs to happen after pixel multiplier. */
1421 if (IS_TV(intel_sdvo_connector)) {
1424 ret = i9xx_adjust_sdvo_tv_clock(pipe_config);
1429 if (conn_state->picture_aspect_ratio)
1430 adjusted_mode->picture_aspect_ratio =
1431 conn_state->picture_aspect_ratio;
1433 if (!intel_sdvo_compute_avi_infoframe(intel_sdvo,
1434 pipe_config, conn_state)) {
1435 DRM_DEBUG_KMS("bad AVI infoframe\n");
1442 #define UPDATE_PROPERTY(input, NAME) \
1445 intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_##NAME, &val, sizeof(val)); \
1448 static void intel_sdvo_update_props(struct intel_sdvo *intel_sdvo,
1449 const struct intel_sdvo_connector_state *sdvo_state)
1451 const struct drm_connector_state *conn_state = &sdvo_state->base.base;
1452 struct intel_sdvo_connector *intel_sdvo_conn =
1453 to_intel_sdvo_connector(conn_state->connector);
1456 if (intel_sdvo_conn->left)
1457 UPDATE_PROPERTY(sdvo_state->tv.overscan_h, OVERSCAN_H);
1459 if (intel_sdvo_conn->top)
1460 UPDATE_PROPERTY(sdvo_state->tv.overscan_v, OVERSCAN_V);
1462 if (intel_sdvo_conn->hpos)
1463 UPDATE_PROPERTY(sdvo_state->tv.hpos, HPOS);
1465 if (intel_sdvo_conn->vpos)
1466 UPDATE_PROPERTY(sdvo_state->tv.vpos, VPOS);
1468 if (intel_sdvo_conn->saturation)
1469 UPDATE_PROPERTY(conn_state->tv.saturation, SATURATION);
1471 if (intel_sdvo_conn->contrast)
1472 UPDATE_PROPERTY(conn_state->tv.contrast, CONTRAST);
1474 if (intel_sdvo_conn->hue)
1475 UPDATE_PROPERTY(conn_state->tv.hue, HUE);
1477 if (intel_sdvo_conn->brightness)
1478 UPDATE_PROPERTY(conn_state->tv.brightness, BRIGHTNESS);
1480 if (intel_sdvo_conn->sharpness)
1481 UPDATE_PROPERTY(sdvo_state->tv.sharpness, SHARPNESS);
1483 if (intel_sdvo_conn->flicker_filter)
1484 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter, FLICKER_FILTER);
1486 if (intel_sdvo_conn->flicker_filter_2d)
1487 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_2d, FLICKER_FILTER_2D);
1489 if (intel_sdvo_conn->flicker_filter_adaptive)
1490 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
1492 if (intel_sdvo_conn->tv_chroma_filter)
1493 UPDATE_PROPERTY(sdvo_state->tv.chroma_filter, TV_CHROMA_FILTER);
1495 if (intel_sdvo_conn->tv_luma_filter)
1496 UPDATE_PROPERTY(sdvo_state->tv.luma_filter, TV_LUMA_FILTER);
1498 if (intel_sdvo_conn->dot_crawl)
1499 UPDATE_PROPERTY(sdvo_state->tv.dot_crawl, DOT_CRAWL);
1501 #undef UPDATE_PROPERTY
1504 static void intel_sdvo_pre_enable(struct intel_atomic_state *state,
1505 struct intel_encoder *intel_encoder,
1506 const struct intel_crtc_state *crtc_state,
1507 const struct drm_connector_state *conn_state)
1509 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
1510 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1511 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
1512 const struct intel_sdvo_connector_state *sdvo_state =
1513 to_intel_sdvo_connector_state(conn_state);
1514 struct intel_sdvo_connector *intel_sdvo_connector =
1515 to_intel_sdvo_connector(conn_state->connector);
1516 const struct drm_display_mode *mode = &crtc_state->hw.mode;
1517 struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
1519 struct intel_sdvo_in_out_map in_out;
1520 struct intel_sdvo_dtd input_dtd, output_dtd;
1523 intel_sdvo_update_props(intel_sdvo, sdvo_state);
1526 * First, set the input mapping for the first input to our controlled
1527 * output. This is only correct if we're a single-input device, in
1528 * which case the first input is the output from the appropriate SDVO
1529 * channel on the motherboard. In a two-input device, the first input
1530 * will be SDVOB and the second SDVOC.
1532 in_out.in0 = intel_sdvo_connector->output_flag;
1535 intel_sdvo_set_value(intel_sdvo,
1536 SDVO_CMD_SET_IN_OUT_MAP,
1537 &in_out, sizeof(in_out));
1539 /* Set the output timings to the screen */
1540 if (!intel_sdvo_set_target_output(intel_sdvo,
1541 intel_sdvo_connector->output_flag))
1544 /* lvds has a special fixed output timing. */
1545 if (IS_LVDS(intel_sdvo_connector)) {
1546 const struct drm_display_mode *fixed_mode =
1547 intel_panel_fixed_mode(&intel_sdvo_connector->base, mode);
1549 intel_sdvo_get_dtd_from_mode(&output_dtd, fixed_mode);
1551 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1553 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1554 drm_info(&dev_priv->drm,
1555 "Setting output timings on %s failed\n",
1556 SDVO_NAME(intel_sdvo));
1558 /* Set the input timing to the screen. Assume always input 0. */
1559 if (!intel_sdvo_set_target_input(intel_sdvo))
1562 if (crtc_state->has_hdmi_sink) {
1563 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
1564 intel_sdvo_set_colorimetry(intel_sdvo,
1565 crtc_state->limited_color_range ?
1566 SDVO_COLORIMETRY_RGB220 :
1567 SDVO_COLORIMETRY_RGB256);
1568 intel_sdvo_set_avi_infoframe(intel_sdvo, crtc_state);
1569 intel_sdvo_set_pixel_replication(intel_sdvo,
1570 !!(adjusted_mode->flags &
1571 DRM_MODE_FLAG_DBLCLK));
1573 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
1575 if (IS_TV(intel_sdvo_connector) &&
1576 !intel_sdvo_set_tv_format(intel_sdvo, conn_state))
1579 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1581 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector))
1582 input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1583 if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1584 drm_info(&dev_priv->drm,
1585 "Setting input timings on %s failed\n",
1586 SDVO_NAME(intel_sdvo));
1588 switch (crtc_state->pixel_multiplier) {
1590 drm_WARN(&dev_priv->drm, 1,
1591 "unknown pixel multiplier specified\n");
1593 case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1594 case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1595 case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1597 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1600 /* Set the SDVO control regs. */
1601 if (DISPLAY_VER(dev_priv) >= 4) {
1602 /* The real mode polarity is set by the SDVO commands, using
1603 * struct intel_sdvo_dtd. */
1604 sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
1605 if (DISPLAY_VER(dev_priv) < 5)
1606 sdvox |= SDVO_BORDER_ENABLE;
1608 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1609 if (intel_sdvo->base.port == PORT_B)
1610 sdvox &= SDVOB_PRESERVE_MASK;
1612 sdvox &= SDVOC_PRESERVE_MASK;
1613 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1616 if (HAS_PCH_CPT(dev_priv))
1617 sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
1619 sdvox |= SDVO_PIPE_SEL(crtc->pipe);
1621 if (DISPLAY_VER(dev_priv) >= 4) {
1622 /* done in crtc_mode_set as the dpll_md reg must be written early */
1623 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
1624 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
1625 /* done in crtc_mode_set as it lives inside the dpll register */
1627 sdvox |= (crtc_state->pixel_multiplier - 1)
1628 << SDVO_PORT_MULTIPLY_SHIFT;
1631 if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
1632 DISPLAY_VER(dev_priv) < 5)
1633 sdvox |= SDVO_STALL_SELECT;
1634 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1637 static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1639 struct intel_sdvo_connector *intel_sdvo_connector =
1640 to_intel_sdvo_connector(&connector->base);
1641 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1642 u16 active_outputs = 0;
1644 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1646 return active_outputs & intel_sdvo_connector->output_flag;
1649 bool intel_sdvo_port_enabled(struct drm_i915_private *dev_priv,
1650 i915_reg_t sdvo_reg, enum pipe *pipe)
1654 val = intel_de_read(dev_priv, sdvo_reg);
1656 /* asserts want to know the pipe even if the port is disabled */
1657 if (HAS_PCH_CPT(dev_priv))
1658 *pipe = (val & SDVO_PIPE_SEL_MASK_CPT) >> SDVO_PIPE_SEL_SHIFT_CPT;
1659 else if (IS_CHERRYVIEW(dev_priv))
1660 *pipe = (val & SDVO_PIPE_SEL_MASK_CHV) >> SDVO_PIPE_SEL_SHIFT_CHV;
1662 *pipe = (val & SDVO_PIPE_SEL_MASK) >> SDVO_PIPE_SEL_SHIFT;
1664 return val & SDVO_ENABLE;
1667 static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1670 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1671 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1672 u16 active_outputs = 0;
1675 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1677 ret = intel_sdvo_port_enabled(dev_priv, intel_sdvo->sdvo_reg, pipe);
1679 return ret || active_outputs;
1682 static void intel_sdvo_get_config(struct intel_encoder *encoder,
1683 struct intel_crtc_state *pipe_config)
1685 struct drm_device *dev = encoder->base.dev;
1686 struct drm_i915_private *dev_priv = to_i915(dev);
1687 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1688 struct intel_sdvo_dtd dtd;
1689 int encoder_pixel_multiplier = 0;
1691 u32 flags = 0, sdvox;
1695 pipe_config->output_types |= BIT(INTEL_OUTPUT_SDVO);
1697 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1699 ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
1702 * Some sdvo encoders are not spec compliant and don't
1703 * implement the mandatory get_timings function.
1705 drm_dbg(&dev_priv->drm, "failed to retrieve SDVO DTD\n");
1706 pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
1708 if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1709 flags |= DRM_MODE_FLAG_PHSYNC;
1711 flags |= DRM_MODE_FLAG_NHSYNC;
1713 if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1714 flags |= DRM_MODE_FLAG_PVSYNC;
1716 flags |= DRM_MODE_FLAG_NVSYNC;
1719 pipe_config->hw.adjusted_mode.flags |= flags;
1722 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1723 * the sdvo port register, on all other platforms it is part of the dpll
1724 * state. Since the general pipe state readout happens before the
1725 * encoder->get_config we so already have a valid pixel multplier on all
1728 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
1729 pipe_config->pixel_multiplier =
1730 ((sdvox & SDVO_PORT_MULTIPLY_MASK)
1731 >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
1734 dotclock = pipe_config->port_clock;
1736 if (pipe_config->pixel_multiplier)
1737 dotclock /= pipe_config->pixel_multiplier;
1739 pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
1741 /* Cross check the port pixel multiplier with the sdvo encoder state. */
1742 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
1745 case SDVO_CLOCK_RATE_MULT_1X:
1746 encoder_pixel_multiplier = 1;
1748 case SDVO_CLOCK_RATE_MULT_2X:
1749 encoder_pixel_multiplier = 2;
1751 case SDVO_CLOCK_RATE_MULT_4X:
1752 encoder_pixel_multiplier = 4;
1758 encoder_pixel_multiplier != pipe_config->pixel_multiplier,
1759 "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1760 pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1762 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_COLORIMETRY,
1764 if (val == SDVO_COLORIMETRY_RGB220)
1765 pipe_config->limited_color_range = true;
1768 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_AUDIO_STAT,
1770 if (val & SDVO_AUDIO_PRESENCE_DETECT)
1771 pipe_config->has_audio = true;
1774 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE,
1776 if (val == SDVO_ENCODE_HDMI)
1777 pipe_config->has_hdmi_sink = true;
1780 intel_sdvo_get_avi_infoframe(intel_sdvo, pipe_config);
1782 intel_sdvo_get_eld(intel_sdvo, pipe_config);
1785 static void intel_sdvo_disable_audio(struct intel_sdvo *intel_sdvo)
1787 intel_sdvo_set_audio_state(intel_sdvo, 0);
1790 static void intel_sdvo_enable_audio(struct intel_sdvo *intel_sdvo,
1791 const struct intel_crtc_state *crtc_state,
1792 const struct drm_connector_state *conn_state)
1794 const u8 *eld = crtc_state->eld;
1796 intel_sdvo_set_audio_state(intel_sdvo, 0);
1798 intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_ELD,
1799 SDVO_HBUF_TX_DISABLED,
1800 eld, drm_eld_size(eld));
1802 intel_sdvo_set_audio_state(intel_sdvo, SDVO_AUDIO_ELD_VALID |
1803 SDVO_AUDIO_PRESENCE_DETECT);
1806 static void intel_disable_sdvo(struct intel_atomic_state *state,
1807 struct intel_encoder *encoder,
1808 const struct intel_crtc_state *old_crtc_state,
1809 const struct drm_connector_state *conn_state)
1811 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1812 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1813 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1816 if (old_crtc_state->has_audio)
1817 intel_sdvo_disable_audio(intel_sdvo);
1819 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1821 intel_sdvo_set_encoder_power_state(intel_sdvo,
1824 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1826 temp &= ~SDVO_ENABLE;
1827 intel_sdvo_write_sdvox(intel_sdvo, temp);
1830 * HW workaround for IBX, we need to move the port
1831 * to transcoder A after disabling it to allow the
1832 * matching DP port to be enabled on transcoder A.
1834 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1836 * We get CPU/PCH FIFO underruns on the other pipe when
1837 * doing the workaround. Sweep them under the rug.
1839 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1840 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1842 temp &= ~SDVO_PIPE_SEL_MASK;
1843 temp |= SDVO_ENABLE | SDVO_PIPE_SEL(PIPE_A);
1844 intel_sdvo_write_sdvox(intel_sdvo, temp);
1846 temp &= ~SDVO_ENABLE;
1847 intel_sdvo_write_sdvox(intel_sdvo, temp);
1849 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1850 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1851 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1855 static void pch_disable_sdvo(struct intel_atomic_state *state,
1856 struct intel_encoder *encoder,
1857 const struct intel_crtc_state *old_crtc_state,
1858 const struct drm_connector_state *old_conn_state)
1862 static void pch_post_disable_sdvo(struct intel_atomic_state *state,
1863 struct intel_encoder *encoder,
1864 const struct intel_crtc_state *old_crtc_state,
1865 const struct drm_connector_state *old_conn_state)
1867 intel_disable_sdvo(state, encoder, old_crtc_state, old_conn_state);
1870 static void intel_enable_sdvo(struct intel_atomic_state *state,
1871 struct intel_encoder *encoder,
1872 const struct intel_crtc_state *pipe_config,
1873 const struct drm_connector_state *conn_state)
1875 struct drm_device *dev = encoder->base.dev;
1876 struct drm_i915_private *dev_priv = to_i915(dev);
1877 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1878 struct intel_sdvo_connector *intel_sdvo_connector =
1879 to_intel_sdvo_connector(conn_state->connector);
1880 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
1882 bool input1, input2;
1886 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1887 temp |= SDVO_ENABLE;
1888 intel_sdvo_write_sdvox(intel_sdvo, temp);
1890 for (i = 0; i < 2; i++)
1891 intel_crtc_wait_for_next_vblank(crtc);
1893 success = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1895 * Warn if the device reported failure to sync.
1897 * A lot of SDVO devices fail to notify of sync, but it's
1898 * a given it the status is a success, we succeeded.
1900 if (success && !input1) {
1901 drm_dbg_kms(&dev_priv->drm,
1902 "First %s output reported failure to "
1903 "sync\n", SDVO_NAME(intel_sdvo));
1907 intel_sdvo_set_encoder_power_state(intel_sdvo,
1909 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo_connector->output_flag);
1911 if (pipe_config->has_audio)
1912 intel_sdvo_enable_audio(intel_sdvo, pipe_config, conn_state);
1915 static enum drm_mode_status
1916 intel_sdvo_mode_valid(struct drm_connector *connector,
1917 struct drm_display_mode *mode)
1919 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
1920 struct intel_sdvo_connector *intel_sdvo_connector =
1921 to_intel_sdvo_connector(connector);
1922 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1923 bool has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo_connector, connector->state);
1924 int clock = mode->clock;
1926 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1927 return MODE_NO_DBLESCAN;
1929 if (clock > max_dotclk)
1930 return MODE_CLOCK_HIGH;
1932 if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
1934 return MODE_CLOCK_LOW;
1938 if (intel_sdvo->pixel_clock_min > clock)
1939 return MODE_CLOCK_LOW;
1941 if (intel_sdvo->pixel_clock_max < clock)
1942 return MODE_CLOCK_HIGH;
1944 if (IS_LVDS(intel_sdvo_connector)) {
1945 enum drm_mode_status status;
1947 status = intel_panel_mode_valid(&intel_sdvo_connector->base, mode);
1948 if (status != MODE_OK)
1955 static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1957 BUILD_BUG_ON(sizeof(*caps) != 8);
1958 if (!intel_sdvo_get_value(intel_sdvo,
1959 SDVO_CMD_GET_DEVICE_CAPS,
1960 caps, sizeof(*caps)))
1963 DRM_DEBUG_KMS("SDVO capabilities:\n"
1966 " device_rev_id: %d\n"
1967 " sdvo_version_major: %d\n"
1968 " sdvo_version_minor: %d\n"
1969 " sdvo_num_inputs: %d\n"
1970 " smooth_scaling: %d\n"
1971 " sharp_scaling: %d\n"
1973 " down_scaling: %d\n"
1974 " stall_support: %d\n"
1975 " output_flags: %d\n",
1978 caps->device_rev_id,
1979 caps->sdvo_version_major,
1980 caps->sdvo_version_minor,
1981 caps->sdvo_num_inputs,
1982 caps->smooth_scaling,
1983 caps->sharp_scaling,
1986 caps->stall_support,
1987 caps->output_flags);
1992 static u8 intel_sdvo_get_colorimetry_cap(struct intel_sdvo *intel_sdvo)
1996 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_COLORIMETRY_CAP,
1998 return SDVO_COLORIMETRY_RGB256;
2003 static u16 intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
2005 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
2008 if (!I915_HAS_HOTPLUG(dev_priv))
2012 * HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
2015 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
2018 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
2019 &hotplug, sizeof(hotplug)))
2025 static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
2027 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
2029 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
2030 &intel_sdvo->hotplug_active, 2);
2033 static enum intel_hotplug_state
2034 intel_sdvo_hotplug(struct intel_encoder *encoder,
2035 struct intel_connector *connector)
2037 intel_sdvo_enable_hotplug(encoder);
2039 return intel_encoder_hotplug(encoder, connector);
2042 static const struct drm_edid *
2043 intel_sdvo_get_edid(struct drm_connector *connector)
2045 struct i2c_adapter *ddc = connector->ddc;
2050 return drm_edid_read_ddc(connector, ddc);
2053 /* Mac mini hack -- use the same DDC as the analog connector */
2054 static const struct drm_edid *
2055 intel_sdvo_get_analog_edid(struct drm_connector *connector)
2057 struct drm_i915_private *i915 = to_i915(connector->dev);
2058 struct i2c_adapter *ddc;
2060 ddc = intel_gmbus_get_adapter(i915, i915->display.vbt.crt_ddc_pin);
2064 return drm_edid_read_ddc(connector, ddc);
2067 static enum drm_connector_status
2068 intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
2070 enum drm_connector_status status;
2071 const struct drm_edid *drm_edid;
2073 drm_edid = intel_sdvo_get_edid(connector);
2076 * When there is no edid and no monitor is connected with VGA
2077 * port, try to use the CRT ddc to read the EDID for DVI-connector.
2080 drm_edid = intel_sdvo_get_analog_edid(connector);
2082 status = connector_status_unknown;
2084 /* DDC bus is shared, match EDID to connector type */
2085 if (drm_edid_is_digital(drm_edid))
2086 status = connector_status_connected;
2088 status = connector_status_disconnected;
2089 drm_edid_free(drm_edid);
2096 intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
2097 const struct drm_edid *drm_edid)
2099 bool monitor_is_digital = drm_edid_is_digital(drm_edid);
2100 bool connector_is_digital = !!IS_DIGITAL(sdvo);
2102 DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
2103 connector_is_digital, monitor_is_digital);
2104 return connector_is_digital == monitor_is_digital;
2107 static enum drm_connector_status
2108 intel_sdvo_detect(struct drm_connector *connector, bool force)
2110 struct drm_i915_private *i915 = to_i915(connector->dev);
2111 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2112 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2113 enum drm_connector_status ret;
2116 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2117 connector->base.id, connector->name);
2119 if (!INTEL_DISPLAY_ENABLED(i915))
2120 return connector_status_disconnected;
2122 if (!intel_sdvo_set_target_output(intel_sdvo,
2123 intel_sdvo_connector->output_flag))
2124 return connector_status_unknown;
2126 if (!intel_sdvo_get_value(intel_sdvo,
2127 SDVO_CMD_GET_ATTACHED_DISPLAYS,
2129 return connector_status_unknown;
2131 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
2132 response & 0xff, response >> 8,
2133 intel_sdvo_connector->output_flag);
2136 return connector_status_disconnected;
2138 if ((intel_sdvo_connector->output_flag & response) == 0)
2139 ret = connector_status_disconnected;
2140 else if (IS_TMDS(intel_sdvo_connector))
2141 ret = intel_sdvo_tmds_sink_detect(connector);
2143 const struct drm_edid *drm_edid;
2145 /* if we have an edid check it matches the connection */
2146 drm_edid = intel_sdvo_get_edid(connector);
2148 drm_edid = intel_sdvo_get_analog_edid(connector);
2150 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
2152 ret = connector_status_connected;
2154 ret = connector_status_disconnected;
2156 drm_edid_free(drm_edid);
2158 ret = connector_status_connected;
2165 static int intel_sdvo_get_ddc_modes(struct drm_connector *connector)
2168 const struct drm_edid *drm_edid;
2170 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2171 connector->base.id, connector->name);
2173 /* set the bus switch and get the modes */
2174 drm_edid = intel_sdvo_get_edid(connector);
2177 * Mac mini hack. On this device, the DVI-I connector shares one DDC
2178 * link between analog and digital outputs. So, if the regular SDVO
2179 * DDC fails, check to see if the analog output is disconnected, in
2180 * which case we'll look there for the digital DDC data.
2183 drm_edid = intel_sdvo_get_analog_edid(connector);
2188 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
2190 num_modes += intel_connector_update_modes(connector, drm_edid);
2192 drm_edid_free(drm_edid);
2198 * Set of SDVO TV modes.
2199 * Note! This is in reply order (see loop in get_tv_modes).
2200 * XXX: all 60Hz refresh?
2202 static const struct drm_display_mode sdvo_tv_modes[] = {
2203 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
2204 416, 0, 200, 201, 232, 233, 0,
2205 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2206 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
2207 416, 0, 240, 241, 272, 273, 0,
2208 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2209 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
2210 496, 0, 300, 301, 332, 333, 0,
2211 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2212 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
2213 736, 0, 350, 351, 382, 383, 0,
2214 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2215 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
2216 736, 0, 400, 401, 432, 433, 0,
2217 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2218 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
2219 736, 0, 480, 481, 512, 513, 0,
2220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2221 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
2222 800, 0, 480, 481, 512, 513, 0,
2223 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2224 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
2225 800, 0, 576, 577, 608, 609, 0,
2226 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2227 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
2228 816, 0, 350, 351, 382, 383, 0,
2229 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2230 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
2231 816, 0, 400, 401, 432, 433, 0,
2232 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2233 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
2234 816, 0, 480, 481, 512, 513, 0,
2235 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2236 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
2237 816, 0, 540, 541, 572, 573, 0,
2238 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2239 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
2240 816, 0, 576, 577, 608, 609, 0,
2241 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2242 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
2243 864, 0, 576, 577, 608, 609, 0,
2244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2245 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
2246 896, 0, 600, 601, 632, 633, 0,
2247 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2248 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
2249 928, 0, 624, 625, 656, 657, 0,
2250 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2251 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
2252 1016, 0, 766, 767, 798, 799, 0,
2253 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2254 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
2255 1120, 0, 768, 769, 800, 801, 0,
2256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2257 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
2258 1376, 0, 1024, 1025, 1056, 1057, 0,
2259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2262 static int intel_sdvo_get_tv_modes(struct drm_connector *connector)
2264 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2265 struct intel_sdvo_connector *intel_sdvo_connector =
2266 to_intel_sdvo_connector(connector);
2267 const struct drm_connector_state *conn_state = connector->state;
2268 struct intel_sdvo_sdtv_resolution_request tv_res;
2269 u32 reply = 0, format_map = 0;
2273 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2274 connector->base.id, connector->name);
2277 * Read the list of supported input resolutions for the selected TV
2280 format_map = 1 << conn_state->tv.mode;
2281 memcpy(&tv_res, &format_map,
2282 min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
2284 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo_connector->output_flag))
2287 BUILD_BUG_ON(sizeof(tv_res) != 3);
2288 if (!intel_sdvo_write_cmd(intel_sdvo,
2289 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
2290 &tv_res, sizeof(tv_res)))
2292 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
2295 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++) {
2296 if (reply & (1 << i)) {
2297 struct drm_display_mode *nmode;
2298 nmode = drm_mode_duplicate(connector->dev,
2301 drm_mode_probed_add(connector, nmode);
2310 static int intel_sdvo_get_lvds_modes(struct drm_connector *connector)
2312 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2314 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s]\n",
2315 connector->base.id, connector->name);
2317 return intel_panel_get_modes(to_intel_connector(connector));
2320 static int intel_sdvo_get_modes(struct drm_connector *connector)
2322 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2324 if (IS_TV(intel_sdvo_connector))
2325 return intel_sdvo_get_tv_modes(connector);
2326 else if (IS_LVDS(intel_sdvo_connector))
2327 return intel_sdvo_get_lvds_modes(connector);
2329 return intel_sdvo_get_ddc_modes(connector);
2333 intel_sdvo_connector_atomic_get_property(struct drm_connector *connector,
2334 const struct drm_connector_state *state,
2335 struct drm_property *property,
2338 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2339 const struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state((void *)state);
2341 if (property == intel_sdvo_connector->tv_format) {
2344 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2345 if (state->tv.mode == intel_sdvo_connector->tv_format_supported[i]) {
2351 drm_WARN_ON(connector->dev, 1);
2353 } else if (property == intel_sdvo_connector->top ||
2354 property == intel_sdvo_connector->bottom)
2355 *val = intel_sdvo_connector->max_vscan - sdvo_state->tv.overscan_v;
2356 else if (property == intel_sdvo_connector->left ||
2357 property == intel_sdvo_connector->right)
2358 *val = intel_sdvo_connector->max_hscan - sdvo_state->tv.overscan_h;
2359 else if (property == intel_sdvo_connector->hpos)
2360 *val = sdvo_state->tv.hpos;
2361 else if (property == intel_sdvo_connector->vpos)
2362 *val = sdvo_state->tv.vpos;
2363 else if (property == intel_sdvo_connector->saturation)
2364 *val = state->tv.saturation;
2365 else if (property == intel_sdvo_connector->contrast)
2366 *val = state->tv.contrast;
2367 else if (property == intel_sdvo_connector->hue)
2368 *val = state->tv.hue;
2369 else if (property == intel_sdvo_connector->brightness)
2370 *val = state->tv.brightness;
2371 else if (property == intel_sdvo_connector->sharpness)
2372 *val = sdvo_state->tv.sharpness;
2373 else if (property == intel_sdvo_connector->flicker_filter)
2374 *val = sdvo_state->tv.flicker_filter;
2375 else if (property == intel_sdvo_connector->flicker_filter_2d)
2376 *val = sdvo_state->tv.flicker_filter_2d;
2377 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2378 *val = sdvo_state->tv.flicker_filter_adaptive;
2379 else if (property == intel_sdvo_connector->tv_chroma_filter)
2380 *val = sdvo_state->tv.chroma_filter;
2381 else if (property == intel_sdvo_connector->tv_luma_filter)
2382 *val = sdvo_state->tv.luma_filter;
2383 else if (property == intel_sdvo_connector->dot_crawl)
2384 *val = sdvo_state->tv.dot_crawl;
2386 return intel_digital_connector_atomic_get_property(connector, state, property, val);
2392 intel_sdvo_connector_atomic_set_property(struct drm_connector *connector,
2393 struct drm_connector_state *state,
2394 struct drm_property *property,
2397 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2398 struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state(state);
2400 if (property == intel_sdvo_connector->tv_format) {
2401 state->tv.mode = intel_sdvo_connector->tv_format_supported[val];
2404 struct drm_crtc_state *crtc_state =
2405 drm_atomic_get_new_crtc_state(state->state, state->crtc);
2407 crtc_state->connectors_changed = true;
2409 } else if (property == intel_sdvo_connector->top ||
2410 property == intel_sdvo_connector->bottom)
2411 /* Cannot set these independent from each other */
2412 sdvo_state->tv.overscan_v = intel_sdvo_connector->max_vscan - val;
2413 else if (property == intel_sdvo_connector->left ||
2414 property == intel_sdvo_connector->right)
2415 /* Cannot set these independent from each other */
2416 sdvo_state->tv.overscan_h = intel_sdvo_connector->max_hscan - val;
2417 else if (property == intel_sdvo_connector->hpos)
2418 sdvo_state->tv.hpos = val;
2419 else if (property == intel_sdvo_connector->vpos)
2420 sdvo_state->tv.vpos = val;
2421 else if (property == intel_sdvo_connector->saturation)
2422 state->tv.saturation = val;
2423 else if (property == intel_sdvo_connector->contrast)
2424 state->tv.contrast = val;
2425 else if (property == intel_sdvo_connector->hue)
2426 state->tv.hue = val;
2427 else if (property == intel_sdvo_connector->brightness)
2428 state->tv.brightness = val;
2429 else if (property == intel_sdvo_connector->sharpness)
2430 sdvo_state->tv.sharpness = val;
2431 else if (property == intel_sdvo_connector->flicker_filter)
2432 sdvo_state->tv.flicker_filter = val;
2433 else if (property == intel_sdvo_connector->flicker_filter_2d)
2434 sdvo_state->tv.flicker_filter_2d = val;
2435 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2436 sdvo_state->tv.flicker_filter_adaptive = val;
2437 else if (property == intel_sdvo_connector->tv_chroma_filter)
2438 sdvo_state->tv.chroma_filter = val;
2439 else if (property == intel_sdvo_connector->tv_luma_filter)
2440 sdvo_state->tv.luma_filter = val;
2441 else if (property == intel_sdvo_connector->dot_crawl)
2442 sdvo_state->tv.dot_crawl = val;
2444 return intel_digital_connector_atomic_set_property(connector, state, property, val);
2449 static struct drm_connector_state *
2450 intel_sdvo_connector_duplicate_state(struct drm_connector *connector)
2452 struct intel_sdvo_connector_state *state;
2454 state = kmemdup(connector->state, sizeof(*state), GFP_KERNEL);
2458 __drm_atomic_helper_connector_duplicate_state(connector, &state->base.base);
2459 return &state->base.base;
2462 static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
2463 .detect = intel_sdvo_detect,
2464 .fill_modes = drm_helper_probe_single_connector_modes,
2465 .atomic_get_property = intel_sdvo_connector_atomic_get_property,
2466 .atomic_set_property = intel_sdvo_connector_atomic_set_property,
2467 .late_register = intel_connector_register,
2468 .early_unregister = intel_connector_unregister,
2469 .destroy = intel_connector_destroy,
2470 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
2471 .atomic_duplicate_state = intel_sdvo_connector_duplicate_state,
2474 static int intel_sdvo_atomic_check(struct drm_connector *conn,
2475 struct drm_atomic_state *state)
2477 struct drm_connector_state *new_conn_state =
2478 drm_atomic_get_new_connector_state(state, conn);
2479 struct drm_connector_state *old_conn_state =
2480 drm_atomic_get_old_connector_state(state, conn);
2481 struct intel_sdvo_connector_state *old_state =
2482 to_intel_sdvo_connector_state(old_conn_state);
2483 struct intel_sdvo_connector_state *new_state =
2484 to_intel_sdvo_connector_state(new_conn_state);
2486 if (new_conn_state->crtc &&
2487 (memcmp(&old_state->tv, &new_state->tv, sizeof(old_state->tv)) ||
2488 memcmp(&old_conn_state->tv, &new_conn_state->tv, sizeof(old_conn_state->tv)))) {
2489 struct drm_crtc_state *crtc_state =
2490 drm_atomic_get_new_crtc_state(state,
2491 new_conn_state->crtc);
2493 crtc_state->connectors_changed = true;
2496 return intel_digital_connector_atomic_check(conn, state);
2499 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2500 .get_modes = intel_sdvo_get_modes,
2501 .mode_valid = intel_sdvo_mode_valid,
2502 .atomic_check = intel_sdvo_atomic_check,
2505 static void intel_sdvo_encoder_destroy(struct drm_encoder *_encoder)
2507 struct intel_encoder *encoder = to_intel_encoder(_encoder);
2508 struct intel_sdvo *sdvo = to_sdvo(encoder);
2511 for (i = 0; i < ARRAY_SIZE(sdvo->ddc); i++) {
2512 if (sdvo->ddc[i].ddc_bus)
2513 i2c_del_adapter(&sdvo->ddc[i].ddc);
2516 drm_encoder_cleanup(&encoder->base);
2520 static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2521 .destroy = intel_sdvo_encoder_destroy,
2525 intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo,
2526 struct intel_sdvo_connector *connector)
2532 * Make a mask of outputs less than or equal to our own priority in the
2535 switch (connector->output_flag) {
2536 case SDVO_OUTPUT_LVDS1:
2537 mask |= SDVO_OUTPUT_LVDS1;
2539 case SDVO_OUTPUT_LVDS0:
2540 mask |= SDVO_OUTPUT_LVDS0;
2542 case SDVO_OUTPUT_TMDS1:
2543 mask |= SDVO_OUTPUT_TMDS1;
2545 case SDVO_OUTPUT_TMDS0:
2546 mask |= SDVO_OUTPUT_TMDS0;
2548 case SDVO_OUTPUT_RGB1:
2549 mask |= SDVO_OUTPUT_RGB1;
2551 case SDVO_OUTPUT_RGB0:
2552 mask |= SDVO_OUTPUT_RGB0;
2556 /* Count bits to find what number we are in the priority list. */
2557 mask &= sdvo->caps.output_flags;
2558 num_bits = hweight16(mask);
2559 /* If more than 3 outputs, default to DDC bus 3 for now. */
2563 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2568 * Choose the appropriate DDC bus for control bus switch command for this
2569 * SDVO output based on the controlled output.
2571 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2572 * outputs, then LVDS outputs.
2574 static struct intel_sdvo_ddc *
2575 intel_sdvo_select_ddc_bus(struct intel_sdvo *sdvo,
2576 struct intel_sdvo_connector *connector)
2578 struct drm_i915_private *dev_priv = to_i915(sdvo->base.base.dev);
2579 struct sdvo_device_mapping *mapping;
2582 if (sdvo->base.port == PORT_B)
2583 mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2585 mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2587 if (mapping->initialized)
2588 ddc_bus = (mapping->ddc_pin & 0xf0) >> 4;
2590 ddc_bus = intel_sdvo_guess_ddc_bus(sdvo, connector);
2592 if (ddc_bus < 1 || ddc_bus > 3)
2595 return &sdvo->ddc[ddc_bus - 1];
2599 intel_sdvo_select_i2c_bus(struct intel_sdvo *sdvo)
2601 struct drm_i915_private *dev_priv = to_i915(sdvo->base.base.dev);
2602 struct sdvo_device_mapping *mapping;
2605 if (sdvo->base.port == PORT_B)
2606 mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2608 mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2610 if (mapping->initialized &&
2611 intel_gmbus_is_valid_pin(dev_priv, mapping->i2c_pin))
2612 pin = mapping->i2c_pin;
2614 pin = GMBUS_PIN_DPB;
2616 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s] I2C pin %d, slave addr 0x%x\n",
2617 sdvo->base.base.base.id, sdvo->base.base.name,
2618 pin, sdvo->slave_addr);
2620 sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
2623 * With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
2624 * our code totally fails once we start using gmbus. Hence fall back to
2625 * bit banging for now.
2627 intel_gmbus_force_bit(sdvo->i2c, true);
2630 /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
2632 intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
2634 intel_gmbus_force_bit(sdvo->i2c, false);
2638 intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo)
2640 return intel_sdvo_check_supp_encode(intel_sdvo);
2644 intel_sdvo_get_slave_addr(struct intel_sdvo *sdvo)
2646 struct drm_i915_private *dev_priv = to_i915(sdvo->base.base.dev);
2647 struct sdvo_device_mapping *my_mapping, *other_mapping;
2649 if (sdvo->base.port == PORT_B) {
2650 my_mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2651 other_mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2653 my_mapping = &dev_priv->display.vbt.sdvo_mappings[1];
2654 other_mapping = &dev_priv->display.vbt.sdvo_mappings[0];
2657 /* If the BIOS described our SDVO device, take advantage of it. */
2658 if (my_mapping->slave_addr)
2659 return my_mapping->slave_addr;
2662 * If the BIOS only described a different SDVO device, use the
2663 * address that it isn't using.
2665 if (other_mapping->slave_addr) {
2666 if (other_mapping->slave_addr == 0x70)
2673 * No SDVO device info is found for another DVO port,
2674 * so use mapping assumption we had before BIOS parsing.
2676 if (sdvo->base.port == PORT_B)
2683 intel_sdvo_init_ddc_proxy(struct intel_sdvo_ddc *ddc,
2684 struct intel_sdvo *sdvo, int bit);
2687 intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2688 struct intel_sdvo *encoder)
2690 struct drm_i915_private *i915 = to_i915(encoder->base.base.dev);
2691 struct intel_sdvo_ddc *ddc = NULL;
2694 if (HAS_DDC(connector))
2695 ddc = intel_sdvo_select_ddc_bus(encoder, connector);
2697 ret = drm_connector_init_with_ddc(encoder->base.base.dev,
2698 &connector->base.base,
2699 &intel_sdvo_connector_funcs,
2700 connector->base.base.connector_type,
2701 ddc ? &ddc->ddc : NULL);
2705 drm_connector_helper_add(&connector->base.base,
2706 &intel_sdvo_connector_helper_funcs);
2708 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2709 connector->base.base.interlace_allowed = true;
2710 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2712 intel_connector_attach_encoder(&connector->base, &encoder->base);
2715 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] using %s\n",
2716 connector->base.base.base.id, connector->base.base.name,
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 intel_panel_init_alloc(&sdvo_connector->base);
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, connector->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 */
2983 flags = intel_sdvo_filter_output_flags(intel_sdvo->caps.output_flags);
2986 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%04x)\n",
2987 SDVO_NAME(intel_sdvo), intel_sdvo->caps.output_flags);
2991 for (i = 0; i < ARRAY_SIZE(probe_order); i++) {
2992 u16 type = flags & probe_order[i];
2997 if (!intel_sdvo_output_init(intel_sdvo, type))
3001 intel_sdvo->base.pipe_mask = ~0;
3006 static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
3008 struct drm_device *dev = intel_sdvo->base.base.dev;
3009 struct drm_connector *connector, *tmp;
3011 list_for_each_entry_safe(connector, tmp,
3012 &dev->mode_config.connector_list, head) {
3013 if (intel_attached_encoder(to_intel_connector(connector)) == &intel_sdvo->base) {
3014 drm_connector_unregister(connector);
3015 intel_connector_destroy(connector);
3020 static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
3021 struct intel_sdvo_connector *intel_sdvo_connector,
3024 struct drm_device *dev = intel_sdvo->base.base.dev;
3025 struct intel_sdvo_tv_format format;
3028 if (!intel_sdvo_set_target_output(intel_sdvo, type))
3031 BUILD_BUG_ON(sizeof(format) != 6);
3032 if (!intel_sdvo_get_value(intel_sdvo,
3033 SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
3034 &format, sizeof(format)))
3037 memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
3039 if (format_map == 0)
3042 intel_sdvo_connector->format_supported_num = 0;
3043 for (i = 0 ; i < TV_FORMAT_NUM; i++)
3044 if (format_map & (1 << i))
3045 intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
3048 intel_sdvo_connector->tv_format =
3049 drm_property_create(dev, DRM_MODE_PROP_ENUM,
3050 "mode", intel_sdvo_connector->format_supported_num);
3051 if (!intel_sdvo_connector->tv_format)
3054 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
3055 drm_property_add_enum(intel_sdvo_connector->tv_format, i,
3056 tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
3058 intel_sdvo_connector->base.base.state->tv.mode = intel_sdvo_connector->tv_format_supported[0];
3059 drm_object_attach_property(&intel_sdvo_connector->base.base.base,
3060 intel_sdvo_connector->tv_format, 0);
3065 #define _ENHANCEMENT(state_assignment, name, NAME) do { \
3066 if (enhancements.name) { \
3067 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
3068 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
3070 intel_sdvo_connector->name = \
3071 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
3072 if (!intel_sdvo_connector->name) return false; \
3073 state_assignment = response; \
3074 drm_object_attach_property(&connector->base, \
3075 intel_sdvo_connector->name, 0); \
3076 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
3077 data_value[0], data_value[1], response); \
3081 #define ENHANCEMENT(state, name, NAME) _ENHANCEMENT((state)->name, name, NAME)
3084 intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
3085 struct intel_sdvo_connector *intel_sdvo_connector,
3086 struct intel_sdvo_enhancements_reply enhancements)
3088 struct drm_device *dev = intel_sdvo->base.base.dev;
3089 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3090 struct drm_connector_state *conn_state = connector->state;
3091 struct intel_sdvo_connector_state *sdvo_state =
3092 to_intel_sdvo_connector_state(conn_state);
3093 u16 response, data_value[2];
3095 /* when horizontal overscan is supported, Add the left/right property */
3096 if (enhancements.overscan_h) {
3097 if (!intel_sdvo_get_value(intel_sdvo,
3098 SDVO_CMD_GET_MAX_OVERSCAN_H,
3102 if (!intel_sdvo_get_value(intel_sdvo,
3103 SDVO_CMD_GET_OVERSCAN_H,
3107 sdvo_state->tv.overscan_h = response;
3109 intel_sdvo_connector->max_hscan = data_value[0];
3110 intel_sdvo_connector->left =
3111 drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
3112 if (!intel_sdvo_connector->left)
3115 drm_object_attach_property(&connector->base,
3116 intel_sdvo_connector->left, 0);
3118 intel_sdvo_connector->right =
3119 drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
3120 if (!intel_sdvo_connector->right)
3123 drm_object_attach_property(&connector->base,
3124 intel_sdvo_connector->right, 0);
3125 DRM_DEBUG_KMS("h_overscan: max %d, "
3126 "default %d, current %d\n",
3127 data_value[0], data_value[1], response);
3130 if (enhancements.overscan_v) {
3131 if (!intel_sdvo_get_value(intel_sdvo,
3132 SDVO_CMD_GET_MAX_OVERSCAN_V,
3136 if (!intel_sdvo_get_value(intel_sdvo,
3137 SDVO_CMD_GET_OVERSCAN_V,
3141 sdvo_state->tv.overscan_v = response;
3143 intel_sdvo_connector->max_vscan = data_value[0];
3144 intel_sdvo_connector->top =
3145 drm_property_create_range(dev, 0,
3146 "top_margin", 0, data_value[0]);
3147 if (!intel_sdvo_connector->top)
3150 drm_object_attach_property(&connector->base,
3151 intel_sdvo_connector->top, 0);
3153 intel_sdvo_connector->bottom =
3154 drm_property_create_range(dev, 0,
3155 "bottom_margin", 0, data_value[0]);
3156 if (!intel_sdvo_connector->bottom)
3159 drm_object_attach_property(&connector->base,
3160 intel_sdvo_connector->bottom, 0);
3161 DRM_DEBUG_KMS("v_overscan: max %d, "
3162 "default %d, current %d\n",
3163 data_value[0], data_value[1], response);
3166 ENHANCEMENT(&sdvo_state->tv, hpos, HPOS);
3167 ENHANCEMENT(&sdvo_state->tv, vpos, VPOS);
3168 ENHANCEMENT(&conn_state->tv, saturation, SATURATION);
3169 ENHANCEMENT(&conn_state->tv, contrast, CONTRAST);
3170 ENHANCEMENT(&conn_state->tv, hue, HUE);
3171 ENHANCEMENT(&conn_state->tv, brightness, BRIGHTNESS);
3172 ENHANCEMENT(&sdvo_state->tv, sharpness, SHARPNESS);
3173 ENHANCEMENT(&sdvo_state->tv, flicker_filter, FLICKER_FILTER);
3174 ENHANCEMENT(&sdvo_state->tv, flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
3175 ENHANCEMENT(&sdvo_state->tv, flicker_filter_2d, FLICKER_FILTER_2D);
3176 _ENHANCEMENT(sdvo_state->tv.chroma_filter, tv_chroma_filter, TV_CHROMA_FILTER);
3177 _ENHANCEMENT(sdvo_state->tv.luma_filter, tv_luma_filter, TV_LUMA_FILTER);
3179 if (enhancements.dot_crawl) {
3180 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
3183 sdvo_state->tv.dot_crawl = response & 0x1;
3184 intel_sdvo_connector->dot_crawl =
3185 drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
3186 if (!intel_sdvo_connector->dot_crawl)
3189 drm_object_attach_property(&connector->base,
3190 intel_sdvo_connector->dot_crawl, 0);
3191 DRM_DEBUG_KMS("dot crawl: current %d\n", response);
3198 intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
3199 struct intel_sdvo_connector *intel_sdvo_connector,
3200 struct intel_sdvo_enhancements_reply enhancements)
3202 struct drm_device *dev = intel_sdvo->base.base.dev;
3203 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3204 u16 response, data_value[2];
3206 ENHANCEMENT(&connector->state->tv, brightness, BRIGHTNESS);
3213 static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
3214 struct intel_sdvo_connector *intel_sdvo_connector)
3217 struct intel_sdvo_enhancements_reply reply;
3221 BUILD_BUG_ON(sizeof(enhancements) != 2);
3223 if (!intel_sdvo_get_value(intel_sdvo,
3224 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
3225 &enhancements, sizeof(enhancements)) ||
3226 enhancements.response == 0) {
3227 DRM_DEBUG_KMS("No enhancement is supported\n");
3231 if (IS_TV(intel_sdvo_connector))
3232 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3233 else if (IS_LVDS(intel_sdvo_connector))
3234 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3239 static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
3240 struct i2c_msg *msgs,
3243 struct intel_sdvo_ddc *ddc = adapter->algo_data;
3244 struct intel_sdvo *sdvo = ddc->sdvo;
3246 if (!__intel_sdvo_set_control_bus_switch(sdvo, 1 << ddc->ddc_bus))
3249 return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
3252 static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
3254 struct intel_sdvo_ddc *ddc = adapter->algo_data;
3255 struct intel_sdvo *sdvo = ddc->sdvo;
3257 return sdvo->i2c->algo->functionality(sdvo->i2c);
3260 static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
3261 .master_xfer = intel_sdvo_ddc_proxy_xfer,
3262 .functionality = intel_sdvo_ddc_proxy_func
3265 static void proxy_lock_bus(struct i2c_adapter *adapter,
3268 struct intel_sdvo_ddc *ddc = adapter->algo_data;
3269 struct intel_sdvo *sdvo = ddc->sdvo;
3271 sdvo->i2c->lock_ops->lock_bus(sdvo->i2c, flags);
3274 static int proxy_trylock_bus(struct i2c_adapter *adapter,
3277 struct intel_sdvo_ddc *ddc = adapter->algo_data;
3278 struct intel_sdvo *sdvo = ddc->sdvo;
3280 return sdvo->i2c->lock_ops->trylock_bus(sdvo->i2c, flags);
3283 static void proxy_unlock_bus(struct i2c_adapter *adapter,
3286 struct intel_sdvo_ddc *ddc = adapter->algo_data;
3287 struct intel_sdvo *sdvo = ddc->sdvo;
3289 sdvo->i2c->lock_ops->unlock_bus(sdvo->i2c, flags);
3292 static const struct i2c_lock_operations proxy_lock_ops = {
3293 .lock_bus = proxy_lock_bus,
3294 .trylock_bus = proxy_trylock_bus,
3295 .unlock_bus = proxy_unlock_bus,
3299 intel_sdvo_init_ddc_proxy(struct intel_sdvo_ddc *ddc,
3300 struct intel_sdvo *sdvo, int ddc_bus)
3302 struct drm_i915_private *dev_priv = to_i915(sdvo->base.base.dev);
3303 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
3306 ddc->ddc_bus = ddc_bus;
3308 ddc->ddc.owner = THIS_MODULE;
3309 ddc->ddc.class = I2C_CLASS_DDC;
3310 snprintf(ddc->ddc.name, I2C_NAME_SIZE, "SDVO %c DDC%d",
3311 port_name(sdvo->base.port), ddc_bus);
3312 ddc->ddc.dev.parent = &pdev->dev;
3313 ddc->ddc.algo_data = ddc;
3314 ddc->ddc.algo = &intel_sdvo_ddc_proxy;
3315 ddc->ddc.lock_ops = &proxy_lock_ops;
3317 return i2c_add_adapter(&ddc->ddc);
3320 static bool is_sdvo_port_valid(struct drm_i915_private *dev_priv, enum port port)
3322 if (HAS_PCH_SPLIT(dev_priv))
3323 return port == PORT_B;
3325 return port == PORT_B || port == PORT_C;
3328 static bool assert_sdvo_port_valid(struct drm_i915_private *dev_priv,
3331 return !drm_WARN(&dev_priv->drm, !is_sdvo_port_valid(dev_priv, port),
3332 "Platform does not support SDVO %c\n", port_name(port));
3335 bool intel_sdvo_init(struct drm_i915_private *dev_priv,
3336 i915_reg_t sdvo_reg, enum port port)
3338 struct intel_encoder *intel_encoder;
3339 struct intel_sdvo *intel_sdvo;
3342 if (!assert_port_valid(dev_priv, port))
3345 if (!assert_sdvo_port_valid(dev_priv, port))
3348 intel_sdvo = kzalloc(sizeof(*intel_sdvo), GFP_KERNEL);
3352 /* encoder type will be decided later */
3353 intel_encoder = &intel_sdvo->base;
3354 intel_encoder->type = INTEL_OUTPUT_SDVO;
3355 intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
3356 intel_encoder->port = port;
3358 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
3359 &intel_sdvo_enc_funcs, 0,
3360 "SDVO %c", port_name(port));
3362 intel_sdvo->sdvo_reg = sdvo_reg;
3363 intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(intel_sdvo) >> 1;
3365 intel_sdvo_select_i2c_bus(intel_sdvo);
3367 /* Read the regs to test if we can talk to the device */
3368 for (i = 0; i < 0x40; i++) {
3371 if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
3372 drm_dbg_kms(&dev_priv->drm,
3373 "No SDVO device found on %s\n",
3374 SDVO_NAME(intel_sdvo));
3379 intel_encoder->compute_config = intel_sdvo_compute_config;
3380 if (HAS_PCH_SPLIT(dev_priv)) {
3381 intel_encoder->disable = pch_disable_sdvo;
3382 intel_encoder->post_disable = pch_post_disable_sdvo;
3384 intel_encoder->disable = intel_disable_sdvo;
3386 intel_encoder->pre_enable = intel_sdvo_pre_enable;
3387 intel_encoder->enable = intel_enable_sdvo;
3388 intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
3389 intel_encoder->get_config = intel_sdvo_get_config;
3391 /* In default case sdvo lvds is false */
3392 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
3395 intel_sdvo->colorimetry_cap =
3396 intel_sdvo_get_colorimetry_cap(intel_sdvo);
3398 for (i = 0; i < ARRAY_SIZE(intel_sdvo->ddc); i++) {
3401 ret = intel_sdvo_init_ddc_proxy(&intel_sdvo->ddc[i],
3407 if (!intel_sdvo_output_setup(intel_sdvo)) {
3408 drm_dbg_kms(&dev_priv->drm,
3409 "SDVO output failed to setup on %s\n",
3410 SDVO_NAME(intel_sdvo));
3411 /* Output_setup can leave behind connectors! */
3416 * Only enable the hotplug irq if we need it, to work around noisy
3419 if (intel_sdvo->hotplug_active) {
3420 if (intel_sdvo->base.port == PORT_B)
3421 intel_encoder->hpd_pin = HPD_SDVO_B;
3423 intel_encoder->hpd_pin = HPD_SDVO_C;
3427 * Cloning SDVO with anything is often impossible, since the SDVO
3428 * encoder can request a special input timing mode. And even if that's
3429 * not the case we have evidence that cloning a plain unscaled mode with
3430 * VGA doesn't really work. Furthermore the cloning flags are way too
3431 * simplistic anyway to express such constraints, so just give up on
3432 * cloning for SDVO encoders.
3434 intel_sdvo->base.cloneable = 0;
3436 /* Set the input timing to the screen. Assume always input 0. */
3437 if (!intel_sdvo_set_target_input(intel_sdvo))
3440 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
3441 &intel_sdvo->pixel_clock_min,
3442 &intel_sdvo->pixel_clock_max))
3445 drm_dbg_kms(&dev_priv->drm, "%s device VID/DID: %02X:%02X.%02X, "
3446 "clock range %dMHz - %dMHz, "
3448 "output 1: %c, output 2: %c\n",
3449 SDVO_NAME(intel_sdvo),
3450 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
3451 intel_sdvo->caps.device_rev_id,
3452 intel_sdvo->pixel_clock_min / 1000,
3453 intel_sdvo->pixel_clock_max / 1000,
3454 intel_sdvo->caps.sdvo_num_inputs,
3455 /* check currently supported outputs */
3456 intel_sdvo->caps.output_flags &
3457 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0 |
3458 SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_SVID0 |
3459 SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_YPRPB0) ? 'Y' : 'N',
3460 intel_sdvo->caps.output_flags &
3461 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1 |
3462 SDVO_OUTPUT_LVDS1) ? 'Y' : 'N');
3466 intel_sdvo_output_cleanup(intel_sdvo);
3468 intel_sdvo_unselect_i2c_bus(intel_sdvo);
3469 intel_sdvo_encoder_destroy(&intel_encoder->base);