2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Eric Anholt <eric@anholt.net>
29 #include <linux/delay.h>
30 #include <linux/export.h>
31 #include <linux/i2c.h>
32 #include <linux/slab.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_edid.h>
39 #include "intel_atomic.h"
40 #include "intel_connector.h"
41 #include "intel_display_types.h"
42 #include "intel_fifo_underrun.h"
43 #include "intel_gmbus.h"
44 #include "intel_hdmi.h"
45 #include "intel_hotplug.h"
46 #include "intel_panel.h"
47 #include "intel_sdvo.h"
48 #include "intel_sdvo_regs.h"
50 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
51 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
52 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
53 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
55 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
58 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
59 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
60 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
61 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
62 #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
65 static const char * const tv_format_names[] = {
66 "NTSC_M" , "NTSC_J" , "NTSC_443",
67 "PAL_B" , "PAL_D" , "PAL_G" ,
68 "PAL_H" , "PAL_I" , "PAL_M" ,
69 "PAL_N" , "PAL_NC" , "PAL_60" ,
70 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
71 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
75 #define TV_FORMAT_NUM ARRAY_SIZE(tv_format_names)
78 struct intel_encoder base;
80 struct i2c_adapter *i2c;
83 struct i2c_adapter ddc;
85 /* Register for the SDVO device: SDVOB or SDVOC */
88 /* Active outputs controlled by this SDVO output */
89 u16 controlled_output;
92 * Capabilities of the SDVO device returned by
93 * intel_sdvo_get_capabilities()
95 struct intel_sdvo_caps caps;
97 /* Pixel clock limitations reported by the SDVO device, in kHz */
98 int pixel_clock_min, pixel_clock_max;
101 * For multiple function SDVO device,
102 * this is for current attached outputs.
107 * Hotplug activation bits for this device
113 bool has_hdmi_monitor;
116 /* DDC bus used by this SDVO encoder */
120 * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
125 struct intel_sdvo_connector {
126 struct intel_connector base;
128 /* Mark the type of connector */
131 /* This contains all current supported TV format */
132 u8 tv_format_supported[TV_FORMAT_NUM];
133 int format_supported_num;
134 struct drm_property *tv_format;
136 /* add the property for the SDVO-TV */
137 struct drm_property *left;
138 struct drm_property *right;
139 struct drm_property *top;
140 struct drm_property *bottom;
141 struct drm_property *hpos;
142 struct drm_property *vpos;
143 struct drm_property *contrast;
144 struct drm_property *saturation;
145 struct drm_property *hue;
146 struct drm_property *sharpness;
147 struct drm_property *flicker_filter;
148 struct drm_property *flicker_filter_adaptive;
149 struct drm_property *flicker_filter_2d;
150 struct drm_property *tv_chroma_filter;
151 struct drm_property *tv_luma_filter;
152 struct drm_property *dot_crawl;
154 /* add the property for the SDVO-TV/LVDS */
155 struct drm_property *brightness;
157 /* this is to get the range of margin.*/
158 u32 max_hscan, max_vscan;
161 * This is set if we treat the device as HDMI, instead of DVI.
166 struct intel_sdvo_connector_state {
167 /* base.base: tv.saturation/contrast/hue/brightness */
168 struct intel_digital_connector_state base;
171 unsigned overscan_h, overscan_v, hpos, vpos, sharpness;
172 unsigned flicker_filter, flicker_filter_2d, flicker_filter_adaptive;
173 unsigned chroma_filter, luma_filter, dot_crawl;
177 static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
179 return container_of(encoder, struct intel_sdvo, base);
182 static struct intel_sdvo *intel_attached_sdvo(struct intel_connector *connector)
184 return to_sdvo(intel_attached_encoder(connector));
187 static struct intel_sdvo_connector *
188 to_intel_sdvo_connector(struct drm_connector *connector)
190 return container_of(connector, struct intel_sdvo_connector, base.base);
193 #define to_intel_sdvo_connector_state(conn_state) \
194 container_of((conn_state), struct intel_sdvo_connector_state, base.base)
197 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, u16 flags);
199 intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
200 struct intel_sdvo_connector *intel_sdvo_connector,
203 intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
204 struct intel_sdvo_connector *intel_sdvo_connector);
207 * Writes the SDVOB or SDVOC with the given value, but always writes both
208 * SDVOB and SDVOC to work around apparent hardware issues (according to
209 * comments in the BIOS).
211 static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
213 struct drm_device *dev = intel_sdvo->base.base.dev;
214 struct drm_i915_private *dev_priv = to_i915(dev);
215 u32 bval = val, cval = val;
218 if (HAS_PCH_SPLIT(dev_priv)) {
219 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
220 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
222 * HW workaround, need to write this twice for issue
223 * that may result in first write getting masked.
225 if (HAS_PCH_IBX(dev_priv)) {
226 intel_de_write(dev_priv, intel_sdvo->sdvo_reg, val);
227 intel_de_posting_read(dev_priv, intel_sdvo->sdvo_reg);
232 if (intel_sdvo->port == PORT_B)
233 cval = intel_de_read(dev_priv, GEN3_SDVOC);
235 bval = intel_de_read(dev_priv, GEN3_SDVOB);
238 * Write the registers twice for luck. Sometimes,
239 * writing them only once doesn't appear to 'stick'.
240 * The BIOS does this too. Yay, magic
242 for (i = 0; i < 2; i++) {
243 intel_de_write(dev_priv, GEN3_SDVOB, bval);
244 intel_de_posting_read(dev_priv, GEN3_SDVOB);
246 intel_de_write(dev_priv, GEN3_SDVOC, cval);
247 intel_de_posting_read(dev_priv, GEN3_SDVOC);
251 static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
253 struct i2c_msg msgs[] = {
255 .addr = intel_sdvo->slave_addr,
261 .addr = intel_sdvo->slave_addr,
269 if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
272 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
276 #define SDVO_CMD_NAME_ENTRY(cmd_) { .cmd = SDVO_CMD_ ## cmd_, .name = #cmd_ }
278 /** Mapping of command numbers to names, for debug output */
279 static const struct {
282 } __attribute__ ((packed)) sdvo_cmd_names[] = {
283 SDVO_CMD_NAME_ENTRY(RESET),
284 SDVO_CMD_NAME_ENTRY(GET_DEVICE_CAPS),
285 SDVO_CMD_NAME_ENTRY(GET_FIRMWARE_REV),
286 SDVO_CMD_NAME_ENTRY(GET_TRAINED_INPUTS),
287 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_OUTPUTS),
288 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_OUTPUTS),
289 SDVO_CMD_NAME_ENTRY(GET_IN_OUT_MAP),
290 SDVO_CMD_NAME_ENTRY(SET_IN_OUT_MAP),
291 SDVO_CMD_NAME_ENTRY(GET_ATTACHED_DISPLAYS),
292 SDVO_CMD_NAME_ENTRY(GET_HOT_PLUG_SUPPORT),
293 SDVO_CMD_NAME_ENTRY(SET_ACTIVE_HOT_PLUG),
294 SDVO_CMD_NAME_ENTRY(GET_ACTIVE_HOT_PLUG),
295 SDVO_CMD_NAME_ENTRY(GET_INTERRUPT_EVENT_SOURCE),
296 SDVO_CMD_NAME_ENTRY(SET_TARGET_INPUT),
297 SDVO_CMD_NAME_ENTRY(SET_TARGET_OUTPUT),
298 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART1),
299 SDVO_CMD_NAME_ENTRY(GET_INPUT_TIMINGS_PART2),
300 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART1),
301 SDVO_CMD_NAME_ENTRY(SET_INPUT_TIMINGS_PART2),
302 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART1),
303 SDVO_CMD_NAME_ENTRY(SET_OUTPUT_TIMINGS_PART2),
304 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART1),
305 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_TIMINGS_PART2),
306 SDVO_CMD_NAME_ENTRY(CREATE_PREFERRED_INPUT_TIMING),
307 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART1),
308 SDVO_CMD_NAME_ENTRY(GET_PREFERRED_INPUT_TIMING_PART2),
309 SDVO_CMD_NAME_ENTRY(GET_INPUT_PIXEL_CLOCK_RANGE),
310 SDVO_CMD_NAME_ENTRY(GET_OUTPUT_PIXEL_CLOCK_RANGE),
311 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_CLOCK_RATE_MULTS),
312 SDVO_CMD_NAME_ENTRY(GET_CLOCK_RATE_MULT),
313 SDVO_CMD_NAME_ENTRY(SET_CLOCK_RATE_MULT),
314 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_TV_FORMATS),
315 SDVO_CMD_NAME_ENTRY(GET_TV_FORMAT),
316 SDVO_CMD_NAME_ENTRY(SET_TV_FORMAT),
317 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_POWER_STATES),
318 SDVO_CMD_NAME_ENTRY(GET_POWER_STATE),
319 SDVO_CMD_NAME_ENTRY(SET_ENCODER_POWER_STATE),
320 SDVO_CMD_NAME_ENTRY(SET_DISPLAY_POWER_STATE),
321 SDVO_CMD_NAME_ENTRY(SET_CONTROL_BUS_SWITCH),
322 SDVO_CMD_NAME_ENTRY(GET_SDTV_RESOLUTION_SUPPORT),
323 SDVO_CMD_NAME_ENTRY(GET_SCALED_HDTV_RESOLUTION_SUPPORT),
324 SDVO_CMD_NAME_ENTRY(GET_SUPPORTED_ENHANCEMENTS),
326 /* Add the op code for SDVO enhancements */
327 SDVO_CMD_NAME_ENTRY(GET_MAX_HPOS),
328 SDVO_CMD_NAME_ENTRY(GET_HPOS),
329 SDVO_CMD_NAME_ENTRY(SET_HPOS),
330 SDVO_CMD_NAME_ENTRY(GET_MAX_VPOS),
331 SDVO_CMD_NAME_ENTRY(GET_VPOS),
332 SDVO_CMD_NAME_ENTRY(SET_VPOS),
333 SDVO_CMD_NAME_ENTRY(GET_MAX_SATURATION),
334 SDVO_CMD_NAME_ENTRY(GET_SATURATION),
335 SDVO_CMD_NAME_ENTRY(SET_SATURATION),
336 SDVO_CMD_NAME_ENTRY(GET_MAX_HUE),
337 SDVO_CMD_NAME_ENTRY(GET_HUE),
338 SDVO_CMD_NAME_ENTRY(SET_HUE),
339 SDVO_CMD_NAME_ENTRY(GET_MAX_CONTRAST),
340 SDVO_CMD_NAME_ENTRY(GET_CONTRAST),
341 SDVO_CMD_NAME_ENTRY(SET_CONTRAST),
342 SDVO_CMD_NAME_ENTRY(GET_MAX_BRIGHTNESS),
343 SDVO_CMD_NAME_ENTRY(GET_BRIGHTNESS),
344 SDVO_CMD_NAME_ENTRY(SET_BRIGHTNESS),
345 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_H),
346 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_H),
347 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_H),
348 SDVO_CMD_NAME_ENTRY(GET_MAX_OVERSCAN_V),
349 SDVO_CMD_NAME_ENTRY(GET_OVERSCAN_V),
350 SDVO_CMD_NAME_ENTRY(SET_OVERSCAN_V),
351 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER),
352 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER),
353 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER),
354 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_ADAPTIVE),
355 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_ADAPTIVE),
356 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_ADAPTIVE),
357 SDVO_CMD_NAME_ENTRY(GET_MAX_FLICKER_FILTER_2D),
358 SDVO_CMD_NAME_ENTRY(GET_FLICKER_FILTER_2D),
359 SDVO_CMD_NAME_ENTRY(SET_FLICKER_FILTER_2D),
360 SDVO_CMD_NAME_ENTRY(GET_MAX_SHARPNESS),
361 SDVO_CMD_NAME_ENTRY(GET_SHARPNESS),
362 SDVO_CMD_NAME_ENTRY(SET_SHARPNESS),
363 SDVO_CMD_NAME_ENTRY(GET_DOT_CRAWL),
364 SDVO_CMD_NAME_ENTRY(SET_DOT_CRAWL),
365 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_CHROMA_FILTER),
366 SDVO_CMD_NAME_ENTRY(GET_TV_CHROMA_FILTER),
367 SDVO_CMD_NAME_ENTRY(SET_TV_CHROMA_FILTER),
368 SDVO_CMD_NAME_ENTRY(GET_MAX_TV_LUMA_FILTER),
369 SDVO_CMD_NAME_ENTRY(GET_TV_LUMA_FILTER),
370 SDVO_CMD_NAME_ENTRY(SET_TV_LUMA_FILTER),
373 SDVO_CMD_NAME_ENTRY(GET_SUPP_ENCODE),
374 SDVO_CMD_NAME_ENTRY(GET_ENCODE),
375 SDVO_CMD_NAME_ENTRY(SET_ENCODE),
376 SDVO_CMD_NAME_ENTRY(SET_PIXEL_REPLI),
377 SDVO_CMD_NAME_ENTRY(GET_PIXEL_REPLI),
378 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY_CAP),
379 SDVO_CMD_NAME_ENTRY(SET_COLORIMETRY),
380 SDVO_CMD_NAME_ENTRY(GET_COLORIMETRY),
381 SDVO_CMD_NAME_ENTRY(GET_AUDIO_ENCRYPT_PREFER),
382 SDVO_CMD_NAME_ENTRY(SET_AUDIO_STAT),
383 SDVO_CMD_NAME_ENTRY(GET_AUDIO_STAT),
384 SDVO_CMD_NAME_ENTRY(GET_HBUF_INDEX),
385 SDVO_CMD_NAME_ENTRY(SET_HBUF_INDEX),
386 SDVO_CMD_NAME_ENTRY(GET_HBUF_INFO),
387 SDVO_CMD_NAME_ENTRY(GET_HBUF_AV_SPLIT),
388 SDVO_CMD_NAME_ENTRY(SET_HBUF_AV_SPLIT),
389 SDVO_CMD_NAME_ENTRY(GET_HBUF_TXRATE),
390 SDVO_CMD_NAME_ENTRY(SET_HBUF_TXRATE),
391 SDVO_CMD_NAME_ENTRY(SET_HBUF_DATA),
392 SDVO_CMD_NAME_ENTRY(GET_HBUF_DATA),
395 #undef SDVO_CMD_NAME_ENTRY
397 static const char *sdvo_cmd_name(u8 cmd)
401 for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
402 if (cmd == sdvo_cmd_names[i].cmd)
403 return sdvo_cmd_names[i].name;
409 #define SDVO_NAME(svdo) ((svdo)->port == PORT_B ? "SDVOB" : "SDVOC")
411 static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
412 const void *args, int args_len)
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 WARN_ON(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 const char *cmd_status;
537 u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
545 * The documentation states that all commands will be
546 * processed within 15µs, and that we need only poll
547 * the status byte a maximum of 3 times in order for the
548 * command to be complete.
550 * Check 5 times in case the hardware failed to read the docs.
552 * Also beware that the first response by many devices is to
553 * reply PENDING and stall for time. TVs are notorious for
554 * requiring longer than specified to complete their replies.
555 * Originally (in the DDX long ago), the delay was only ever 15ms
556 * with an additional delay of 30ms applied for TVs added later after
557 * many experiments. To accommodate both sets of delays, we do a
558 * sequence of slow checks if the device is falling behind and fails
559 * to reply within 5*15µs.
561 if (!intel_sdvo_read_byte(intel_sdvo,
566 while ((status == SDVO_CMD_STATUS_PENDING ||
567 status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
573 if (!intel_sdvo_read_byte(intel_sdvo,
579 #define BUF_PRINT(args...) \
580 pos += snprintf(buffer + pos, max_t(int, sizeof(buffer) - pos, 0), args)
582 cmd_status = sdvo_cmd_status(status);
584 BUF_PRINT("(%s)", cmd_status);
586 BUF_PRINT("(??? %d)", status);
588 if (status != SDVO_CMD_STATUS_SUCCESS)
591 /* Read the command response */
592 for (i = 0; i < response_len; i++) {
593 if (!intel_sdvo_read_byte(intel_sdvo,
594 SDVO_I2C_RETURN_0 + i,
595 &((u8 *)response)[i]))
597 BUF_PRINT(" %02X", ((u8 *)response)[i]);
600 WARN_ON(pos >= sizeof(buffer) - 1);
603 DRM_DEBUG_KMS("%s: R: %s\n", SDVO_NAME(intel_sdvo), buffer);
607 DRM_DEBUG_KMS("%s: R: ... failed %s\n",
608 SDVO_NAME(intel_sdvo), buffer);
612 static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode *adjusted_mode)
614 if (adjusted_mode->crtc_clock >= 100000)
616 else if (adjusted_mode->crtc_clock >= 50000)
622 static bool __intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
625 /* This must be the immediately preceding write before the i2c xfer */
626 return __intel_sdvo_write_cmd(intel_sdvo,
627 SDVO_CMD_SET_CONTROL_BUS_SWITCH,
631 static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
633 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
636 return intel_sdvo_read_response(intel_sdvo, NULL, 0);
640 intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
642 if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
645 return intel_sdvo_read_response(intel_sdvo, value, len);
648 static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
650 struct intel_sdvo_set_target_input_args targets = {0};
651 return intel_sdvo_set_value(intel_sdvo,
652 SDVO_CMD_SET_TARGET_INPUT,
653 &targets, sizeof(targets));
657 * Return whether each input is trained.
659 * This function is making an assumption about the layout of the response,
660 * which should be checked against the docs.
662 static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
664 struct intel_sdvo_get_trained_inputs_response response;
666 BUILD_BUG_ON(sizeof(response) != 1);
667 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
668 &response, sizeof(response)))
671 *input_1 = response.input0_trained;
672 *input_2 = response.input1_trained;
676 static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
679 return intel_sdvo_set_value(intel_sdvo,
680 SDVO_CMD_SET_ACTIVE_OUTPUTS,
681 &outputs, sizeof(outputs));
684 static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
687 return intel_sdvo_get_value(intel_sdvo,
688 SDVO_CMD_GET_ACTIVE_OUTPUTS,
689 outputs, sizeof(*outputs));
692 static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
695 u8 state = SDVO_ENCODER_STATE_ON;
698 case DRM_MODE_DPMS_ON:
699 state = SDVO_ENCODER_STATE_ON;
701 case DRM_MODE_DPMS_STANDBY:
702 state = SDVO_ENCODER_STATE_STANDBY;
704 case DRM_MODE_DPMS_SUSPEND:
705 state = SDVO_ENCODER_STATE_SUSPEND;
707 case DRM_MODE_DPMS_OFF:
708 state = SDVO_ENCODER_STATE_OFF;
712 return intel_sdvo_set_value(intel_sdvo,
713 SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
716 static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
720 struct intel_sdvo_pixel_clock_range clocks;
722 BUILD_BUG_ON(sizeof(clocks) != 4);
723 if (!intel_sdvo_get_value(intel_sdvo,
724 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
725 &clocks, sizeof(clocks)))
728 /* Convert the values from units of 10 kHz to kHz. */
729 *clock_min = clocks.min * 10;
730 *clock_max = clocks.max * 10;
734 static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
737 return intel_sdvo_set_value(intel_sdvo,
738 SDVO_CMD_SET_TARGET_OUTPUT,
739 &outputs, sizeof(outputs));
742 static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
743 struct intel_sdvo_dtd *dtd)
745 return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
746 intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
749 static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
750 struct intel_sdvo_dtd *dtd)
752 return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
753 intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
756 static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
757 struct intel_sdvo_dtd *dtd)
759 return intel_sdvo_set_timing(intel_sdvo,
760 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
763 static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
764 struct intel_sdvo_dtd *dtd)
766 return intel_sdvo_set_timing(intel_sdvo,
767 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
770 static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
771 struct intel_sdvo_dtd *dtd)
773 return intel_sdvo_get_timing(intel_sdvo,
774 SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
778 intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
779 struct intel_sdvo_connector *intel_sdvo_connector,
784 struct intel_sdvo_preferred_input_timing_args args;
786 memset(&args, 0, sizeof(args));
789 args.height = height;
792 if (IS_LVDS(intel_sdvo_connector)) {
793 const struct drm_display_mode *fixed_mode =
794 intel_sdvo_connector->base.panel.fixed_mode;
796 if (fixed_mode->hdisplay != width ||
797 fixed_mode->vdisplay != height)
801 return intel_sdvo_set_value(intel_sdvo,
802 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
803 &args, sizeof(args));
806 static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
807 struct intel_sdvo_dtd *dtd)
809 BUILD_BUG_ON(sizeof(dtd->part1) != 8);
810 BUILD_BUG_ON(sizeof(dtd->part2) != 8);
811 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
812 &dtd->part1, sizeof(dtd->part1)) &&
813 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
814 &dtd->part2, sizeof(dtd->part2));
817 static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
819 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
822 static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
823 const struct drm_display_mode *mode)
826 u16 h_blank_len, h_sync_len, v_blank_len, v_sync_len;
827 u16 h_sync_offset, v_sync_offset;
830 memset(dtd, 0, sizeof(*dtd));
832 width = mode->hdisplay;
833 height = mode->vdisplay;
835 /* do some mode translations */
836 h_blank_len = mode->htotal - mode->hdisplay;
837 h_sync_len = mode->hsync_end - mode->hsync_start;
839 v_blank_len = mode->vtotal - mode->vdisplay;
840 v_sync_len = mode->vsync_end - mode->vsync_start;
842 h_sync_offset = mode->hsync_start - mode->hdisplay;
843 v_sync_offset = mode->vsync_start - mode->vdisplay;
845 mode_clock = mode->clock;
847 dtd->part1.clock = mode_clock;
849 dtd->part1.h_active = width & 0xff;
850 dtd->part1.h_blank = h_blank_len & 0xff;
851 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
852 ((h_blank_len >> 8) & 0xf);
853 dtd->part1.v_active = height & 0xff;
854 dtd->part1.v_blank = v_blank_len & 0xff;
855 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
856 ((v_blank_len >> 8) & 0xf);
858 dtd->part2.h_sync_off = h_sync_offset & 0xff;
859 dtd->part2.h_sync_width = h_sync_len & 0xff;
860 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
862 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
863 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
864 ((v_sync_len & 0x30) >> 4);
866 dtd->part2.dtd_flags = 0x18;
867 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
868 dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
869 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
870 dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
871 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
872 dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
874 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
877 static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode *pmode,
878 const struct intel_sdvo_dtd *dtd)
880 struct drm_display_mode mode = {};
882 mode.hdisplay = dtd->part1.h_active;
883 mode.hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
884 mode.hsync_start = mode.hdisplay + dtd->part2.h_sync_off;
885 mode.hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
886 mode.hsync_end = mode.hsync_start + dtd->part2.h_sync_width;
887 mode.hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
888 mode.htotal = mode.hdisplay + dtd->part1.h_blank;
889 mode.htotal += (dtd->part1.h_high & 0xf) << 8;
891 mode.vdisplay = dtd->part1.v_active;
892 mode.vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
893 mode.vsync_start = mode.vdisplay;
894 mode.vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
895 mode.vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
896 mode.vsync_start += dtd->part2.v_sync_off_high & 0xc0;
897 mode.vsync_end = mode.vsync_start +
898 (dtd->part2.v_sync_off_width & 0xf);
899 mode.vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
900 mode.vtotal = mode.vdisplay + dtd->part1.v_blank;
901 mode.vtotal += (dtd->part1.v_high & 0xf) << 8;
903 mode.clock = dtd->part1.clock * 10;
905 if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
906 mode.flags |= DRM_MODE_FLAG_INTERLACE;
907 if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
908 mode.flags |= DRM_MODE_FLAG_PHSYNC;
910 mode.flags |= DRM_MODE_FLAG_NHSYNC;
911 if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
912 mode.flags |= DRM_MODE_FLAG_PVSYNC;
914 mode.flags |= DRM_MODE_FLAG_NVSYNC;
916 drm_mode_set_crtcinfo(&mode, 0);
918 drm_mode_copy(pmode, &mode);
921 static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
923 struct intel_sdvo_encode encode;
925 BUILD_BUG_ON(sizeof(encode) != 2);
926 return intel_sdvo_get_value(intel_sdvo,
927 SDVO_CMD_GET_SUPP_ENCODE,
928 &encode, sizeof(encode));
931 static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
934 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
937 static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
940 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
943 static bool intel_sdvo_set_audio_state(struct intel_sdvo *intel_sdvo,
946 return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_AUDIO_STAT,
950 static bool intel_sdvo_get_hbuf_size(struct intel_sdvo *intel_sdvo,
953 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
957 /* Buffer size is 0 based, hooray! However zero means zero. */
965 static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
974 intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
976 for (i = 0; i <= av_split; i++) {
977 set_buf_index[0] = i; set_buf_index[1] = 0;
978 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
980 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
981 intel_sdvo_read_response(encoder, &buf_size, 1);
984 for (j = 0; j <= buf_size; j += 8) {
985 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
987 intel_sdvo_read_response(encoder, pos, 8);
994 static bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
995 unsigned int if_index, u8 tx_rate,
996 const u8 *data, unsigned int length)
998 u8 set_buf_index[2] = { if_index, 0 };
999 u8 hbuf_size, tmp[8];
1002 if (!intel_sdvo_set_value(intel_sdvo,
1003 SDVO_CMD_SET_HBUF_INDEX,
1007 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1010 DRM_DEBUG_KMS("writing sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1011 if_index, length, hbuf_size);
1013 if (hbuf_size < length)
1016 for (i = 0; i < hbuf_size; i += 8) {
1019 memcpy(tmp, data + i, min_t(unsigned, 8, length - i));
1021 if (!intel_sdvo_set_value(intel_sdvo,
1022 SDVO_CMD_SET_HBUF_DATA,
1027 return intel_sdvo_set_value(intel_sdvo,
1028 SDVO_CMD_SET_HBUF_TXRATE,
1032 static ssize_t intel_sdvo_read_infoframe(struct intel_sdvo *intel_sdvo,
1033 unsigned int if_index,
1034 u8 *data, unsigned int length)
1036 u8 set_buf_index[2] = { if_index, 0 };
1037 u8 hbuf_size, tx_rate, av_split;
1040 if (!intel_sdvo_get_value(intel_sdvo,
1041 SDVO_CMD_GET_HBUF_AV_SPLIT,
1045 if (av_split < if_index)
1048 if (!intel_sdvo_set_value(intel_sdvo,
1049 SDVO_CMD_SET_HBUF_INDEX,
1053 if (!intel_sdvo_get_value(intel_sdvo,
1054 SDVO_CMD_GET_HBUF_TXRATE,
1058 if (tx_rate == SDVO_HBUF_TX_DISABLED)
1061 if (!intel_sdvo_get_hbuf_size(intel_sdvo, &hbuf_size))
1064 DRM_DEBUG_KMS("reading sdvo hbuf: %i, length %u, hbuf_size: %i\n",
1065 if_index, length, hbuf_size);
1067 hbuf_size = min_t(unsigned int, length, hbuf_size);
1069 for (i = 0; i < hbuf_size; i += 8) {
1070 if (!intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_GET_HBUF_DATA, NULL, 0))
1072 if (!intel_sdvo_read_response(intel_sdvo, &data[i],
1073 min_t(unsigned int, 8, hbuf_size - i)))
1080 static bool intel_sdvo_compute_avi_infoframe(struct intel_sdvo *intel_sdvo,
1081 struct intel_crtc_state *crtc_state,
1082 struct drm_connector_state *conn_state)
1084 struct hdmi_avi_infoframe *frame = &crtc_state->infoframes.avi.avi;
1085 const struct drm_display_mode *adjusted_mode =
1086 &crtc_state->hw.adjusted_mode;
1089 if (!crtc_state->has_hdmi_sink)
1092 crtc_state->infoframes.enable |=
1093 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1095 ret = drm_hdmi_avi_infoframe_from_display_mode(frame,
1096 conn_state->connector,
1101 drm_hdmi_avi_infoframe_quant_range(frame,
1102 conn_state->connector,
1104 crtc_state->limited_color_range ?
1105 HDMI_QUANTIZATION_RANGE_LIMITED :
1106 HDMI_QUANTIZATION_RANGE_FULL);
1108 ret = hdmi_avi_infoframe_check(frame);
1115 static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1116 const struct intel_crtc_state *crtc_state)
1118 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1119 const union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1122 if ((crtc_state->infoframes.enable &
1123 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI)) == 0)
1126 if (WARN_ON(frame->any.type != HDMI_INFOFRAME_TYPE_AVI))
1129 len = hdmi_infoframe_pack_only(frame, sdvo_data, sizeof(sdvo_data));
1130 if (WARN_ON(len < 0))
1133 return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1138 static void intel_sdvo_get_avi_infoframe(struct intel_sdvo *intel_sdvo,
1139 struct intel_crtc_state *crtc_state)
1141 u8 sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
1142 union hdmi_infoframe *frame = &crtc_state->infoframes.avi;
1146 if (!crtc_state->has_hdmi_sink)
1149 len = intel_sdvo_read_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1150 sdvo_data, sizeof(sdvo_data));
1152 DRM_DEBUG_KMS("failed to read AVI infoframe\n");
1154 } else if (len == 0) {
1158 crtc_state->infoframes.enable |=
1159 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI);
1161 ret = hdmi_infoframe_unpack(frame, sdvo_data, len);
1163 DRM_DEBUG_KMS("Failed to unpack AVI infoframe\n");
1167 if (frame->any.type != HDMI_INFOFRAME_TYPE_AVI)
1168 DRM_DEBUG_KMS("Found the wrong infoframe type 0x%x (expected 0x%02x)\n",
1169 frame->any.type, HDMI_INFOFRAME_TYPE_AVI);
1172 static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo,
1173 const struct drm_connector_state *conn_state)
1175 struct intel_sdvo_tv_format format;
1178 format_map = 1 << conn_state->tv.mode;
1179 memset(&format, 0, sizeof(format));
1180 memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1182 BUILD_BUG_ON(sizeof(format) != 6);
1183 return intel_sdvo_set_value(intel_sdvo,
1184 SDVO_CMD_SET_TV_FORMAT,
1185 &format, sizeof(format));
1189 intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1190 const struct drm_display_mode *mode)
1192 struct intel_sdvo_dtd output_dtd;
1194 if (!intel_sdvo_set_target_output(intel_sdvo,
1195 intel_sdvo->attached_output))
1198 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1199 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1206 * Asks the sdvo controller for the preferred input mode given the output mode.
1207 * Unfortunately we have to set up the full output mode to do that.
1210 intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
1211 struct intel_sdvo_connector *intel_sdvo_connector,
1212 const struct drm_display_mode *mode,
1213 struct drm_display_mode *adjusted_mode)
1215 struct intel_sdvo_dtd input_dtd;
1217 /* Reset the input timing to the screen. Assume always input 0. */
1218 if (!intel_sdvo_set_target_input(intel_sdvo))
1221 if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1222 intel_sdvo_connector,
1228 if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1232 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1233 intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1238 static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_state *pipe_config)
1240 unsigned dotclock = pipe_config->port_clock;
1241 struct dpll *clock = &pipe_config->dpll;
1244 * SDVO TV has fixed PLL values depend on its clock range,
1245 * this mirrors vbios setting.
1247 if (dotclock >= 100000 && dotclock < 140500) {
1253 } else if (dotclock >= 140500 && dotclock <= 200000) {
1260 WARN(1, "SDVO TV clock out of range: %i\n", dotclock);
1263 pipe_config->clock_set = true;
1266 static bool intel_has_hdmi_sink(struct intel_sdvo *sdvo,
1267 const struct drm_connector_state *conn_state)
1269 return sdvo->has_hdmi_monitor &&
1270 READ_ONCE(to_intel_digital_connector_state(conn_state)->force_audio) != HDMI_AUDIO_OFF_DVI;
1273 static int intel_sdvo_compute_config(struct intel_encoder *encoder,
1274 struct intel_crtc_state *pipe_config,
1275 struct drm_connector_state *conn_state)
1277 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1278 struct intel_sdvo_connector_state *intel_sdvo_state =
1279 to_intel_sdvo_connector_state(conn_state);
1280 struct intel_sdvo_connector *intel_sdvo_connector =
1281 to_intel_sdvo_connector(conn_state->connector);
1282 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1283 struct drm_display_mode *mode = &pipe_config->hw.mode;
1285 DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1286 pipe_config->pipe_bpp = 8*3;
1287 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
1289 if (HAS_PCH_SPLIT(to_i915(encoder->base.dev)))
1290 pipe_config->has_pch_encoder = true;
1293 * We need to construct preferred input timings based on our
1294 * output timings. To do that, we have to set the output
1295 * timings, even though this isn't really the right place in
1296 * the sequence to do it. Oh well.
1298 if (IS_TV(intel_sdvo_connector)) {
1299 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1302 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1303 intel_sdvo_connector,
1306 pipe_config->sdvo_tv_clock = true;
1307 } else if (IS_LVDS(intel_sdvo_connector)) {
1308 if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1309 intel_sdvo_connector->base.panel.fixed_mode))
1312 (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1313 intel_sdvo_connector,
1318 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
1322 * Make the CRTC code factor in the SDVO pixel multiplier. The
1323 * SDVO device will factor out the multiplier during mode_set.
1325 pipe_config->pixel_multiplier =
1326 intel_sdvo_get_pixel_multiplier(adjusted_mode);
1328 pipe_config->has_hdmi_sink = intel_has_hdmi_sink(intel_sdvo, conn_state);
1330 if (pipe_config->has_hdmi_sink) {
1331 if (intel_sdvo_state->base.force_audio == HDMI_AUDIO_AUTO)
1332 pipe_config->has_audio = intel_sdvo->has_hdmi_audio;
1334 pipe_config->has_audio =
1335 intel_sdvo_state->base.force_audio == HDMI_AUDIO_ON;
1338 if (intel_sdvo_state->base.broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
1340 * See CEA-861-E - 5.1 Default Encoding Parameters
1342 * FIXME: This bit is only valid when using TMDS encoding and 8
1343 * bit per color mode.
1345 if (pipe_config->has_hdmi_sink &&
1346 drm_match_cea_mode(adjusted_mode) > 1)
1347 pipe_config->limited_color_range = true;
1349 if (pipe_config->has_hdmi_sink &&
1350 intel_sdvo_state->base.broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED)
1351 pipe_config->limited_color_range = true;
1354 /* Clock computation needs to happen after pixel multiplier. */
1355 if (IS_TV(intel_sdvo_connector))
1356 i9xx_adjust_sdvo_tv_clock(pipe_config);
1358 if (conn_state->picture_aspect_ratio)
1359 adjusted_mode->picture_aspect_ratio =
1360 conn_state->picture_aspect_ratio;
1362 if (!intel_sdvo_compute_avi_infoframe(intel_sdvo,
1363 pipe_config, conn_state)) {
1364 DRM_DEBUG_KMS("bad AVI infoframe\n");
1371 #define UPDATE_PROPERTY(input, NAME) \
1374 intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_##NAME, &val, sizeof(val)); \
1377 static void intel_sdvo_update_props(struct intel_sdvo *intel_sdvo,
1378 const struct intel_sdvo_connector_state *sdvo_state)
1380 const struct drm_connector_state *conn_state = &sdvo_state->base.base;
1381 struct intel_sdvo_connector *intel_sdvo_conn =
1382 to_intel_sdvo_connector(conn_state->connector);
1385 if (intel_sdvo_conn->left)
1386 UPDATE_PROPERTY(sdvo_state->tv.overscan_h, OVERSCAN_H);
1388 if (intel_sdvo_conn->top)
1389 UPDATE_PROPERTY(sdvo_state->tv.overscan_v, OVERSCAN_V);
1391 if (intel_sdvo_conn->hpos)
1392 UPDATE_PROPERTY(sdvo_state->tv.hpos, HPOS);
1394 if (intel_sdvo_conn->vpos)
1395 UPDATE_PROPERTY(sdvo_state->tv.vpos, VPOS);
1397 if (intel_sdvo_conn->saturation)
1398 UPDATE_PROPERTY(conn_state->tv.saturation, SATURATION);
1400 if (intel_sdvo_conn->contrast)
1401 UPDATE_PROPERTY(conn_state->tv.contrast, CONTRAST);
1403 if (intel_sdvo_conn->hue)
1404 UPDATE_PROPERTY(conn_state->tv.hue, HUE);
1406 if (intel_sdvo_conn->brightness)
1407 UPDATE_PROPERTY(conn_state->tv.brightness, BRIGHTNESS);
1409 if (intel_sdvo_conn->sharpness)
1410 UPDATE_PROPERTY(sdvo_state->tv.sharpness, SHARPNESS);
1412 if (intel_sdvo_conn->flicker_filter)
1413 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter, FLICKER_FILTER);
1415 if (intel_sdvo_conn->flicker_filter_2d)
1416 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_2d, FLICKER_FILTER_2D);
1418 if (intel_sdvo_conn->flicker_filter_adaptive)
1419 UPDATE_PROPERTY(sdvo_state->tv.flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
1421 if (intel_sdvo_conn->tv_chroma_filter)
1422 UPDATE_PROPERTY(sdvo_state->tv.chroma_filter, TV_CHROMA_FILTER);
1424 if (intel_sdvo_conn->tv_luma_filter)
1425 UPDATE_PROPERTY(sdvo_state->tv.luma_filter, TV_LUMA_FILTER);
1427 if (intel_sdvo_conn->dot_crawl)
1428 UPDATE_PROPERTY(sdvo_state->tv.dot_crawl, DOT_CRAWL);
1430 #undef UPDATE_PROPERTY
1433 static void intel_sdvo_pre_enable(struct intel_atomic_state *state,
1434 struct intel_encoder *intel_encoder,
1435 const struct intel_crtc_state *crtc_state,
1436 const struct drm_connector_state *conn_state)
1438 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
1439 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1440 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
1441 const struct intel_sdvo_connector_state *sdvo_state =
1442 to_intel_sdvo_connector_state(conn_state);
1443 const struct intel_sdvo_connector *intel_sdvo_connector =
1444 to_intel_sdvo_connector(conn_state->connector);
1445 const struct drm_display_mode *mode = &crtc_state->hw.mode;
1446 struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
1448 struct intel_sdvo_in_out_map in_out;
1449 struct intel_sdvo_dtd input_dtd, output_dtd;
1452 intel_sdvo_update_props(intel_sdvo, sdvo_state);
1455 * First, set the input mapping for the first input to our controlled
1456 * output. This is only correct if we're a single-input device, in
1457 * which case the first input is the output from the appropriate SDVO
1458 * channel on the motherboard. In a two-input device, the first input
1459 * will be SDVOB and the second SDVOC.
1461 in_out.in0 = intel_sdvo->attached_output;
1464 intel_sdvo_set_value(intel_sdvo,
1465 SDVO_CMD_SET_IN_OUT_MAP,
1466 &in_out, sizeof(in_out));
1468 /* Set the output timings to the screen */
1469 if (!intel_sdvo_set_target_output(intel_sdvo,
1470 intel_sdvo->attached_output))
1473 /* lvds has a special fixed output timing. */
1474 if (IS_LVDS(intel_sdvo_connector))
1475 intel_sdvo_get_dtd_from_mode(&output_dtd,
1476 intel_sdvo_connector->base.panel.fixed_mode);
1478 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1479 if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1480 drm_info(&dev_priv->drm,
1481 "Setting output timings on %s failed\n",
1482 SDVO_NAME(intel_sdvo));
1484 /* Set the input timing to the screen. Assume always input 0. */
1485 if (!intel_sdvo_set_target_input(intel_sdvo))
1488 if (crtc_state->has_hdmi_sink) {
1489 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
1490 intel_sdvo_set_colorimetry(intel_sdvo,
1491 SDVO_COLORIMETRY_RGB256);
1492 intel_sdvo_set_avi_infoframe(intel_sdvo, crtc_state);
1494 intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
1496 if (IS_TV(intel_sdvo_connector) &&
1497 !intel_sdvo_set_tv_format(intel_sdvo, conn_state))
1500 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1502 if (IS_TV(intel_sdvo_connector) || IS_LVDS(intel_sdvo_connector))
1503 input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1504 if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1505 drm_info(&dev_priv->drm,
1506 "Setting input timings on %s failed\n",
1507 SDVO_NAME(intel_sdvo));
1509 switch (crtc_state->pixel_multiplier) {
1511 drm_WARN(&dev_priv->drm, 1,
1512 "unknown pixel multiplier specified\n");
1514 case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1515 case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1516 case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1518 if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1521 /* Set the SDVO control regs. */
1522 if (INTEL_GEN(dev_priv) >= 4) {
1523 /* The real mode polarity is set by the SDVO commands, using
1524 * struct intel_sdvo_dtd. */
1525 sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
1526 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
1527 sdvox |= HDMI_COLOR_RANGE_16_235;
1528 if (INTEL_GEN(dev_priv) < 5)
1529 sdvox |= SDVO_BORDER_ENABLE;
1531 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1532 if (intel_sdvo->port == PORT_B)
1533 sdvox &= SDVOB_PRESERVE_MASK;
1535 sdvox &= SDVOC_PRESERVE_MASK;
1536 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1539 if (HAS_PCH_CPT(dev_priv))
1540 sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
1542 sdvox |= SDVO_PIPE_SEL(crtc->pipe);
1544 if (INTEL_GEN(dev_priv) >= 4) {
1545 /* done in crtc_mode_set as the dpll_md reg must be written early */
1546 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
1547 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
1548 /* done in crtc_mode_set as it lives inside the dpll register */
1550 sdvox |= (crtc_state->pixel_multiplier - 1)
1551 << SDVO_PORT_MULTIPLY_SHIFT;
1554 if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
1555 INTEL_GEN(dev_priv) < 5)
1556 sdvox |= SDVO_STALL_SELECT;
1557 intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1560 static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1562 struct intel_sdvo_connector *intel_sdvo_connector =
1563 to_intel_sdvo_connector(&connector->base);
1564 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1565 u16 active_outputs = 0;
1567 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1569 return active_outputs & intel_sdvo_connector->output_flag;
1572 bool intel_sdvo_port_enabled(struct drm_i915_private *dev_priv,
1573 i915_reg_t sdvo_reg, enum pipe *pipe)
1577 val = intel_de_read(dev_priv, sdvo_reg);
1579 /* asserts want to know the pipe even if the port is disabled */
1580 if (HAS_PCH_CPT(dev_priv))
1581 *pipe = (val & SDVO_PIPE_SEL_MASK_CPT) >> SDVO_PIPE_SEL_SHIFT_CPT;
1582 else if (IS_CHERRYVIEW(dev_priv))
1583 *pipe = (val & SDVO_PIPE_SEL_MASK_CHV) >> SDVO_PIPE_SEL_SHIFT_CHV;
1585 *pipe = (val & SDVO_PIPE_SEL_MASK) >> SDVO_PIPE_SEL_SHIFT;
1587 return val & SDVO_ENABLE;
1590 static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1593 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1594 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1595 u16 active_outputs = 0;
1598 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1600 ret = intel_sdvo_port_enabled(dev_priv, intel_sdvo->sdvo_reg, pipe);
1602 return ret || active_outputs;
1605 static void intel_sdvo_get_config(struct intel_encoder *encoder,
1606 struct intel_crtc_state *pipe_config)
1608 struct drm_device *dev = encoder->base.dev;
1609 struct drm_i915_private *dev_priv = to_i915(dev);
1610 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1611 struct intel_sdvo_dtd dtd;
1612 int encoder_pixel_multiplier = 0;
1614 u32 flags = 0, sdvox;
1618 pipe_config->output_types |= BIT(INTEL_OUTPUT_SDVO);
1620 sdvox = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1622 ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
1625 * Some sdvo encoders are not spec compliant and don't
1626 * implement the mandatory get_timings function.
1628 drm_dbg(&dev_priv->drm, "failed to retrieve SDVO DTD\n");
1629 pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
1631 if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1632 flags |= DRM_MODE_FLAG_PHSYNC;
1634 flags |= DRM_MODE_FLAG_NHSYNC;
1636 if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1637 flags |= DRM_MODE_FLAG_PVSYNC;
1639 flags |= DRM_MODE_FLAG_NVSYNC;
1642 pipe_config->hw.adjusted_mode.flags |= flags;
1645 * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1646 * the sdvo port register, on all other platforms it is part of the dpll
1647 * state. Since the general pipe state readout happens before the
1648 * encoder->get_config we so already have a valid pixel multplier on all
1651 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
1652 pipe_config->pixel_multiplier =
1653 ((sdvox & SDVO_PORT_MULTIPLY_MASK)
1654 >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
1657 dotclock = pipe_config->port_clock;
1659 if (pipe_config->pixel_multiplier)
1660 dotclock /= pipe_config->pixel_multiplier;
1662 pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
1664 /* Cross check the port pixel multiplier with the sdvo encoder state. */
1665 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
1668 case SDVO_CLOCK_RATE_MULT_1X:
1669 encoder_pixel_multiplier = 1;
1671 case SDVO_CLOCK_RATE_MULT_2X:
1672 encoder_pixel_multiplier = 2;
1674 case SDVO_CLOCK_RATE_MULT_4X:
1675 encoder_pixel_multiplier = 4;
1681 encoder_pixel_multiplier != pipe_config->pixel_multiplier,
1682 "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1683 pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1685 if (sdvox & HDMI_COLOR_RANGE_16_235)
1686 pipe_config->limited_color_range = true;
1688 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_AUDIO_STAT,
1690 u8 mask = SDVO_AUDIO_ELD_VALID | SDVO_AUDIO_PRESENCE_DETECT;
1692 if ((val & mask) == mask)
1693 pipe_config->has_audio = true;
1696 if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE,
1698 if (val == SDVO_ENCODE_HDMI)
1699 pipe_config->has_hdmi_sink = true;
1702 intel_sdvo_get_avi_infoframe(intel_sdvo, pipe_config);
1705 static void intel_sdvo_disable_audio(struct intel_sdvo *intel_sdvo)
1707 intel_sdvo_set_audio_state(intel_sdvo, 0);
1710 static void intel_sdvo_enable_audio(struct intel_sdvo *intel_sdvo,
1711 const struct intel_crtc_state *crtc_state,
1712 const struct drm_connector_state *conn_state)
1714 const struct drm_display_mode *adjusted_mode =
1715 &crtc_state->hw.adjusted_mode;
1716 struct drm_connector *connector = conn_state->connector;
1717 u8 *eld = connector->eld;
1719 eld[6] = drm_av_sync_delay(connector, adjusted_mode) / 2;
1721 intel_sdvo_set_audio_state(intel_sdvo, 0);
1723 intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_ELD,
1724 SDVO_HBUF_TX_DISABLED,
1725 eld, drm_eld_size(eld));
1727 intel_sdvo_set_audio_state(intel_sdvo, SDVO_AUDIO_ELD_VALID |
1728 SDVO_AUDIO_PRESENCE_DETECT);
1731 static void intel_disable_sdvo(struct intel_atomic_state *state,
1732 struct intel_encoder *encoder,
1733 const struct intel_crtc_state *old_crtc_state,
1734 const struct drm_connector_state *conn_state)
1736 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1737 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1738 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1741 if (old_crtc_state->has_audio)
1742 intel_sdvo_disable_audio(intel_sdvo);
1744 intel_sdvo_set_active_outputs(intel_sdvo, 0);
1746 intel_sdvo_set_encoder_power_state(intel_sdvo,
1749 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1751 temp &= ~SDVO_ENABLE;
1752 intel_sdvo_write_sdvox(intel_sdvo, temp);
1755 * HW workaround for IBX, we need to move the port
1756 * to transcoder A after disabling it to allow the
1757 * matching DP port to be enabled on transcoder A.
1759 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
1761 * We get CPU/PCH FIFO underruns on the other pipe when
1762 * doing the workaround. Sweep them under the rug.
1764 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1765 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1767 temp &= ~SDVO_PIPE_SEL_MASK;
1768 temp |= SDVO_ENABLE | SDVO_PIPE_SEL(PIPE_A);
1769 intel_sdvo_write_sdvox(intel_sdvo, temp);
1771 temp &= ~SDVO_ENABLE;
1772 intel_sdvo_write_sdvox(intel_sdvo, temp);
1774 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
1775 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1776 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1780 static void pch_disable_sdvo(struct intel_atomic_state *state,
1781 struct intel_encoder *encoder,
1782 const struct intel_crtc_state *old_crtc_state,
1783 const struct drm_connector_state *old_conn_state)
1787 static void pch_post_disable_sdvo(struct intel_atomic_state *state,
1788 struct intel_encoder *encoder,
1789 const struct intel_crtc_state *old_crtc_state,
1790 const struct drm_connector_state *old_conn_state)
1792 intel_disable_sdvo(state, encoder, old_crtc_state, old_conn_state);
1795 static void intel_enable_sdvo(struct intel_atomic_state *state,
1796 struct intel_encoder *encoder,
1797 const struct intel_crtc_state *pipe_config,
1798 const struct drm_connector_state *conn_state)
1800 struct drm_device *dev = encoder->base.dev;
1801 struct drm_i915_private *dev_priv = to_i915(dev);
1802 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1803 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
1805 bool input1, input2;
1809 temp = intel_de_read(dev_priv, intel_sdvo->sdvo_reg);
1810 temp |= SDVO_ENABLE;
1811 intel_sdvo_write_sdvox(intel_sdvo, temp);
1813 for (i = 0; i < 2; i++)
1814 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
1816 success = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1818 * Warn if the device reported failure to sync.
1820 * A lot of SDVO devices fail to notify of sync, but it's
1821 * a given it the status is a success, we succeeded.
1823 if (success && !input1) {
1824 drm_dbg_kms(&dev_priv->drm,
1825 "First %s output reported failure to "
1826 "sync\n", SDVO_NAME(intel_sdvo));
1830 intel_sdvo_set_encoder_power_state(intel_sdvo,
1832 intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1834 if (pipe_config->has_audio)
1835 intel_sdvo_enable_audio(intel_sdvo, pipe_config, conn_state);
1838 static enum drm_mode_status
1839 intel_sdvo_mode_valid(struct drm_connector *connector,
1840 struct drm_display_mode *mode)
1842 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
1843 struct intel_sdvo_connector *intel_sdvo_connector =
1844 to_intel_sdvo_connector(connector);
1845 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
1847 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1848 return MODE_NO_DBLESCAN;
1850 if (intel_sdvo->pixel_clock_min > mode->clock)
1851 return MODE_CLOCK_LOW;
1853 if (intel_sdvo->pixel_clock_max < mode->clock)
1854 return MODE_CLOCK_HIGH;
1856 if (mode->clock > max_dotclk)
1857 return MODE_CLOCK_HIGH;
1859 if (IS_LVDS(intel_sdvo_connector)) {
1860 const struct drm_display_mode *fixed_mode =
1861 intel_sdvo_connector->base.panel.fixed_mode;
1863 if (mode->hdisplay > fixed_mode->hdisplay)
1866 if (mode->vdisplay > fixed_mode->vdisplay)
1873 static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1875 BUILD_BUG_ON(sizeof(*caps) != 8);
1876 if (!intel_sdvo_get_value(intel_sdvo,
1877 SDVO_CMD_GET_DEVICE_CAPS,
1878 caps, sizeof(*caps)))
1881 DRM_DEBUG_KMS("SDVO capabilities:\n"
1884 " device_rev_id: %d\n"
1885 " sdvo_version_major: %d\n"
1886 " sdvo_version_minor: %d\n"
1887 " sdvo_inputs_mask: %d\n"
1888 " smooth_scaling: %d\n"
1889 " sharp_scaling: %d\n"
1891 " down_scaling: %d\n"
1892 " stall_support: %d\n"
1893 " output_flags: %d\n",
1896 caps->device_rev_id,
1897 caps->sdvo_version_major,
1898 caps->sdvo_version_minor,
1899 caps->sdvo_inputs_mask,
1900 caps->smooth_scaling,
1901 caps->sharp_scaling,
1904 caps->stall_support,
1905 caps->output_flags);
1910 static u16 intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1912 struct drm_i915_private *dev_priv = to_i915(intel_sdvo->base.base.dev);
1915 if (!I915_HAS_HOTPLUG(dev_priv))
1919 * HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1922 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
1925 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1926 &hotplug, sizeof(hotplug)))
1932 static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1934 struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
1936 intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
1937 &intel_sdvo->hotplug_active, 2);
1940 static enum intel_hotplug_state
1941 intel_sdvo_hotplug(struct intel_encoder *encoder,
1942 struct intel_connector *connector)
1944 intel_sdvo_enable_hotplug(encoder);
1946 return intel_encoder_hotplug(encoder, connector);
1950 intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
1952 /* Is there more than one type of output? */
1953 return hweight16(intel_sdvo->caps.output_flags) > 1;
1956 static struct edid *
1957 intel_sdvo_get_edid(struct drm_connector *connector)
1959 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
1960 return drm_get_edid(connector, &sdvo->ddc);
1963 /* Mac mini hack -- use the same DDC as the analog connector */
1964 static struct edid *
1965 intel_sdvo_get_analog_edid(struct drm_connector *connector)
1967 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1969 return drm_get_edid(connector,
1970 intel_gmbus_get_adapter(dev_priv,
1971 dev_priv->vbt.crt_ddc_pin));
1974 static enum drm_connector_status
1975 intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
1977 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
1978 struct intel_sdvo_connector *intel_sdvo_connector =
1979 to_intel_sdvo_connector(connector);
1980 enum drm_connector_status status;
1983 edid = intel_sdvo_get_edid(connector);
1985 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
1986 u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
1989 * Don't use the 1 as the argument of DDC bus switch to get
1990 * the EDID. It is used for SDVO SPD ROM.
1992 for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
1993 intel_sdvo->ddc_bus = ddc;
1994 edid = intel_sdvo_get_edid(connector);
1999 * If we found the EDID on the other bus,
2000 * assume that is the correct DDC bus.
2003 intel_sdvo->ddc_bus = saved_ddc;
2007 * When there is no edid and no monitor is connected with VGA
2008 * port, try to use the CRT ddc to read the EDID for DVI-connector.
2011 edid = intel_sdvo_get_analog_edid(connector);
2013 status = connector_status_unknown;
2015 /* DDC bus is shared, match EDID to connector type */
2016 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
2017 status = connector_status_connected;
2018 if (intel_sdvo_connector->is_hdmi) {
2019 intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
2020 intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
2023 status = connector_status_disconnected;
2031 intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
2034 bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
2035 bool connector_is_digital = !!IS_DIGITAL(sdvo);
2037 DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
2038 connector_is_digital, monitor_is_digital);
2039 return connector_is_digital == monitor_is_digital;
2042 static enum drm_connector_status
2043 intel_sdvo_detect(struct drm_connector *connector, bool force)
2046 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2047 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2048 enum drm_connector_status ret;
2050 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2051 connector->base.id, connector->name);
2053 if (!intel_sdvo_get_value(intel_sdvo,
2054 SDVO_CMD_GET_ATTACHED_DISPLAYS,
2056 return connector_status_unknown;
2058 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
2059 response & 0xff, response >> 8,
2060 intel_sdvo_connector->output_flag);
2063 return connector_status_disconnected;
2065 intel_sdvo->attached_output = response;
2067 intel_sdvo->has_hdmi_monitor = false;
2068 intel_sdvo->has_hdmi_audio = false;
2070 if ((intel_sdvo_connector->output_flag & response) == 0)
2071 ret = connector_status_disconnected;
2072 else if (IS_TMDS(intel_sdvo_connector))
2073 ret = intel_sdvo_tmds_sink_detect(connector);
2077 /* if we have an edid check it matches the connection */
2078 edid = intel_sdvo_get_edid(connector);
2080 edid = intel_sdvo_get_analog_edid(connector);
2082 if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
2084 ret = connector_status_connected;
2086 ret = connector_status_disconnected;
2090 ret = connector_status_connected;
2096 static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
2100 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2101 connector->base.id, connector->name);
2103 /* set the bus switch and get the modes */
2104 edid = intel_sdvo_get_edid(connector);
2107 * Mac mini hack. On this device, the DVI-I connector shares one DDC
2108 * link between analog and digital outputs. So, if the regular SDVO
2109 * DDC fails, check to see if the analog output is disconnected, in
2110 * which case we'll look there for the digital DDC data.
2113 edid = intel_sdvo_get_analog_edid(connector);
2116 if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
2118 drm_connector_update_edid_property(connector, edid);
2119 drm_add_edid_modes(connector, edid);
2127 * Set of SDVO TV modes.
2128 * Note! This is in reply order (see loop in get_tv_modes).
2129 * XXX: all 60Hz refresh?
2131 static const struct drm_display_mode sdvo_tv_modes[] = {
2132 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
2133 416, 0, 200, 201, 232, 233, 0,
2134 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2135 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
2136 416, 0, 240, 241, 272, 273, 0,
2137 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2138 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
2139 496, 0, 300, 301, 332, 333, 0,
2140 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2141 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
2142 736, 0, 350, 351, 382, 383, 0,
2143 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2144 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
2145 736, 0, 400, 401, 432, 433, 0,
2146 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2147 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
2148 736, 0, 480, 481, 512, 513, 0,
2149 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2150 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
2151 800, 0, 480, 481, 512, 513, 0,
2152 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2153 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
2154 800, 0, 576, 577, 608, 609, 0,
2155 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2156 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
2157 816, 0, 350, 351, 382, 383, 0,
2158 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2159 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
2160 816, 0, 400, 401, 432, 433, 0,
2161 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2162 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
2163 816, 0, 480, 481, 512, 513, 0,
2164 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2165 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
2166 816, 0, 540, 541, 572, 573, 0,
2167 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2168 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
2169 816, 0, 576, 577, 608, 609, 0,
2170 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2171 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
2172 864, 0, 576, 577, 608, 609, 0,
2173 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2174 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
2175 896, 0, 600, 601, 632, 633, 0,
2176 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2177 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
2178 928, 0, 624, 625, 656, 657, 0,
2179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2180 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
2181 1016, 0, 766, 767, 798, 799, 0,
2182 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2183 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
2184 1120, 0, 768, 769, 800, 801, 0,
2185 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2186 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
2187 1376, 0, 1024, 1025, 1056, 1057, 0,
2188 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
2191 static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
2193 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2194 const struct drm_connector_state *conn_state = connector->state;
2195 struct intel_sdvo_sdtv_resolution_request tv_res;
2196 u32 reply = 0, format_map = 0;
2199 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2200 connector->base.id, connector->name);
2203 * Read the list of supported input resolutions for the selected TV
2206 format_map = 1 << conn_state->tv.mode;
2207 memcpy(&tv_res, &format_map,
2208 min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
2210 if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
2213 BUILD_BUG_ON(sizeof(tv_res) != 3);
2214 if (!intel_sdvo_write_cmd(intel_sdvo,
2215 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
2216 &tv_res, sizeof(tv_res)))
2218 if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
2221 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
2222 if (reply & (1 << i)) {
2223 struct drm_display_mode *nmode;
2224 nmode = drm_mode_duplicate(connector->dev,
2227 drm_mode_probed_add(connector, nmode);
2231 static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
2233 struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector));
2234 struct drm_i915_private *dev_priv = to_i915(connector->dev);
2235 struct drm_display_mode *newmode;
2237 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s]\n",
2238 connector->base.id, connector->name);
2241 * Fetch modes from VBT. For SDVO prefer the VBT mode since some
2242 * SDVO->LVDS transcoders can't cope with the EDID mode.
2244 if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
2245 newmode = drm_mode_duplicate(connector->dev,
2246 dev_priv->vbt.sdvo_lvds_vbt_mode);
2247 if (newmode != NULL) {
2248 /* Guarantee the mode is preferred */
2249 newmode->type = (DRM_MODE_TYPE_PREFERRED |
2250 DRM_MODE_TYPE_DRIVER);
2251 drm_mode_probed_add(connector, newmode);
2256 * Attempt to get the mode list from DDC.
2257 * Assume that the preferred modes are
2258 * arranged in priority order.
2260 intel_ddc_get_modes(connector, &intel_sdvo->ddc);
2263 static int intel_sdvo_get_modes(struct drm_connector *connector)
2265 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2267 if (IS_TV(intel_sdvo_connector))
2268 intel_sdvo_get_tv_modes(connector);
2269 else if (IS_LVDS(intel_sdvo_connector))
2270 intel_sdvo_get_lvds_modes(connector);
2272 intel_sdvo_get_ddc_modes(connector);
2274 return !list_empty(&connector->probed_modes);
2278 intel_sdvo_connector_atomic_get_property(struct drm_connector *connector,
2279 const struct drm_connector_state *state,
2280 struct drm_property *property,
2283 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2284 const struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state((void *)state);
2286 if (property == intel_sdvo_connector->tv_format) {
2289 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2290 if (state->tv.mode == intel_sdvo_connector->tv_format_supported[i]) {
2298 } else if (property == intel_sdvo_connector->top ||
2299 property == intel_sdvo_connector->bottom)
2300 *val = intel_sdvo_connector->max_vscan - sdvo_state->tv.overscan_v;
2301 else if (property == intel_sdvo_connector->left ||
2302 property == intel_sdvo_connector->right)
2303 *val = intel_sdvo_connector->max_hscan - sdvo_state->tv.overscan_h;
2304 else if (property == intel_sdvo_connector->hpos)
2305 *val = sdvo_state->tv.hpos;
2306 else if (property == intel_sdvo_connector->vpos)
2307 *val = sdvo_state->tv.vpos;
2308 else if (property == intel_sdvo_connector->saturation)
2309 *val = state->tv.saturation;
2310 else if (property == intel_sdvo_connector->contrast)
2311 *val = state->tv.contrast;
2312 else if (property == intel_sdvo_connector->hue)
2313 *val = state->tv.hue;
2314 else if (property == intel_sdvo_connector->brightness)
2315 *val = state->tv.brightness;
2316 else if (property == intel_sdvo_connector->sharpness)
2317 *val = sdvo_state->tv.sharpness;
2318 else if (property == intel_sdvo_connector->flicker_filter)
2319 *val = sdvo_state->tv.flicker_filter;
2320 else if (property == intel_sdvo_connector->flicker_filter_2d)
2321 *val = sdvo_state->tv.flicker_filter_2d;
2322 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2323 *val = sdvo_state->tv.flicker_filter_adaptive;
2324 else if (property == intel_sdvo_connector->tv_chroma_filter)
2325 *val = sdvo_state->tv.chroma_filter;
2326 else if (property == intel_sdvo_connector->tv_luma_filter)
2327 *val = sdvo_state->tv.luma_filter;
2328 else if (property == intel_sdvo_connector->dot_crawl)
2329 *val = sdvo_state->tv.dot_crawl;
2331 return intel_digital_connector_atomic_get_property(connector, state, property, val);
2337 intel_sdvo_connector_atomic_set_property(struct drm_connector *connector,
2338 struct drm_connector_state *state,
2339 struct drm_property *property,
2342 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
2343 struct intel_sdvo_connector_state *sdvo_state = to_intel_sdvo_connector_state(state);
2345 if (property == intel_sdvo_connector->tv_format) {
2346 state->tv.mode = intel_sdvo_connector->tv_format_supported[val];
2349 struct drm_crtc_state *crtc_state =
2350 drm_atomic_get_new_crtc_state(state->state, state->crtc);
2352 crtc_state->connectors_changed = true;
2354 } else if (property == intel_sdvo_connector->top ||
2355 property == intel_sdvo_connector->bottom)
2356 /* Cannot set these independent from each other */
2357 sdvo_state->tv.overscan_v = intel_sdvo_connector->max_vscan - val;
2358 else if (property == intel_sdvo_connector->left ||
2359 property == intel_sdvo_connector->right)
2360 /* Cannot set these independent from each other */
2361 sdvo_state->tv.overscan_h = intel_sdvo_connector->max_hscan - val;
2362 else if (property == intel_sdvo_connector->hpos)
2363 sdvo_state->tv.hpos = val;
2364 else if (property == intel_sdvo_connector->vpos)
2365 sdvo_state->tv.vpos = val;
2366 else if (property == intel_sdvo_connector->saturation)
2367 state->tv.saturation = val;
2368 else if (property == intel_sdvo_connector->contrast)
2369 state->tv.contrast = val;
2370 else if (property == intel_sdvo_connector->hue)
2371 state->tv.hue = val;
2372 else if (property == intel_sdvo_connector->brightness)
2373 state->tv.brightness = val;
2374 else if (property == intel_sdvo_connector->sharpness)
2375 sdvo_state->tv.sharpness = val;
2376 else if (property == intel_sdvo_connector->flicker_filter)
2377 sdvo_state->tv.flicker_filter = val;
2378 else if (property == intel_sdvo_connector->flicker_filter_2d)
2379 sdvo_state->tv.flicker_filter_2d = val;
2380 else if (property == intel_sdvo_connector->flicker_filter_adaptive)
2381 sdvo_state->tv.flicker_filter_adaptive = val;
2382 else if (property == intel_sdvo_connector->tv_chroma_filter)
2383 sdvo_state->tv.chroma_filter = val;
2384 else if (property == intel_sdvo_connector->tv_luma_filter)
2385 sdvo_state->tv.luma_filter = val;
2386 else if (property == intel_sdvo_connector->dot_crawl)
2387 sdvo_state->tv.dot_crawl = val;
2389 return intel_digital_connector_atomic_set_property(connector, state, property, val);
2395 intel_sdvo_connector_register(struct drm_connector *connector)
2397 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2400 ret = intel_connector_register(connector);
2404 return sysfs_create_link(&connector->kdev->kobj,
2405 &sdvo->ddc.dev.kobj,
2406 sdvo->ddc.dev.kobj.name);
2410 intel_sdvo_connector_unregister(struct drm_connector *connector)
2412 struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector));
2414 sysfs_remove_link(&connector->kdev->kobj,
2415 sdvo->ddc.dev.kobj.name);
2416 intel_connector_unregister(connector);
2419 static struct drm_connector_state *
2420 intel_sdvo_connector_duplicate_state(struct drm_connector *connector)
2422 struct intel_sdvo_connector_state *state;
2424 state = kmemdup(connector->state, sizeof(*state), GFP_KERNEL);
2428 __drm_atomic_helper_connector_duplicate_state(connector, &state->base.base);
2429 return &state->base.base;
2432 static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
2433 .detect = intel_sdvo_detect,
2434 .fill_modes = drm_helper_probe_single_connector_modes,
2435 .atomic_get_property = intel_sdvo_connector_atomic_get_property,
2436 .atomic_set_property = intel_sdvo_connector_atomic_set_property,
2437 .late_register = intel_sdvo_connector_register,
2438 .early_unregister = intel_sdvo_connector_unregister,
2439 .destroy = intel_connector_destroy,
2440 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
2441 .atomic_duplicate_state = intel_sdvo_connector_duplicate_state,
2444 static int intel_sdvo_atomic_check(struct drm_connector *conn,
2445 struct drm_atomic_state *state)
2447 struct drm_connector_state *new_conn_state =
2448 drm_atomic_get_new_connector_state(state, conn);
2449 struct drm_connector_state *old_conn_state =
2450 drm_atomic_get_old_connector_state(state, conn);
2451 struct intel_sdvo_connector_state *old_state =
2452 to_intel_sdvo_connector_state(old_conn_state);
2453 struct intel_sdvo_connector_state *new_state =
2454 to_intel_sdvo_connector_state(new_conn_state);
2456 if (new_conn_state->crtc &&
2457 (memcmp(&old_state->tv, &new_state->tv, sizeof(old_state->tv)) ||
2458 memcmp(&old_conn_state->tv, &new_conn_state->tv, sizeof(old_conn_state->tv)))) {
2459 struct drm_crtc_state *crtc_state =
2460 drm_atomic_get_new_crtc_state(state,
2461 new_conn_state->crtc);
2463 crtc_state->connectors_changed = true;
2466 return intel_digital_connector_atomic_check(conn, state);
2469 static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2470 .get_modes = intel_sdvo_get_modes,
2471 .mode_valid = intel_sdvo_mode_valid,
2472 .atomic_check = intel_sdvo_atomic_check,
2475 static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
2477 struct intel_sdvo *intel_sdvo = to_sdvo(to_intel_encoder(encoder));
2479 i2c_del_adapter(&intel_sdvo->ddc);
2480 intel_encoder_destroy(encoder);
2483 static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2484 .destroy = intel_sdvo_enc_destroy,
2488 intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
2491 unsigned int num_bits;
2494 * Make a mask of outputs less than or equal to our own priority in the
2497 switch (sdvo->controlled_output) {
2498 case SDVO_OUTPUT_LVDS1:
2499 mask |= SDVO_OUTPUT_LVDS1;
2501 case SDVO_OUTPUT_LVDS0:
2502 mask |= SDVO_OUTPUT_LVDS0;
2504 case SDVO_OUTPUT_TMDS1:
2505 mask |= SDVO_OUTPUT_TMDS1;
2507 case SDVO_OUTPUT_TMDS0:
2508 mask |= SDVO_OUTPUT_TMDS0;
2510 case SDVO_OUTPUT_RGB1:
2511 mask |= SDVO_OUTPUT_RGB1;
2513 case SDVO_OUTPUT_RGB0:
2514 mask |= SDVO_OUTPUT_RGB0;
2518 /* Count bits to find what number we are in the priority list. */
2519 mask &= sdvo->caps.output_flags;
2520 num_bits = hweight16(mask);
2521 /* If more than 3 outputs, default to DDC bus 3 for now. */
2525 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2526 sdvo->ddc_bus = 1 << num_bits;
2530 * Choose the appropriate DDC bus for control bus switch command for this
2531 * SDVO output based on the controlled output.
2533 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2534 * outputs, then LVDS outputs.
2537 intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
2538 struct intel_sdvo *sdvo)
2540 struct sdvo_device_mapping *mapping;
2542 if (sdvo->port == PORT_B)
2543 mapping = &dev_priv->vbt.sdvo_mappings[0];
2545 mapping = &dev_priv->vbt.sdvo_mappings[1];
2547 if (mapping->initialized)
2548 sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
2550 intel_sdvo_guess_ddc_bus(sdvo);
2554 intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
2555 struct intel_sdvo *sdvo)
2557 struct sdvo_device_mapping *mapping;
2560 if (sdvo->port == PORT_B)
2561 mapping = &dev_priv->vbt.sdvo_mappings[0];
2563 mapping = &dev_priv->vbt.sdvo_mappings[1];
2565 if (mapping->initialized &&
2566 intel_gmbus_is_valid_pin(dev_priv, mapping->i2c_pin))
2567 pin = mapping->i2c_pin;
2569 pin = GMBUS_PIN_DPB;
2571 sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
2574 * With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
2575 * our code totally fails once we start using gmbus. Hence fall back to
2576 * bit banging for now.
2578 intel_gmbus_force_bit(sdvo->i2c, true);
2581 /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
2583 intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
2585 intel_gmbus_force_bit(sdvo->i2c, false);
2589 intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)
2591 return intel_sdvo_check_supp_encode(intel_sdvo);
2595 intel_sdvo_get_slave_addr(struct drm_i915_private *dev_priv,
2596 struct intel_sdvo *sdvo)
2598 struct sdvo_device_mapping *my_mapping, *other_mapping;
2600 if (sdvo->port == PORT_B) {
2601 my_mapping = &dev_priv->vbt.sdvo_mappings[0];
2602 other_mapping = &dev_priv->vbt.sdvo_mappings[1];
2604 my_mapping = &dev_priv->vbt.sdvo_mappings[1];
2605 other_mapping = &dev_priv->vbt.sdvo_mappings[0];
2608 /* If the BIOS described our SDVO device, take advantage of it. */
2609 if (my_mapping->slave_addr)
2610 return my_mapping->slave_addr;
2613 * If the BIOS only described a different SDVO device, use the
2614 * address that it isn't using.
2616 if (other_mapping->slave_addr) {
2617 if (other_mapping->slave_addr == 0x70)
2624 * No SDVO device info is found for another DVO port,
2625 * so use mapping assumption we had before BIOS parsing.
2627 if (sdvo->port == PORT_B)
2634 intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2635 struct intel_sdvo *encoder)
2637 struct drm_connector *drm_connector;
2640 drm_connector = &connector->base.base;
2641 ret = drm_connector_init(encoder->base.base.dev,
2643 &intel_sdvo_connector_funcs,
2644 connector->base.base.connector_type);
2648 drm_connector_helper_add(drm_connector,
2649 &intel_sdvo_connector_helper_funcs);
2651 connector->base.base.interlace_allowed = 1;
2652 connector->base.base.doublescan_allowed = 0;
2653 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2654 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2656 intel_connector_attach_encoder(&connector->base, &encoder->base);
2662 intel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
2663 struct intel_sdvo_connector *connector)
2665 struct drm_i915_private *dev_priv = to_i915(connector->base.base.dev);
2667 intel_attach_force_audio_property(&connector->base.base);
2668 if (INTEL_GEN(dev_priv) >= 4 && IS_MOBILE(dev_priv)) {
2669 intel_attach_broadcast_rgb_property(&connector->base.base);
2671 intel_attach_aspect_ratio_property(&connector->base.base);
2674 static struct intel_sdvo_connector *intel_sdvo_connector_alloc(void)
2676 struct intel_sdvo_connector *sdvo_connector;
2677 struct intel_sdvo_connector_state *conn_state;
2679 sdvo_connector = kzalloc(sizeof(*sdvo_connector), GFP_KERNEL);
2680 if (!sdvo_connector)
2683 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
2685 kfree(sdvo_connector);
2689 __drm_atomic_helper_connector_reset(&sdvo_connector->base.base,
2690 &conn_state->base.base);
2692 return sdvo_connector;
2696 intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2698 struct drm_encoder *encoder = &intel_sdvo->base.base;
2699 struct drm_connector *connector;
2700 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2701 struct intel_connector *intel_connector;
2702 struct intel_sdvo_connector *intel_sdvo_connector;
2704 DRM_DEBUG_KMS("initialising DVI device %d\n", device);
2706 intel_sdvo_connector = intel_sdvo_connector_alloc();
2707 if (!intel_sdvo_connector)
2711 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
2712 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2713 } else if (device == 1) {
2714 intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
2715 intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2718 intel_connector = &intel_sdvo_connector->base;
2719 connector = &intel_connector->base;
2720 if (intel_sdvo_get_hotplug_support(intel_sdvo) &
2721 intel_sdvo_connector->output_flag) {
2722 intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
2724 * Some SDVO devices have one-shot hotplug interrupts.
2725 * Ensure that they get re-enabled when an interrupt happens.
2727 intel_connector->polled = DRM_CONNECTOR_POLL_HPD;
2728 intel_encoder->hotplug = intel_sdvo_hotplug;
2729 intel_sdvo_enable_hotplug(intel_encoder);
2731 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2733 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2734 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2736 if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
2737 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2738 intel_sdvo_connector->is_hdmi = true;
2741 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2742 kfree(intel_sdvo_connector);
2746 if (intel_sdvo_connector->is_hdmi)
2747 intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
2753 intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
2755 struct drm_encoder *encoder = &intel_sdvo->base.base;
2756 struct drm_connector *connector;
2757 struct intel_connector *intel_connector;
2758 struct intel_sdvo_connector *intel_sdvo_connector;
2760 DRM_DEBUG_KMS("initialising TV type %d\n", type);
2762 intel_sdvo_connector = intel_sdvo_connector_alloc();
2763 if (!intel_sdvo_connector)
2766 intel_connector = &intel_sdvo_connector->base;
2767 connector = &intel_connector->base;
2768 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2769 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2771 intel_sdvo->controlled_output |= type;
2772 intel_sdvo_connector->output_flag = type;
2774 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2775 kfree(intel_sdvo_connector);
2779 if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
2782 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2788 intel_connector_destroy(connector);
2793 intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
2795 struct drm_encoder *encoder = &intel_sdvo->base.base;
2796 struct drm_connector *connector;
2797 struct intel_connector *intel_connector;
2798 struct intel_sdvo_connector *intel_sdvo_connector;
2800 DRM_DEBUG_KMS("initialising analog device %d\n", device);
2802 intel_sdvo_connector = intel_sdvo_connector_alloc();
2803 if (!intel_sdvo_connector)
2806 intel_connector = &intel_sdvo_connector->base;
2807 connector = &intel_connector->base;
2808 intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2809 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2810 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2813 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
2814 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2815 } else if (device == 1) {
2816 intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
2817 intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2820 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2821 kfree(intel_sdvo_connector);
2829 intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
2831 struct drm_encoder *encoder = &intel_sdvo->base.base;
2832 struct drm_connector *connector;
2833 struct intel_connector *intel_connector;
2834 struct intel_sdvo_connector *intel_sdvo_connector;
2835 struct drm_display_mode *mode;
2837 DRM_DEBUG_KMS("initialising LVDS device %d\n", device);
2839 intel_sdvo_connector = intel_sdvo_connector_alloc();
2840 if (!intel_sdvo_connector)
2843 intel_connector = &intel_sdvo_connector->base;
2844 connector = &intel_connector->base;
2845 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2846 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2849 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
2850 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2851 } else if (device == 1) {
2852 intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
2853 intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2856 if (intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo) < 0) {
2857 kfree(intel_sdvo_connector);
2861 if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
2864 intel_sdvo_get_lvds_modes(connector);
2866 list_for_each_entry(mode, &connector->probed_modes, head) {
2867 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
2868 struct drm_display_mode *fixed_mode =
2869 drm_mode_duplicate(connector->dev, mode);
2871 intel_panel_init(&intel_connector->panel,
2877 if (!intel_connector->panel.fixed_mode)
2883 intel_connector_destroy(connector);
2888 intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, u16 flags)
2890 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2892 if (flags & SDVO_OUTPUT_TMDS0)
2893 if (!intel_sdvo_dvi_init(intel_sdvo, 0))
2896 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2897 if (!intel_sdvo_dvi_init(intel_sdvo, 1))
2900 /* TV has no XXX1 function block */
2901 if (flags & SDVO_OUTPUT_SVID0)
2902 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
2905 if (flags & SDVO_OUTPUT_CVBS0)
2906 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
2909 if (flags & SDVO_OUTPUT_YPRPB0)
2910 if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
2913 if (flags & SDVO_OUTPUT_RGB0)
2914 if (!intel_sdvo_analog_init(intel_sdvo, 0))
2917 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2918 if (!intel_sdvo_analog_init(intel_sdvo, 1))
2921 if (flags & SDVO_OUTPUT_LVDS0)
2922 if (!intel_sdvo_lvds_init(intel_sdvo, 0))
2925 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2926 if (!intel_sdvo_lvds_init(intel_sdvo, 1))
2929 if ((flags & SDVO_OUTPUT_MASK) == 0) {
2930 unsigned char bytes[2];
2932 intel_sdvo->controlled_output = 0;
2933 memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
2934 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2935 SDVO_NAME(intel_sdvo),
2936 bytes[0], bytes[1]);
2939 intel_sdvo->base.pipe_mask = ~0;
2944 static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
2946 struct drm_device *dev = intel_sdvo->base.base.dev;
2947 struct drm_connector *connector, *tmp;
2949 list_for_each_entry_safe(connector, tmp,
2950 &dev->mode_config.connector_list, head) {
2951 if (intel_attached_encoder(to_intel_connector(connector)) == &intel_sdvo->base) {
2952 drm_connector_unregister(connector);
2953 intel_connector_destroy(connector);
2958 static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
2959 struct intel_sdvo_connector *intel_sdvo_connector,
2962 struct drm_device *dev = intel_sdvo->base.base.dev;
2963 struct intel_sdvo_tv_format format;
2966 if (!intel_sdvo_set_target_output(intel_sdvo, type))
2969 BUILD_BUG_ON(sizeof(format) != 6);
2970 if (!intel_sdvo_get_value(intel_sdvo,
2971 SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
2972 &format, sizeof(format)))
2975 memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
2977 if (format_map == 0)
2980 intel_sdvo_connector->format_supported_num = 0;
2981 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2982 if (format_map & (1 << i))
2983 intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
2986 intel_sdvo_connector->tv_format =
2987 drm_property_create(dev, DRM_MODE_PROP_ENUM,
2988 "mode", intel_sdvo_connector->format_supported_num);
2989 if (!intel_sdvo_connector->tv_format)
2992 for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
2993 drm_property_add_enum(intel_sdvo_connector->tv_format, i,
2994 tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
2996 intel_sdvo_connector->base.base.state->tv.mode = intel_sdvo_connector->tv_format_supported[0];
2997 drm_object_attach_property(&intel_sdvo_connector->base.base.base,
2998 intel_sdvo_connector->tv_format, 0);
3003 #define _ENHANCEMENT(state_assignment, name, NAME) do { \
3004 if (enhancements.name) { \
3005 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
3006 !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
3008 intel_sdvo_connector->name = \
3009 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
3010 if (!intel_sdvo_connector->name) return false; \
3011 state_assignment = response; \
3012 drm_object_attach_property(&connector->base, \
3013 intel_sdvo_connector->name, 0); \
3014 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
3015 data_value[0], data_value[1], response); \
3019 #define ENHANCEMENT(state, name, NAME) _ENHANCEMENT((state)->name, name, NAME)
3022 intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
3023 struct intel_sdvo_connector *intel_sdvo_connector,
3024 struct intel_sdvo_enhancements_reply enhancements)
3026 struct drm_device *dev = intel_sdvo->base.base.dev;
3027 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3028 struct drm_connector_state *conn_state = connector->state;
3029 struct intel_sdvo_connector_state *sdvo_state =
3030 to_intel_sdvo_connector_state(conn_state);
3031 u16 response, data_value[2];
3033 /* when horizontal overscan is supported, Add the left/right property */
3034 if (enhancements.overscan_h) {
3035 if (!intel_sdvo_get_value(intel_sdvo,
3036 SDVO_CMD_GET_MAX_OVERSCAN_H,
3040 if (!intel_sdvo_get_value(intel_sdvo,
3041 SDVO_CMD_GET_OVERSCAN_H,
3045 sdvo_state->tv.overscan_h = response;
3047 intel_sdvo_connector->max_hscan = data_value[0];
3048 intel_sdvo_connector->left =
3049 drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
3050 if (!intel_sdvo_connector->left)
3053 drm_object_attach_property(&connector->base,
3054 intel_sdvo_connector->left, 0);
3056 intel_sdvo_connector->right =
3057 drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
3058 if (!intel_sdvo_connector->right)
3061 drm_object_attach_property(&connector->base,
3062 intel_sdvo_connector->right, 0);
3063 DRM_DEBUG_KMS("h_overscan: max %d, "
3064 "default %d, current %d\n",
3065 data_value[0], data_value[1], response);
3068 if (enhancements.overscan_v) {
3069 if (!intel_sdvo_get_value(intel_sdvo,
3070 SDVO_CMD_GET_MAX_OVERSCAN_V,
3074 if (!intel_sdvo_get_value(intel_sdvo,
3075 SDVO_CMD_GET_OVERSCAN_V,
3079 sdvo_state->tv.overscan_v = response;
3081 intel_sdvo_connector->max_vscan = data_value[0];
3082 intel_sdvo_connector->top =
3083 drm_property_create_range(dev, 0,
3084 "top_margin", 0, data_value[0]);
3085 if (!intel_sdvo_connector->top)
3088 drm_object_attach_property(&connector->base,
3089 intel_sdvo_connector->top, 0);
3091 intel_sdvo_connector->bottom =
3092 drm_property_create_range(dev, 0,
3093 "bottom_margin", 0, data_value[0]);
3094 if (!intel_sdvo_connector->bottom)
3097 drm_object_attach_property(&connector->base,
3098 intel_sdvo_connector->bottom, 0);
3099 DRM_DEBUG_KMS("v_overscan: max %d, "
3100 "default %d, current %d\n",
3101 data_value[0], data_value[1], response);
3104 ENHANCEMENT(&sdvo_state->tv, hpos, HPOS);
3105 ENHANCEMENT(&sdvo_state->tv, vpos, VPOS);
3106 ENHANCEMENT(&conn_state->tv, saturation, SATURATION);
3107 ENHANCEMENT(&conn_state->tv, contrast, CONTRAST);
3108 ENHANCEMENT(&conn_state->tv, hue, HUE);
3109 ENHANCEMENT(&conn_state->tv, brightness, BRIGHTNESS);
3110 ENHANCEMENT(&sdvo_state->tv, sharpness, SHARPNESS);
3111 ENHANCEMENT(&sdvo_state->tv, flicker_filter, FLICKER_FILTER);
3112 ENHANCEMENT(&sdvo_state->tv, flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
3113 ENHANCEMENT(&sdvo_state->tv, flicker_filter_2d, FLICKER_FILTER_2D);
3114 _ENHANCEMENT(sdvo_state->tv.chroma_filter, tv_chroma_filter, TV_CHROMA_FILTER);
3115 _ENHANCEMENT(sdvo_state->tv.luma_filter, tv_luma_filter, TV_LUMA_FILTER);
3117 if (enhancements.dot_crawl) {
3118 if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
3121 sdvo_state->tv.dot_crawl = response & 0x1;
3122 intel_sdvo_connector->dot_crawl =
3123 drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
3124 if (!intel_sdvo_connector->dot_crawl)
3127 drm_object_attach_property(&connector->base,
3128 intel_sdvo_connector->dot_crawl, 0);
3129 DRM_DEBUG_KMS("dot crawl: current %d\n", response);
3136 intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
3137 struct intel_sdvo_connector *intel_sdvo_connector,
3138 struct intel_sdvo_enhancements_reply enhancements)
3140 struct drm_device *dev = intel_sdvo->base.base.dev;
3141 struct drm_connector *connector = &intel_sdvo_connector->base.base;
3142 u16 response, data_value[2];
3144 ENHANCEMENT(&connector->state->tv, brightness, BRIGHTNESS);
3151 static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
3152 struct intel_sdvo_connector *intel_sdvo_connector)
3155 struct intel_sdvo_enhancements_reply reply;
3159 BUILD_BUG_ON(sizeof(enhancements) != 2);
3161 if (!intel_sdvo_get_value(intel_sdvo,
3162 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
3163 &enhancements, sizeof(enhancements)) ||
3164 enhancements.response == 0) {
3165 DRM_DEBUG_KMS("No enhancement is supported\n");
3169 if (IS_TV(intel_sdvo_connector))
3170 return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3171 else if (IS_LVDS(intel_sdvo_connector))
3172 return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
3177 static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
3178 struct i2c_msg *msgs,
3181 struct intel_sdvo *sdvo = adapter->algo_data;
3183 if (!__intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
3186 return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
3189 static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
3191 struct intel_sdvo *sdvo = adapter->algo_data;
3192 return sdvo->i2c->algo->functionality(sdvo->i2c);
3195 static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
3196 .master_xfer = intel_sdvo_ddc_proxy_xfer,
3197 .functionality = intel_sdvo_ddc_proxy_func
3200 static void proxy_lock_bus(struct i2c_adapter *adapter,
3203 struct intel_sdvo *sdvo = adapter->algo_data;
3204 sdvo->i2c->lock_ops->lock_bus(sdvo->i2c, flags);
3207 static int proxy_trylock_bus(struct i2c_adapter *adapter,
3210 struct intel_sdvo *sdvo = adapter->algo_data;
3211 return sdvo->i2c->lock_ops->trylock_bus(sdvo->i2c, flags);
3214 static void proxy_unlock_bus(struct i2c_adapter *adapter,
3217 struct intel_sdvo *sdvo = adapter->algo_data;
3218 sdvo->i2c->lock_ops->unlock_bus(sdvo->i2c, flags);
3221 static const struct i2c_lock_operations proxy_lock_ops = {
3222 .lock_bus = proxy_lock_bus,
3223 .trylock_bus = proxy_trylock_bus,
3224 .unlock_bus = proxy_unlock_bus,
3228 intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
3229 struct drm_i915_private *dev_priv)
3231 struct pci_dev *pdev = dev_priv->drm.pdev;
3233 sdvo->ddc.owner = THIS_MODULE;
3234 sdvo->ddc.class = I2C_CLASS_DDC;
3235 snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
3236 sdvo->ddc.dev.parent = &pdev->dev;
3237 sdvo->ddc.algo_data = sdvo;
3238 sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
3239 sdvo->ddc.lock_ops = &proxy_lock_ops;
3241 return i2c_add_adapter(&sdvo->ddc) == 0;
3244 static void assert_sdvo_port_valid(const struct drm_i915_private *dev_priv,
3247 if (HAS_PCH_SPLIT(dev_priv))
3248 drm_WARN_ON(&dev_priv->drm, port != PORT_B);
3250 drm_WARN_ON(&dev_priv->drm, port != PORT_B && port != PORT_C);
3253 bool intel_sdvo_init(struct drm_i915_private *dev_priv,
3254 i915_reg_t sdvo_reg, enum port port)
3256 struct intel_encoder *intel_encoder;
3257 struct intel_sdvo *intel_sdvo;
3260 assert_sdvo_port_valid(dev_priv, port);
3262 intel_sdvo = kzalloc(sizeof(*intel_sdvo), GFP_KERNEL);
3266 intel_sdvo->sdvo_reg = sdvo_reg;
3267 intel_sdvo->port = port;
3268 intel_sdvo->slave_addr =
3269 intel_sdvo_get_slave_addr(dev_priv, intel_sdvo) >> 1;
3270 intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo);
3271 if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev_priv))
3274 /* encoder type will be decided later */
3275 intel_encoder = &intel_sdvo->base;
3276 intel_encoder->type = INTEL_OUTPUT_SDVO;
3277 intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
3278 intel_encoder->port = port;
3279 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
3280 &intel_sdvo_enc_funcs, 0,
3281 "SDVO %c", port_name(port));
3283 /* Read the regs to test if we can talk to the device */
3284 for (i = 0; i < 0x40; i++) {
3287 if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
3288 drm_dbg_kms(&dev_priv->drm,
3289 "No SDVO device found on %s\n",
3290 SDVO_NAME(intel_sdvo));
3295 intel_encoder->compute_config = intel_sdvo_compute_config;
3296 if (HAS_PCH_SPLIT(dev_priv)) {
3297 intel_encoder->disable = pch_disable_sdvo;
3298 intel_encoder->post_disable = pch_post_disable_sdvo;
3300 intel_encoder->disable = intel_disable_sdvo;
3302 intel_encoder->pre_enable = intel_sdvo_pre_enable;
3303 intel_encoder->enable = intel_enable_sdvo;
3304 intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
3305 intel_encoder->get_config = intel_sdvo_get_config;
3307 /* In default case sdvo lvds is false */
3308 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
3311 if (intel_sdvo_output_setup(intel_sdvo,
3312 intel_sdvo->caps.output_flags) != true) {
3313 drm_dbg_kms(&dev_priv->drm,
3314 "SDVO output failed to setup on %s\n",
3315 SDVO_NAME(intel_sdvo));
3316 /* Output_setup can leave behind connectors! */
3321 * Only enable the hotplug irq if we need it, to work around noisy
3324 if (intel_sdvo->hotplug_active) {
3325 if (intel_sdvo->port == PORT_B)
3326 intel_encoder->hpd_pin = HPD_SDVO_B;
3328 intel_encoder->hpd_pin = HPD_SDVO_C;
3332 * Cloning SDVO with anything is often impossible, since the SDVO
3333 * encoder can request a special input timing mode. And even if that's
3334 * not the case we have evidence that cloning a plain unscaled mode with
3335 * VGA doesn't really work. Furthermore the cloning flags are way too
3336 * simplistic anyway to express such constraints, so just give up on
3337 * cloning for SDVO encoders.
3339 intel_sdvo->base.cloneable = 0;
3341 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo);
3343 /* Set the input timing to the screen. Assume always input 0. */
3344 if (!intel_sdvo_set_target_input(intel_sdvo))
3347 if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
3348 &intel_sdvo->pixel_clock_min,
3349 &intel_sdvo->pixel_clock_max))
3352 drm_dbg_kms(&dev_priv->drm, "%s device VID/DID: %02X:%02X.%02X, "
3353 "clock range %dMHz - %dMHz, "
3354 "input 1: %c, input 2: %c, "
3355 "output 1: %c, output 2: %c\n",
3356 SDVO_NAME(intel_sdvo),
3357 intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
3358 intel_sdvo->caps.device_rev_id,
3359 intel_sdvo->pixel_clock_min / 1000,
3360 intel_sdvo->pixel_clock_max / 1000,
3361 (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
3362 (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
3363 /* check currently supported outputs */
3364 intel_sdvo->caps.output_flags &
3365 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
3366 intel_sdvo->caps.output_flags &
3367 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
3371 intel_sdvo_output_cleanup(intel_sdvo);
3374 drm_encoder_cleanup(&intel_encoder->base);
3375 i2c_del_adapter(&intel_sdvo->ddc);
3377 intel_sdvo_unselect_i2c_bus(intel_sdvo);