Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 Dave Airlie <airlied@linux.ie> |
| 3 | * Copyright © 2006-2007 Intel Corporation |
| 4 | * Jesse Barnes <jesse.barnes@intel.com> |
| 5 | * |
| 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: |
| 12 | * |
| 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 |
| 15 | * Software. |
| 16 | * |
| 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. |
| 24 | * |
| 25 | * Authors: |
| 26 | * Eric Anholt <eric@anholt.net> |
| 27 | */ |
| 28 | #include <linux/i2c.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include "drmP.h" |
| 31 | #include "drm.h" |
| 32 | #include "drm_crtc.h" |
| 33 | #include "intel_drv.h" |
ling.ma@intel.com | 2b8d33f7 | 2009-07-29 11:31:18 +0800 | [diff] [blame] | 34 | #include "drm_edid.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include "i915_drm.h" |
| 36 | #include "i915_drv.h" |
| 37 | #include "intel_sdvo_regs.h" |
Zhao Yakui | 6070a4a | 2010-02-08 21:35:12 +0800 | [diff] [blame] | 38 | #include <linux/dmi.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 39 | |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 40 | static char *tv_format_names[] = { |
| 41 | "NTSC_M" , "NTSC_J" , "NTSC_443", |
| 42 | "PAL_B" , "PAL_D" , "PAL_G" , |
| 43 | "PAL_H" , "PAL_I" , "PAL_M" , |
| 44 | "PAL_N" , "PAL_NC" , "PAL_60" , |
| 45 | "SECAM_B" , "SECAM_D" , "SECAM_G" , |
| 46 | "SECAM_K" , "SECAM_K1", "SECAM_L" , |
| 47 | "SECAM_60" |
| 48 | }; |
| 49 | |
| 50 | #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names)) |
| 51 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 52 | struct intel_sdvo_priv { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 53 | u8 slave_addr; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 54 | |
| 55 | /* Register for the SDVO device: SDVOB or SDVOC */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 56 | int sdvo_reg; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 57 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 58 | /* Active outputs controlled by this SDVO output */ |
| 59 | uint16_t controlled_output; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 60 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 61 | /* |
| 62 | * Capabilities of the SDVO device returned by |
| 63 | * i830_sdvo_get_capabilities() |
| 64 | */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 65 | struct intel_sdvo_caps caps; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 66 | |
| 67 | /* Pixel clock limitations reported by the SDVO device, in kHz */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 68 | int pixel_clock_min, pixel_clock_max; |
| 69 | |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 70 | /* |
| 71 | * For multiple function SDVO device, |
| 72 | * this is for current attached outputs. |
| 73 | */ |
| 74 | uint16_t attached_output; |
| 75 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 76 | /** |
| 77 | * This is set if we're going to treat the device as TV-out. |
| 78 | * |
| 79 | * While we have these nice friendly flags for output types that ought |
| 80 | * to decide this for us, the S-Video output on our HDMI+S-Video card |
| 81 | * shows up as RGB1 (VGA). |
| 82 | */ |
| 83 | bool is_tv; |
| 84 | |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 85 | /* This is for current tv format name */ |
| 86 | char *tv_format_name; |
| 87 | |
| 88 | /* This contains all current supported TV format */ |
| 89 | char *tv_format_supported[TV_FORMAT_NUM]; |
| 90 | int format_supported_num; |
| 91 | struct drm_property *tv_format_property; |
| 92 | struct drm_property *tv_format_name_property[TV_FORMAT_NUM]; |
| 93 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 94 | /** |
| 95 | * This is set if we treat the device as HDMI, instead of DVI. |
| 96 | */ |
| 97 | bool is_hdmi; |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 98 | |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 99 | /** |
| 100 | * This is set if we detect output of sdvo device as LVDS. |
| 101 | */ |
| 102 | bool is_lvds; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 105 | * This is sdvo flags for input timing. |
| 106 | */ |
| 107 | uint8_t sdvo_flags; |
| 108 | |
| 109 | /** |
| 110 | * This is sdvo fixed pannel mode pointer |
| 111 | */ |
| 112 | struct drm_display_mode *sdvo_lvds_fixed_mode; |
| 113 | |
| 114 | /** |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 115 | * Returned SDTV resolutions allowed for the current format, if the |
| 116 | * device reported it. |
| 117 | */ |
| 118 | struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions; |
| 119 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 120 | /* |
| 121 | * supported encoding mode, used to determine whether HDMI is |
| 122 | * supported |
| 123 | */ |
| 124 | struct intel_sdvo_encode encode; |
| 125 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 126 | /* DDC bus used by this SDVO encoder */ |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 127 | uint8_t ddc_bus; |
| 128 | |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 129 | /* Mac mini hack -- use the same DDC as the analog connector */ |
| 130 | struct i2c_adapter *analog_ddc_bus; |
| 131 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 132 | int save_sdvo_mult; |
| 133 | u16 save_active_outputs; |
| 134 | struct intel_sdvo_dtd save_input_dtd_1, save_input_dtd_2; |
| 135 | struct intel_sdvo_dtd save_output_dtd[16]; |
| 136 | u32 save_SDVOX; |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 137 | /* add the property for the SDVO-TV */ |
| 138 | struct drm_property *left_property; |
| 139 | struct drm_property *right_property; |
| 140 | struct drm_property *top_property; |
| 141 | struct drm_property *bottom_property; |
| 142 | struct drm_property *hpos_property; |
| 143 | struct drm_property *vpos_property; |
| 144 | |
| 145 | /* add the property for the SDVO-TV/LVDS */ |
| 146 | struct drm_property *brightness_property; |
| 147 | struct drm_property *contrast_property; |
| 148 | struct drm_property *saturation_property; |
| 149 | struct drm_property *hue_property; |
| 150 | |
| 151 | /* Add variable to record current setting for the above property */ |
| 152 | u32 left_margin, right_margin, top_margin, bottom_margin; |
| 153 | /* this is to get the range of margin.*/ |
| 154 | u32 max_hscan, max_vscan; |
| 155 | u32 max_hpos, cur_hpos; |
| 156 | u32 max_vpos, cur_vpos; |
| 157 | u32 cur_brightness, max_brightness; |
| 158 | u32 cur_contrast, max_contrast; |
| 159 | u32 cur_saturation, max_saturation; |
| 160 | u32 cur_hue, max_hue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 163 | static bool |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 164 | intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 165 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 166 | /** |
| 167 | * Writes the SDVOB or SDVOC with the given value, but always writes both |
| 168 | * SDVOB and SDVOC to work around apparent hardware issues (according to |
| 169 | * comments in the BIOS). |
| 170 | */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 171 | static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 172 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 173 | struct drm_device *dev = intel_encoder->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 174 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 175 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 176 | u32 bval = val, cval = val; |
| 177 | int i; |
| 178 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 179 | if (sdvo_priv->sdvo_reg == SDVOB) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 180 | cval = I915_READ(SDVOC); |
| 181 | } else { |
| 182 | bval = I915_READ(SDVOB); |
| 183 | } |
| 184 | /* |
| 185 | * Write the registers twice for luck. Sometimes, |
| 186 | * writing them only once doesn't appear to 'stick'. |
| 187 | * The BIOS does this too. Yay, magic |
| 188 | */ |
| 189 | for (i = 0; i < 2; i++) |
| 190 | { |
| 191 | I915_WRITE(SDVOB, bval); |
| 192 | I915_READ(SDVOB); |
| 193 | I915_WRITE(SDVOC, cval); |
| 194 | I915_READ(SDVOC); |
| 195 | } |
| 196 | } |
| 197 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 198 | static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 199 | u8 *ch) |
| 200 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 201 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 202 | u8 out_buf[2]; |
| 203 | u8 buf[2]; |
| 204 | int ret; |
| 205 | |
| 206 | struct i2c_msg msgs[] = { |
| 207 | { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 208 | .addr = sdvo_priv->slave_addr >> 1, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 209 | .flags = 0, |
| 210 | .len = 1, |
| 211 | .buf = out_buf, |
| 212 | }, |
| 213 | { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 214 | .addr = sdvo_priv->slave_addr >> 1, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 215 | .flags = I2C_M_RD, |
| 216 | .len = 1, |
| 217 | .buf = buf, |
| 218 | } |
| 219 | }; |
| 220 | |
| 221 | out_buf[0] = addr; |
| 222 | out_buf[1] = 0; |
| 223 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 224 | if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 225 | { |
| 226 | *ch = buf[0]; |
| 227 | return true; |
| 228 | } |
| 229 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 230 | DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 231 | return false; |
| 232 | } |
| 233 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 234 | static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 235 | u8 ch) |
| 236 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 237 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 238 | u8 out_buf[2]; |
| 239 | struct i2c_msg msgs[] = { |
| 240 | { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 241 | .addr = sdvo_priv->slave_addr >> 1, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 242 | .flags = 0, |
| 243 | .len = 2, |
| 244 | .buf = out_buf, |
| 245 | } |
| 246 | }; |
| 247 | |
| 248 | out_buf[0] = addr; |
| 249 | out_buf[1] = ch; |
| 250 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 251 | if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 252 | { |
| 253 | return true; |
| 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} |
| 259 | /** Mapping of command numbers to names, for debug output */ |
Tobias Klauser | 005568b | 2009-02-09 22:02:42 +0100 | [diff] [blame] | 260 | static const struct _sdvo_cmd_name { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 261 | u8 cmd; |
| 262 | char *name; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 263 | } sdvo_cmd_names[] = { |
| 264 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET), |
| 265 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS), |
| 266 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV), |
| 267 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS), |
| 268 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS), |
| 269 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS), |
| 270 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP), |
| 271 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP), |
| 272 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS), |
| 273 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT), |
| 274 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG), |
| 275 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG), |
| 276 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE), |
| 277 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT), |
| 278 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT), |
| 279 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1), |
| 280 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2), |
| 281 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1), |
| 282 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2), |
| 283 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1), |
| 284 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1), |
| 285 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2), |
| 286 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1), |
| 287 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2), |
| 288 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING), |
| 289 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1), |
| 290 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2), |
| 291 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE), |
| 292 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE), |
| 293 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS), |
| 294 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT), |
| 295 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT), |
| 296 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS), |
| 297 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT), |
| 298 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT), |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 299 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES), |
| 300 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE), |
| 301 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE), |
| 302 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE), |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 303 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH), |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 304 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT), |
| 305 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT), |
| 306 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS), |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 307 | /* Add the op code for SDVO enhancements */ |
| 308 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H), |
| 309 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H), |
| 310 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H), |
| 311 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V), |
| 312 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V), |
| 313 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V), |
| 314 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION), |
| 315 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION), |
| 316 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION), |
| 317 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE), |
| 318 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE), |
| 319 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE), |
| 320 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST), |
| 321 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST), |
| 322 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST), |
| 323 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS), |
| 324 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS), |
| 325 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS), |
| 326 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H), |
| 327 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H), |
| 328 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H), |
| 329 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V), |
| 330 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V), |
| 331 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V), |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 332 | /* HDMI op code */ |
| 333 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE), |
| 334 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE), |
| 335 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE), |
| 336 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI), |
| 337 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI), |
| 338 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP), |
| 339 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY), |
| 340 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY), |
| 341 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER), |
| 342 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT), |
| 343 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT), |
| 344 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX), |
| 345 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX), |
| 346 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO), |
| 347 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT), |
| 348 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT), |
| 349 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE), |
| 350 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE), |
| 351 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA), |
| 352 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA), |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 353 | }; |
| 354 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 355 | #define SDVO_NAME(dev_priv) ((dev_priv)->sdvo_reg == SDVOB ? "SDVOB" : "SDVOC") |
| 356 | #define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 357 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 358 | static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 359 | void *args, int args_len) |
| 360 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 361 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 362 | int i; |
| 363 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 364 | DRM_DEBUG_KMS("%s: W: %02X ", |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 365 | SDVO_NAME(sdvo_priv), cmd); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 366 | for (i = 0; i < args_len; i++) |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 367 | DRM_LOG_KMS("%02X ", ((u8 *)args)[i]); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 368 | for (; i < 8; i++) |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 369 | DRM_LOG_KMS(" "); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 370 | for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) { |
| 371 | if (cmd == sdvo_cmd_names[i].cmd) { |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 372 | DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 373 | break; |
| 374 | } |
| 375 | } |
| 376 | if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0])) |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 377 | DRM_LOG_KMS("(%02X)", cmd); |
| 378 | DRM_LOG_KMS("\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 379 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 380 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 381 | static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 382 | void *args, int args_len) |
| 383 | { |
| 384 | int i; |
| 385 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 386 | intel_sdvo_debug_write(intel_encoder, cmd, args, args_len); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 387 | |
| 388 | for (i = 0; i < args_len; i++) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 389 | intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 390 | ((u8*)args)[i]); |
| 391 | } |
| 392 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 393 | intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 396 | static const char *cmd_status_names[] = { |
| 397 | "Power on", |
| 398 | "Success", |
| 399 | "Not supported", |
| 400 | "Invalid arg", |
| 401 | "Pending", |
| 402 | "Target not specified", |
| 403 | "Scaling not supported" |
| 404 | }; |
| 405 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 406 | static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 407 | void *response, int response_len, |
| 408 | u8 status) |
| 409 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 410 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Zhenyu Wang | 33b5296 | 2009-03-24 14:02:40 +0800 | [diff] [blame] | 411 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 412 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 413 | DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 414 | for (i = 0; i < response_len; i++) |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 415 | DRM_LOG_KMS("%02X ", ((u8 *)response)[i]); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 416 | for (; i < 8; i++) |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 417 | DRM_LOG_KMS(" "); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 418 | if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 419 | DRM_LOG_KMS("(%s)", cmd_status_names[status]); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 420 | else |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 421 | DRM_LOG_KMS("(??? %d)", status); |
| 422 | DRM_LOG_KMS("\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 423 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 424 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 425 | static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 426 | void *response, int response_len) |
| 427 | { |
| 428 | int i; |
| 429 | u8 status; |
| 430 | u8 retry = 50; |
| 431 | |
| 432 | while (retry--) { |
| 433 | /* Read the command response */ |
| 434 | for (i = 0; i < response_len; i++) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 435 | intel_sdvo_read_byte(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 436 | SDVO_I2C_RETURN_0 + i, |
| 437 | &((u8 *)response)[i]); |
| 438 | } |
| 439 | |
| 440 | /* read the return status */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 441 | intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 442 | &status); |
| 443 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 444 | intel_sdvo_debug_response(intel_encoder, response, response_len, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 445 | status); |
| 446 | if (status != SDVO_CMD_STATUS_PENDING) |
| 447 | return status; |
| 448 | |
| 449 | mdelay(50); |
| 450 | } |
| 451 | |
| 452 | return status; |
| 453 | } |
| 454 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 455 | static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 456 | { |
| 457 | if (mode->clock >= 100000) |
| 458 | return 1; |
| 459 | else if (mode->clock >= 50000) |
| 460 | return 2; |
| 461 | else |
| 462 | return 4; |
| 463 | } |
| 464 | |
| 465 | /** |
Zhao Yakui | 6a304ca | 2010-01-08 10:58:19 +0800 | [diff] [blame] | 466 | * Try to read the response after issuie the DDC switch command. But it |
| 467 | * is noted that we must do the action of reading response and issuing DDC |
| 468 | * switch command in one I2C transaction. Otherwise when we try to start |
| 469 | * another I2C transaction after issuing the DDC bus switch, it will be |
| 470 | * switched to the internal SDVO register. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 471 | */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 472 | static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder, |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 473 | u8 target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 474 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 475 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Zhao Yakui | 6a304ca | 2010-01-08 10:58:19 +0800 | [diff] [blame] | 476 | u8 out_buf[2], cmd_buf[2], ret_value[2], ret; |
| 477 | struct i2c_msg msgs[] = { |
| 478 | { |
| 479 | .addr = sdvo_priv->slave_addr >> 1, |
| 480 | .flags = 0, |
| 481 | .len = 2, |
| 482 | .buf = out_buf, |
| 483 | }, |
| 484 | /* the following two are to read the response */ |
| 485 | { |
| 486 | .addr = sdvo_priv->slave_addr >> 1, |
| 487 | .flags = 0, |
| 488 | .len = 1, |
| 489 | .buf = cmd_buf, |
| 490 | }, |
| 491 | { |
| 492 | .addr = sdvo_priv->slave_addr >> 1, |
| 493 | .flags = I2C_M_RD, |
| 494 | .len = 1, |
| 495 | .buf = ret_value, |
| 496 | }, |
| 497 | }; |
| 498 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 499 | intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH, |
Zhao Yakui | 6a304ca | 2010-01-08 10:58:19 +0800 | [diff] [blame] | 500 | &target, 1); |
| 501 | /* write the DDC switch command argument */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 502 | intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target); |
Zhao Yakui | 6a304ca | 2010-01-08 10:58:19 +0800 | [diff] [blame] | 503 | |
| 504 | out_buf[0] = SDVO_I2C_OPCODE; |
| 505 | out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH; |
| 506 | cmd_buf[0] = SDVO_I2C_CMD_STATUS; |
| 507 | cmd_buf[1] = 0; |
| 508 | ret_value[0] = 0; |
| 509 | ret_value[1] = 0; |
| 510 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 511 | ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3); |
Zhao Yakui | 6a304ca | 2010-01-08 10:58:19 +0800 | [diff] [blame] | 512 | if (ret != 3) { |
| 513 | /* failure in I2C transfer */ |
| 514 | DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); |
| 515 | return; |
| 516 | } |
| 517 | if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) { |
| 518 | DRM_DEBUG_KMS("DDC switch command returns response %d\n", |
| 519 | ret_value[0]); |
| 520 | return; |
| 521 | } |
| 522 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 525 | static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 526 | { |
| 527 | struct intel_sdvo_set_target_input_args targets = {0}; |
| 528 | u8 status; |
| 529 | |
| 530 | if (target_0 && target_1) |
| 531 | return SDVO_CMD_STATUS_NOTSUPP; |
| 532 | |
| 533 | if (target_1) |
| 534 | targets.target_1 = 1; |
| 535 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 536 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 537 | sizeof(targets)); |
| 538 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 539 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 540 | |
| 541 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Return whether each input is trained. |
| 546 | * |
| 547 | * This function is making an assumption about the layout of the response, |
| 548 | * which should be checked against the docs. |
| 549 | */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 550 | static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 551 | { |
| 552 | struct intel_sdvo_get_trained_inputs_response response; |
| 553 | u8 status; |
| 554 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 555 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0); |
| 556 | status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 557 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 558 | return false; |
| 559 | |
| 560 | *input_1 = response.input0_trained; |
| 561 | *input_2 = response.input1_trained; |
| 562 | return true; |
| 563 | } |
| 564 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 565 | static bool intel_sdvo_get_active_outputs(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 566 | u16 *outputs) |
| 567 | { |
| 568 | u8 status; |
| 569 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 570 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_OUTPUTS, NULL, 0); |
| 571 | status = intel_sdvo_read_response(intel_encoder, outputs, sizeof(*outputs)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 572 | |
| 573 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 574 | } |
| 575 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 576 | static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 577 | u16 outputs) |
| 578 | { |
| 579 | u8 status; |
| 580 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 581 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 582 | sizeof(outputs)); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 583 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 584 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 585 | } |
| 586 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 587 | static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 588 | int mode) |
| 589 | { |
| 590 | u8 status, state = SDVO_ENCODER_STATE_ON; |
| 591 | |
| 592 | switch (mode) { |
| 593 | case DRM_MODE_DPMS_ON: |
| 594 | state = SDVO_ENCODER_STATE_ON; |
| 595 | break; |
| 596 | case DRM_MODE_DPMS_STANDBY: |
| 597 | state = SDVO_ENCODER_STATE_STANDBY; |
| 598 | break; |
| 599 | case DRM_MODE_DPMS_SUSPEND: |
| 600 | state = SDVO_ENCODER_STATE_SUSPEND; |
| 601 | break; |
| 602 | case DRM_MODE_DPMS_OFF: |
| 603 | state = SDVO_ENCODER_STATE_OFF; |
| 604 | break; |
| 605 | } |
| 606 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 607 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 608 | sizeof(state)); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 609 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | |
| 611 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 612 | } |
| 613 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 614 | static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 615 | int *clock_min, |
| 616 | int *clock_max) |
| 617 | { |
| 618 | struct intel_sdvo_pixel_clock_range clocks; |
| 619 | u8 status; |
| 620 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 621 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 622 | NULL, 0); |
| 623 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 624 | status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 625 | |
| 626 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 627 | return false; |
| 628 | |
| 629 | /* Convert the values from units of 10 kHz to kHz. */ |
| 630 | *clock_min = clocks.min * 10; |
| 631 | *clock_max = clocks.max * 10; |
| 632 | |
| 633 | return true; |
| 634 | } |
| 635 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 636 | static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 637 | u16 outputs) |
| 638 | { |
| 639 | u8 status; |
| 640 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 641 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 642 | sizeof(outputs)); |
| 643 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 644 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 645 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 646 | } |
| 647 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 648 | static bool intel_sdvo_get_timing(struct intel_encoder *intel_encoder, u8 cmd, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 649 | struct intel_sdvo_dtd *dtd) |
| 650 | { |
| 651 | u8 status; |
| 652 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 653 | intel_sdvo_write_cmd(intel_encoder, cmd, NULL, 0); |
| 654 | status = intel_sdvo_read_response(intel_encoder, &dtd->part1, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 655 | sizeof(dtd->part1)); |
| 656 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 657 | return false; |
| 658 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 659 | intel_sdvo_write_cmd(intel_encoder, cmd + 1, NULL, 0); |
| 660 | status = intel_sdvo_read_response(intel_encoder, &dtd->part2, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 661 | sizeof(dtd->part2)); |
| 662 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 663 | return false; |
| 664 | |
| 665 | return true; |
| 666 | } |
| 667 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 668 | static bool intel_sdvo_get_input_timing(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 669 | struct intel_sdvo_dtd *dtd) |
| 670 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 671 | return intel_sdvo_get_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 672 | SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd); |
| 673 | } |
| 674 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 675 | static bool intel_sdvo_get_output_timing(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 676 | struct intel_sdvo_dtd *dtd) |
| 677 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 678 | return intel_sdvo_get_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 679 | SDVO_CMD_GET_OUTPUT_TIMINGS_PART1, dtd); |
| 680 | } |
| 681 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 682 | static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 683 | struct intel_sdvo_dtd *dtd) |
| 684 | { |
| 685 | u8 status; |
| 686 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 687 | intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1)); |
| 688 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 689 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 690 | return false; |
| 691 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 692 | intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2)); |
| 693 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 694 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 695 | return false; |
| 696 | |
| 697 | return true; |
| 698 | } |
| 699 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 700 | static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 701 | struct intel_sdvo_dtd *dtd) |
| 702 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 703 | return intel_sdvo_set_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 704 | SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd); |
| 705 | } |
| 706 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 707 | static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 708 | struct intel_sdvo_dtd *dtd) |
| 709 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 710 | return intel_sdvo_set_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 711 | SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd); |
| 712 | } |
| 713 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 714 | static bool |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 715 | intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 716 | uint16_t clock, |
| 717 | uint16_t width, |
| 718 | uint16_t height) |
| 719 | { |
| 720 | struct intel_sdvo_preferred_input_timing_args args; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 721 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 722 | uint8_t status; |
| 723 | |
Zhenyu Wang | e642c6f | 2009-03-24 14:02:42 +0800 | [diff] [blame] | 724 | memset(&args, 0, sizeof(args)); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 725 | args.clock = clock; |
| 726 | args.width = width; |
| 727 | args.height = height; |
Zhenyu Wang | e642c6f | 2009-03-24 14:02:42 +0800 | [diff] [blame] | 728 | args.interlace = 0; |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 729 | |
| 730 | if (sdvo_priv->is_lvds && |
| 731 | (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width || |
| 732 | sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height)) |
| 733 | args.scaled = 1; |
| 734 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 735 | intel_sdvo_write_cmd(intel_encoder, |
| 736 | SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 737 | &args, sizeof(args)); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 738 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 739 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 740 | return false; |
| 741 | |
| 742 | return true; |
| 743 | } |
| 744 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 745 | static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 746 | struct intel_sdvo_dtd *dtd) |
| 747 | { |
| 748 | bool status; |
| 749 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 750 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 751 | NULL, 0); |
| 752 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 753 | status = intel_sdvo_read_response(intel_encoder, &dtd->part1, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 754 | sizeof(dtd->part1)); |
| 755 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 756 | return false; |
| 757 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 758 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 759 | NULL, 0); |
| 760 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 761 | status = intel_sdvo_read_response(intel_encoder, &dtd->part2, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 762 | sizeof(dtd->part2)); |
| 763 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 764 | return false; |
| 765 | |
| 766 | return false; |
| 767 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 768 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 769 | static int intel_sdvo_get_clock_rate_mult(struct intel_encoder *intel_encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 770 | { |
| 771 | u8 response, status; |
| 772 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 773 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_CLOCK_RATE_MULT, NULL, 0); |
| 774 | status = intel_sdvo_read_response(intel_encoder, &response, 1); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 775 | |
| 776 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 777 | DRM_DEBUG_KMS("Couldn't get SDVO clock rate multiplier\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 778 | return SDVO_CLOCK_RATE_MULT_1X; |
| 779 | } else { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 780 | DRM_DEBUG_KMS("Current clock rate multiplier: %d\n", response); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | return response; |
| 784 | } |
| 785 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 786 | static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 787 | { |
| 788 | u8 status; |
| 789 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 790 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1); |
| 791 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 792 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 793 | return false; |
| 794 | |
| 795 | return true; |
| 796 | } |
| 797 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 798 | static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd, |
| 799 | struct drm_display_mode *mode) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 800 | { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 801 | uint16_t width, height; |
| 802 | uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len; |
| 803 | uint16_t h_sync_offset, v_sync_offset; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 804 | |
| 805 | width = mode->crtc_hdisplay; |
| 806 | height = mode->crtc_vdisplay; |
| 807 | |
| 808 | /* do some mode translations */ |
| 809 | h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start; |
| 810 | h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 811 | |
| 812 | v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start; |
| 813 | v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 814 | |
| 815 | h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start; |
| 816 | v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start; |
| 817 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 818 | dtd->part1.clock = mode->clock / 10; |
| 819 | dtd->part1.h_active = width & 0xff; |
| 820 | dtd->part1.h_blank = h_blank_len & 0xff; |
| 821 | dtd->part1.h_high = (((width >> 8) & 0xf) << 4) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 822 | ((h_blank_len >> 8) & 0xf); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 823 | dtd->part1.v_active = height & 0xff; |
| 824 | dtd->part1.v_blank = v_blank_len & 0xff; |
| 825 | dtd->part1.v_high = (((height >> 8) & 0xf) << 4) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 826 | ((v_blank_len >> 8) & 0xf); |
| 827 | |
Zhenyu Wang | 171a9e9 | 2009-03-24 14:02:41 +0800 | [diff] [blame] | 828 | dtd->part2.h_sync_off = h_sync_offset & 0xff; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 829 | dtd->part2.h_sync_width = h_sync_len & 0xff; |
| 830 | dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 831 | (v_sync_len & 0xf); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 832 | dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 833 | ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) | |
| 834 | ((v_sync_len & 0x30) >> 4); |
| 835 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 836 | dtd->part2.dtd_flags = 0x18; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 837 | if (mode->flags & DRM_MODE_FLAG_PHSYNC) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 838 | dtd->part2.dtd_flags |= 0x2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 839 | if (mode->flags & DRM_MODE_FLAG_PVSYNC) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 840 | dtd->part2.dtd_flags |= 0x4; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 841 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 842 | dtd->part2.sdvo_flags = 0; |
| 843 | dtd->part2.v_sync_off_high = v_sync_offset & 0xc0; |
| 844 | dtd->part2.reserved = 0; |
| 845 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 846 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 847 | static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode, |
| 848 | struct intel_sdvo_dtd *dtd) |
| 849 | { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 850 | mode->hdisplay = dtd->part1.h_active; |
| 851 | mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8; |
| 852 | mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off; |
Zhenyu Wang | 171a9e9 | 2009-03-24 14:02:41 +0800 | [diff] [blame] | 853 | mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 854 | mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width; |
| 855 | mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4; |
| 856 | mode->htotal = mode->hdisplay + dtd->part1.h_blank; |
| 857 | mode->htotal += (dtd->part1.h_high & 0xf) << 8; |
| 858 | |
| 859 | mode->vdisplay = dtd->part1.v_active; |
| 860 | mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8; |
| 861 | mode->vsync_start = mode->vdisplay; |
| 862 | mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf; |
Zhenyu Wang | 171a9e9 | 2009-03-24 14:02:41 +0800 | [diff] [blame] | 863 | mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 864 | mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0; |
| 865 | mode->vsync_end = mode->vsync_start + |
| 866 | (dtd->part2.v_sync_off_width & 0xf); |
| 867 | mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4; |
| 868 | mode->vtotal = mode->vdisplay + dtd->part1.v_blank; |
| 869 | mode->vtotal += (dtd->part1.v_high & 0xf) << 8; |
| 870 | |
| 871 | mode->clock = dtd->part1.clock * 10; |
| 872 | |
Zhenyu Wang | 171a9e9 | 2009-03-24 14:02:41 +0800 | [diff] [blame] | 873 | mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 874 | if (dtd->part2.dtd_flags & 0x2) |
| 875 | mode->flags |= DRM_MODE_FLAG_PHSYNC; |
| 876 | if (dtd->part2.dtd_flags & 0x4) |
| 877 | mode->flags |= DRM_MODE_FLAG_PVSYNC; |
| 878 | } |
| 879 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 880 | static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 881 | struct intel_sdvo_encode *encode) |
| 882 | { |
| 883 | uint8_t status; |
| 884 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 885 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0); |
| 886 | status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode)); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 887 | if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */ |
| 888 | memset(encode, 0, sizeof(*encode)); |
| 889 | return false; |
| 890 | } |
| 891 | |
| 892 | return true; |
| 893 | } |
| 894 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 895 | static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder, |
| 896 | uint8_t mode) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 897 | { |
| 898 | uint8_t status; |
| 899 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 900 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1); |
| 901 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 902 | |
| 903 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 904 | } |
| 905 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 906 | static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 907 | uint8_t mode) |
| 908 | { |
| 909 | uint8_t status; |
| 910 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 911 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1); |
| 912 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 913 | |
| 914 | return (status == SDVO_CMD_STATUS_SUCCESS); |
| 915 | } |
| 916 | |
| 917 | #if 0 |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 918 | static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 919 | { |
| 920 | int i, j; |
| 921 | uint8_t set_buf_index[2]; |
| 922 | uint8_t av_split; |
| 923 | uint8_t buf_size; |
| 924 | uint8_t buf[48]; |
| 925 | uint8_t *pos; |
| 926 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 927 | intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0); |
| 928 | intel_sdvo_read_response(encoder, &av_split, 1); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 929 | |
| 930 | for (i = 0; i <= av_split; i++) { |
| 931 | set_buf_index[0] = i; set_buf_index[1] = 0; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 932 | intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 933 | set_buf_index, 2); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 934 | intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0); |
| 935 | intel_sdvo_read_response(encoder, &buf_size, 1); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 936 | |
| 937 | pos = buf; |
| 938 | for (j = 0; j <= buf_size; j += 8) { |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 939 | intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 940 | NULL, 0); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 941 | intel_sdvo_read_response(encoder, pos, 8); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 942 | pos += 8; |
| 943 | } |
| 944 | } |
| 945 | } |
| 946 | #endif |
| 947 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 948 | static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder, |
| 949 | int index, |
| 950 | uint8_t *data, int8_t size, uint8_t tx_rate) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 951 | { |
| 952 | uint8_t set_buf_index[2]; |
| 953 | |
| 954 | set_buf_index[0] = index; |
| 955 | set_buf_index[1] = 0; |
| 956 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 957 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX, |
| 958 | set_buf_index, 2); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 959 | |
| 960 | for (; size > 0; size -= 8) { |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 961 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 962 | data += 8; |
| 963 | } |
| 964 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 965 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size) |
| 969 | { |
| 970 | uint8_t csum = 0; |
| 971 | int i; |
| 972 | |
| 973 | for (i = 0; i < size; i++) |
| 974 | csum += data[i]; |
| 975 | |
| 976 | return 0x100 - csum; |
| 977 | } |
| 978 | |
| 979 | #define DIP_TYPE_AVI 0x82 |
| 980 | #define DIP_VERSION_AVI 0x2 |
| 981 | #define DIP_LEN_AVI 13 |
| 982 | |
| 983 | struct dip_infoframe { |
| 984 | uint8_t type; |
| 985 | uint8_t version; |
| 986 | uint8_t len; |
| 987 | uint8_t checksum; |
| 988 | union { |
| 989 | struct { |
| 990 | /* Packet Byte #1 */ |
| 991 | uint8_t S:2; |
| 992 | uint8_t B:2; |
| 993 | uint8_t A:1; |
| 994 | uint8_t Y:2; |
| 995 | uint8_t rsvd1:1; |
| 996 | /* Packet Byte #2 */ |
| 997 | uint8_t R:4; |
| 998 | uint8_t M:2; |
| 999 | uint8_t C:2; |
| 1000 | /* Packet Byte #3 */ |
| 1001 | uint8_t SC:2; |
| 1002 | uint8_t Q:2; |
| 1003 | uint8_t EC:3; |
| 1004 | uint8_t ITC:1; |
| 1005 | /* Packet Byte #4 */ |
| 1006 | uint8_t VIC:7; |
| 1007 | uint8_t rsvd2:1; |
| 1008 | /* Packet Byte #5 */ |
| 1009 | uint8_t PR:4; |
| 1010 | uint8_t rsvd3:4; |
| 1011 | /* Packet Byte #6~13 */ |
| 1012 | uint16_t top_bar_end; |
| 1013 | uint16_t bottom_bar_start; |
| 1014 | uint16_t left_bar_end; |
| 1015 | uint16_t right_bar_start; |
| 1016 | } avi; |
| 1017 | struct { |
| 1018 | /* Packet Byte #1 */ |
| 1019 | uint8_t channel_count:3; |
| 1020 | uint8_t rsvd1:1; |
| 1021 | uint8_t coding_type:4; |
| 1022 | /* Packet Byte #2 */ |
| 1023 | uint8_t sample_size:2; /* SS0, SS1 */ |
| 1024 | uint8_t sample_frequency:3; |
| 1025 | uint8_t rsvd2:3; |
| 1026 | /* Packet Byte #3 */ |
| 1027 | uint8_t coding_type_private:5; |
| 1028 | uint8_t rsvd3:3; |
| 1029 | /* Packet Byte #4 */ |
| 1030 | uint8_t channel_allocation; |
| 1031 | /* Packet Byte #5 */ |
| 1032 | uint8_t rsvd4:3; |
| 1033 | uint8_t level_shift:4; |
| 1034 | uint8_t downmix_inhibit:1; |
| 1035 | } audio; |
| 1036 | uint8_t payload[28]; |
| 1037 | } __attribute__ ((packed)) u; |
| 1038 | } __attribute__((packed)); |
| 1039 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1040 | static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1041 | struct drm_display_mode * mode) |
| 1042 | { |
| 1043 | struct dip_infoframe avi_if = { |
| 1044 | .type = DIP_TYPE_AVI, |
| 1045 | .version = DIP_VERSION_AVI, |
| 1046 | .len = DIP_LEN_AVI, |
| 1047 | }; |
| 1048 | |
| 1049 | avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if, |
| 1050 | 4 + avi_if.len); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1051 | intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if, |
| 1052 | 4 + avi_if.len, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1053 | SDVO_HBUF_TX_VSYNC); |
| 1054 | } |
| 1055 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1056 | static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder) |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1057 | { |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1058 | |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1059 | struct intel_sdvo_tv_format format; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1060 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1061 | uint32_t format_map, i; |
| 1062 | uint8_t status; |
| 1063 | |
| 1064 | for (i = 0; i < TV_FORMAT_NUM; i++) |
| 1065 | if (tv_format_names[i] == sdvo_priv->tv_format_name) |
| 1066 | break; |
| 1067 | |
| 1068 | format_map = 1 << i; |
| 1069 | memset(&format, 0, sizeof(format)); |
| 1070 | memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ? |
| 1071 | sizeof(format) : sizeof(format_map)); |
| 1072 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1073 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format_map, |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1074 | sizeof(format)); |
| 1075 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1076 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1077 | if (status != SDVO_CMD_STATUS_SUCCESS) |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 1078 | DRM_DEBUG_KMS("%s: Failed to set TV format\n", |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1079 | SDVO_NAME(sdvo_priv)); |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1082 | static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, |
| 1083 | struct drm_display_mode *mode, |
| 1084 | struct drm_display_mode *adjusted_mode) |
| 1085 | { |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1086 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); |
| 1087 | struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1088 | |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1089 | if (dev_priv->is_tv) { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1090 | struct intel_sdvo_dtd output_dtd; |
| 1091 | bool success; |
| 1092 | |
| 1093 | /* We need to construct preferred input timings based on our |
| 1094 | * output timings. To do that, we have to set the output |
| 1095 | * timings, even though this isn't really the right place in |
| 1096 | * the sequence to do it. Oh well. |
| 1097 | */ |
| 1098 | |
| 1099 | |
| 1100 | /* Set output timings */ |
| 1101 | intel_sdvo_get_dtd_from_mode(&output_dtd, mode); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1102 | intel_sdvo_set_target_output(intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1103 | dev_priv->controlled_output); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1104 | intel_sdvo_set_output_timing(intel_encoder, &output_dtd); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1105 | |
| 1106 | /* Set the input timing to the screen. Assume always input 0. */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1107 | intel_sdvo_set_target_input(intel_encoder, true, false); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1108 | |
| 1109 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1110 | success = intel_sdvo_create_preferred_input_timing(intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1111 | mode->clock / 10, |
| 1112 | mode->hdisplay, |
| 1113 | mode->vdisplay); |
| 1114 | if (success) { |
| 1115 | struct intel_sdvo_dtd input_dtd; |
| 1116 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1117 | intel_sdvo_get_preferred_input_timing(intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1118 | &input_dtd); |
| 1119 | intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1120 | dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1121 | |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1122 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
| 1123 | |
| 1124 | mode->clock = adjusted_mode->clock; |
| 1125 | |
| 1126 | adjusted_mode->clock *= |
| 1127 | intel_sdvo_get_pixel_multiplier(mode); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1128 | } else { |
| 1129 | return false; |
| 1130 | } |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1131 | } else if (dev_priv->is_lvds) { |
| 1132 | struct intel_sdvo_dtd output_dtd; |
| 1133 | bool success; |
| 1134 | |
| 1135 | drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0); |
| 1136 | /* Set output timings */ |
| 1137 | intel_sdvo_get_dtd_from_mode(&output_dtd, |
| 1138 | dev_priv->sdvo_lvds_fixed_mode); |
| 1139 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1140 | intel_sdvo_set_target_output(intel_encoder, |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1141 | dev_priv->controlled_output); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1142 | intel_sdvo_set_output_timing(intel_encoder, &output_dtd); |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1143 | |
| 1144 | /* Set the input timing to the screen. Assume always input 0. */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1145 | intel_sdvo_set_target_input(intel_encoder, true, false); |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1146 | |
| 1147 | |
| 1148 | success = intel_sdvo_create_preferred_input_timing( |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1149 | intel_encoder, |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1150 | mode->clock / 10, |
| 1151 | mode->hdisplay, |
| 1152 | mode->vdisplay); |
| 1153 | |
| 1154 | if (success) { |
| 1155 | struct intel_sdvo_dtd input_dtd; |
| 1156 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1157 | intel_sdvo_get_preferred_input_timing(intel_encoder, |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1158 | &input_dtd); |
| 1159 | intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); |
| 1160 | dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags; |
| 1161 | |
| 1162 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
| 1163 | |
| 1164 | mode->clock = adjusted_mode->clock; |
| 1165 | |
| 1166 | adjusted_mode->clock *= |
| 1167 | intel_sdvo_get_pixel_multiplier(mode); |
| 1168 | } else { |
| 1169 | return false; |
| 1170 | } |
| 1171 | |
| 1172 | } else { |
| 1173 | /* Make the CRTC code factor in the SDVO pixel multiplier. The |
| 1174 | * SDVO device will be told of the multiplier during mode_set. |
| 1175 | */ |
| 1176 | adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1177 | } |
| 1178 | return true; |
| 1179 | } |
| 1180 | |
| 1181 | static void intel_sdvo_mode_set(struct drm_encoder *encoder, |
| 1182 | struct drm_display_mode *mode, |
| 1183 | struct drm_display_mode *adjusted_mode) |
| 1184 | { |
| 1185 | struct drm_device *dev = encoder->dev; |
| 1186 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1187 | struct drm_crtc *crtc = encoder->crtc; |
| 1188 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1189 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); |
| 1190 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1191 | u32 sdvox = 0; |
| 1192 | int sdvo_pixel_multiply; |
| 1193 | struct intel_sdvo_in_out_map in_out; |
| 1194 | struct intel_sdvo_dtd input_dtd; |
| 1195 | u8 status; |
| 1196 | |
| 1197 | if (!mode) |
| 1198 | return; |
| 1199 | |
| 1200 | /* First, set the input mapping for the first input to our controlled |
| 1201 | * output. This is only correct if we're a single-input device, in |
| 1202 | * which case the first input is the output from the appropriate SDVO |
| 1203 | * channel on the motherboard. In a two-input device, the first input |
| 1204 | * will be SDVOB and the second SDVOC. |
| 1205 | */ |
| 1206 | in_out.in0 = sdvo_priv->controlled_output; |
| 1207 | in_out.in1 = 0; |
| 1208 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1209 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1210 | &in_out, sizeof(in_out)); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1211 | status = intel_sdvo_read_response(intel_encoder, NULL, 0); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1212 | |
| 1213 | if (sdvo_priv->is_hdmi) { |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1214 | intel_sdvo_set_avi_infoframe(intel_encoder, mode); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1215 | sdvox |= SDVO_AUDIO_ENABLE; |
| 1216 | } |
| 1217 | |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1218 | /* We have tried to get input timing in mode_fixup, and filled into |
| 1219 | adjusted_mode */ |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1220 | if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1221 | intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1222 | input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags; |
| 1223 | } else |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1224 | intel_sdvo_get_dtd_from_mode(&input_dtd, mode); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1225 | |
| 1226 | /* If it's a TV, we already set the output timing in mode_fixup. |
| 1227 | * Otherwise, the output timing is equal to the input timing. |
| 1228 | */ |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1229 | if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1230 | /* Set the output timing to the screen */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1231 | intel_sdvo_set_target_output(intel_encoder, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1232 | sdvo_priv->controlled_output); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1233 | intel_sdvo_set_output_timing(intel_encoder, &input_dtd); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1234 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1235 | |
| 1236 | /* Set the input timing to the screen. Assume always input 0. */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1237 | intel_sdvo_set_target_input(intel_encoder, true, false); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1238 | |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1239 | if (sdvo_priv->is_tv) |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1240 | intel_sdvo_set_tv_format(intel_encoder); |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1241 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1242 | /* We would like to use intel_sdvo_create_preferred_input_timing() to |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1243 | * provide the device with a timing it can support, if it supports that |
| 1244 | * feature. However, presumably we would need to adjust the CRTC to |
| 1245 | * output the preferred timing, and we don't support that currently. |
| 1246 | */ |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1247 | #if 0 |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1248 | success = intel_sdvo_create_preferred_input_timing(encoder, clock, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1249 | width, height); |
| 1250 | if (success) { |
| 1251 | struct intel_sdvo_dtd *input_dtd; |
| 1252 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1253 | intel_sdvo_get_preferred_input_timing(encoder, &input_dtd); |
| 1254 | intel_sdvo_set_input_timing(encoder, &input_dtd); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1255 | } |
| 1256 | #else |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1257 | intel_sdvo_set_input_timing(intel_encoder, &input_dtd); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1258 | #endif |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1259 | |
| 1260 | switch (intel_sdvo_get_pixel_multiplier(mode)) { |
| 1261 | case 1: |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1262 | intel_sdvo_set_clock_rate_mult(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1263 | SDVO_CLOCK_RATE_MULT_1X); |
| 1264 | break; |
| 1265 | case 2: |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1266 | intel_sdvo_set_clock_rate_mult(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1267 | SDVO_CLOCK_RATE_MULT_2X); |
| 1268 | break; |
| 1269 | case 4: |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1270 | intel_sdvo_set_clock_rate_mult(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1271 | SDVO_CLOCK_RATE_MULT_4X); |
| 1272 | break; |
| 1273 | } |
| 1274 | |
| 1275 | /* Set the SDVO control regs. */ |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1276 | if (IS_I965G(dev)) { |
| 1277 | sdvox |= SDVO_BORDER_ENABLE | |
| 1278 | SDVO_VSYNC_ACTIVE_HIGH | |
| 1279 | SDVO_HSYNC_ACTIVE_HIGH; |
| 1280 | } else { |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1281 | sdvox |= I915_READ(sdvo_priv->sdvo_reg); |
| 1282 | switch (sdvo_priv->sdvo_reg) { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1283 | case SDVOB: |
| 1284 | sdvox &= SDVOB_PRESERVE_MASK; |
| 1285 | break; |
| 1286 | case SDVOC: |
| 1287 | sdvox &= SDVOC_PRESERVE_MASK; |
| 1288 | break; |
| 1289 | } |
| 1290 | sdvox |= (9 << 19) | SDVO_BORDER_ENABLE; |
| 1291 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1292 | if (intel_crtc->pipe == 1) |
| 1293 | sdvox |= SDVO_PIPE_B_SELECT; |
| 1294 | |
| 1295 | sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode); |
| 1296 | if (IS_I965G(dev)) { |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1297 | /* done in crtc_mode_set as the dpll_md reg must be written early */ |
| 1298 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 1299 | /* done in crtc_mode_set as it lives inside the dpll register */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1300 | } else { |
| 1301 | sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT; |
| 1302 | } |
| 1303 | |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1304 | if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL) |
| 1305 | sdvox |= SDVO_STALL_SELECT; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1306 | intel_sdvo_write_sdvox(intel_encoder, sdvox); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) |
| 1310 | { |
| 1311 | struct drm_device *dev = encoder->dev; |
| 1312 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1313 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); |
| 1314 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1315 | u32 temp; |
| 1316 | |
| 1317 | if (mode != DRM_MODE_DPMS_ON) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1318 | intel_sdvo_set_active_outputs(intel_encoder, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1319 | if (0) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1320 | intel_sdvo_set_encoder_power_state(intel_encoder, mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1321 | |
| 1322 | if (mode == DRM_MODE_DPMS_OFF) { |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1323 | temp = I915_READ(sdvo_priv->sdvo_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1324 | if ((temp & SDVO_ENABLE) != 0) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1325 | intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | } else { |
| 1329 | bool input1, input2; |
| 1330 | int i; |
| 1331 | u8 status; |
| 1332 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1333 | temp = I915_READ(sdvo_priv->sdvo_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1334 | if ((temp & SDVO_ENABLE) == 0) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1335 | intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1336 | for (i = 0; i < 2; i++) |
| 1337 | intel_wait_for_vblank(dev); |
| 1338 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1339 | status = intel_sdvo_get_trained_inputs(intel_encoder, &input1, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1340 | &input2); |
| 1341 | |
| 1342 | |
| 1343 | /* Warn if the device reported failure to sync. |
| 1344 | * A lot of SDVO devices fail to notify of sync, but it's |
| 1345 | * a given it the status is a success, we succeeded. |
| 1346 | */ |
| 1347 | if (status == SDVO_CMD_STATUS_SUCCESS && !input1) { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1348 | DRM_DEBUG_KMS("First %s output reported failure to " |
| 1349 | "sync\n", SDVO_NAME(sdvo_priv)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | if (0) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1353 | intel_sdvo_set_encoder_power_state(intel_encoder, mode); |
| 1354 | intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->controlled_output); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1355 | } |
| 1356 | return; |
| 1357 | } |
| 1358 | |
| 1359 | static void intel_sdvo_save(struct drm_connector *connector) |
| 1360 | { |
| 1361 | struct drm_device *dev = connector->dev; |
| 1362 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1363 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1364 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1365 | int o; |
| 1366 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1367 | sdvo_priv->save_sdvo_mult = intel_sdvo_get_clock_rate_mult(intel_encoder); |
| 1368 | intel_sdvo_get_active_outputs(intel_encoder, &sdvo_priv->save_active_outputs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1369 | |
| 1370 | if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1371 | intel_sdvo_set_target_input(intel_encoder, true, false); |
| 1372 | intel_sdvo_get_input_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1373 | &sdvo_priv->save_input_dtd_1); |
| 1374 | } |
| 1375 | |
| 1376 | if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1377 | intel_sdvo_set_target_input(intel_encoder, false, true); |
| 1378 | intel_sdvo_get_input_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1379 | &sdvo_priv->save_input_dtd_2); |
| 1380 | } |
| 1381 | |
| 1382 | for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++) |
| 1383 | { |
| 1384 | u16 this_output = (1 << o); |
| 1385 | if (sdvo_priv->caps.output_flags & this_output) |
| 1386 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1387 | intel_sdvo_set_target_output(intel_encoder, this_output); |
| 1388 | intel_sdvo_get_output_timing(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1389 | &sdvo_priv->save_output_dtd[o]); |
| 1390 | } |
| 1391 | } |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1392 | if (sdvo_priv->is_tv) { |
| 1393 | /* XXX: Save TV format/enhancements. */ |
| 1394 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1395 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1396 | sdvo_priv->save_SDVOX = I915_READ(sdvo_priv->sdvo_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | static void intel_sdvo_restore(struct drm_connector *connector) |
| 1400 | { |
| 1401 | struct drm_device *dev = connector->dev; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1402 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1403 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1404 | int o; |
| 1405 | int i; |
| 1406 | bool input1, input2; |
| 1407 | u8 status; |
| 1408 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1409 | intel_sdvo_set_active_outputs(intel_encoder, 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1410 | |
| 1411 | for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++) |
| 1412 | { |
| 1413 | u16 this_output = (1 << o); |
| 1414 | if (sdvo_priv->caps.output_flags & this_output) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1415 | intel_sdvo_set_target_output(intel_encoder, this_output); |
| 1416 | intel_sdvo_set_output_timing(intel_encoder, &sdvo_priv->save_output_dtd[o]); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1421 | intel_sdvo_set_target_input(intel_encoder, true, false); |
| 1422 | intel_sdvo_set_input_timing(intel_encoder, &sdvo_priv->save_input_dtd_1); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1426 | intel_sdvo_set_target_input(intel_encoder, false, true); |
| 1427 | intel_sdvo_set_input_timing(intel_encoder, &sdvo_priv->save_input_dtd_2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1430 | intel_sdvo_set_clock_rate_mult(intel_encoder, sdvo_priv->save_sdvo_mult); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1431 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1432 | if (sdvo_priv->is_tv) { |
| 1433 | /* XXX: Restore TV format/enhancements. */ |
| 1434 | } |
| 1435 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1436 | intel_sdvo_write_sdvox(intel_encoder, sdvo_priv->save_SDVOX); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1437 | |
| 1438 | if (sdvo_priv->save_SDVOX & SDVO_ENABLE) |
| 1439 | { |
| 1440 | for (i = 0; i < 2; i++) |
| 1441 | intel_wait_for_vblank(dev); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1442 | status = intel_sdvo_get_trained_inputs(intel_encoder, &input1, &input2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1443 | if (status == SDVO_CMD_STATUS_SUCCESS && !input1) |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1444 | DRM_DEBUG_KMS("First %s output reported failure to " |
| 1445 | "sync\n", SDVO_NAME(sdvo_priv)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1448 | intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->save_active_outputs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | static int intel_sdvo_mode_valid(struct drm_connector *connector, |
| 1452 | struct drm_display_mode *mode) |
| 1453 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1454 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1455 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1456 | |
| 1457 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 1458 | return MODE_NO_DBLESCAN; |
| 1459 | |
| 1460 | if (sdvo_priv->pixel_clock_min > mode->clock) |
| 1461 | return MODE_CLOCK_LOW; |
| 1462 | |
| 1463 | if (sdvo_priv->pixel_clock_max < mode->clock) |
| 1464 | return MODE_CLOCK_HIGH; |
| 1465 | |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1466 | if (sdvo_priv->is_lvds == true) { |
| 1467 | if (sdvo_priv->sdvo_lvds_fixed_mode == NULL) |
| 1468 | return MODE_PANEL; |
| 1469 | |
| 1470 | if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay) |
| 1471 | return MODE_PANEL; |
| 1472 | |
| 1473 | if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay) |
| 1474 | return MODE_PANEL; |
| 1475 | } |
| 1476 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1477 | return MODE_OK; |
| 1478 | } |
| 1479 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1480 | static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1481 | { |
| 1482 | u8 status; |
| 1483 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1484 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0); |
| 1485 | status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1486 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 1487 | return false; |
| 1488 | |
| 1489 | return true; |
| 1490 | } |
| 1491 | |
| 1492 | struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB) |
| 1493 | { |
| 1494 | struct drm_connector *connector = NULL; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1495 | struct intel_encoder *iout = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1496 | struct intel_sdvo_priv *sdvo; |
| 1497 | |
| 1498 | /* find the sdvo connector */ |
| 1499 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1500 | iout = to_intel_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1501 | |
| 1502 | if (iout->type != INTEL_OUTPUT_SDVO) |
| 1503 | continue; |
| 1504 | |
| 1505 | sdvo = iout->dev_priv; |
| 1506 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1507 | if (sdvo->sdvo_reg == SDVOB && sdvoB) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1508 | return connector; |
| 1509 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 1510 | if (sdvo->sdvo_reg == SDVOC && !sdvoB) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1511 | return connector; |
| 1512 | |
| 1513 | } |
| 1514 | |
| 1515 | return NULL; |
| 1516 | } |
| 1517 | |
| 1518 | int intel_sdvo_supports_hotplug(struct drm_connector *connector) |
| 1519 | { |
| 1520 | u8 response[2]; |
| 1521 | u8 status; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1522 | struct intel_encoder *intel_encoder; |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1523 | DRM_DEBUG_KMS("\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1524 | |
| 1525 | if (!connector) |
| 1526 | return 0; |
| 1527 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1528 | intel_encoder = to_intel_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1529 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1530 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); |
| 1531 | status = intel_sdvo_read_response(intel_encoder, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1532 | |
| 1533 | if (response[0] !=0) |
| 1534 | return 1; |
| 1535 | |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | void intel_sdvo_set_hotplug(struct drm_connector *connector, int on) |
| 1540 | { |
| 1541 | u8 response[2]; |
| 1542 | u8 status; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1543 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1544 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1545 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); |
| 1546 | intel_sdvo_read_response(intel_encoder, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1547 | |
| 1548 | if (on) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1549 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); |
| 1550 | status = intel_sdvo_read_response(intel_encoder, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1551 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1552 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1553 | } else { |
| 1554 | response[0] = 0; |
| 1555 | response[1] = 0; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1556 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1559 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); |
| 1560 | intel_sdvo_read_response(intel_encoder, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1563 | static bool |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1564 | intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder) |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1565 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1566 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1567 | int caps = 0; |
| 1568 | |
| 1569 | if (sdvo_priv->caps.output_flags & |
| 1570 | (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) |
| 1571 | caps++; |
| 1572 | if (sdvo_priv->caps.output_flags & |
| 1573 | (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)) |
| 1574 | caps++; |
| 1575 | if (sdvo_priv->caps.output_flags & |
Roel Kluin | 19e1f88 | 2009-08-09 13:50:53 +0200 | [diff] [blame] | 1576 | (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1)) |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1577 | caps++; |
| 1578 | if (sdvo_priv->caps.output_flags & |
| 1579 | (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1)) |
| 1580 | caps++; |
| 1581 | if (sdvo_priv->caps.output_flags & |
| 1582 | (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1)) |
| 1583 | caps++; |
| 1584 | |
| 1585 | if (sdvo_priv->caps.output_flags & |
| 1586 | (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1)) |
| 1587 | caps++; |
| 1588 | |
| 1589 | if (sdvo_priv->caps.output_flags & |
| 1590 | (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)) |
| 1591 | caps++; |
| 1592 | |
| 1593 | return (caps > 1); |
| 1594 | } |
| 1595 | |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1596 | static struct drm_connector * |
| 1597 | intel_find_analog_connector(struct drm_device *dev) |
| 1598 | { |
| 1599 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1600 | struct intel_encoder *intel_encoder; |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1601 | |
| 1602 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1603 | intel_encoder = to_intel_encoder(connector); |
| 1604 | if (intel_encoder->type == INTEL_OUTPUT_ANALOG) |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1605 | return connector; |
| 1606 | } |
| 1607 | return NULL; |
| 1608 | } |
| 1609 | |
| 1610 | static int |
| 1611 | intel_analog_is_connected(struct drm_device *dev) |
| 1612 | { |
| 1613 | struct drm_connector *analog_connector; |
| 1614 | analog_connector = intel_find_analog_connector(dev); |
| 1615 | |
| 1616 | if (!analog_connector) |
| 1617 | return false; |
| 1618 | |
| 1619 | if (analog_connector->funcs->detect(analog_connector) == |
| 1620 | connector_status_disconnected) |
| 1621 | return false; |
| 1622 | |
| 1623 | return true; |
| 1624 | } |
| 1625 | |
ling.ma@intel.com | 2b8d33f7 | 2009-07-29 11:31:18 +0800 | [diff] [blame] | 1626 | enum drm_connector_status |
| 1627 | intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 1628 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1629 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1630 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
ling.ma@intel.com | 2b8d33f7 | 2009-07-29 11:31:18 +0800 | [diff] [blame] | 1631 | enum drm_connector_status status = connector_status_connected; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 1632 | struct edid *edid = NULL; |
| 1633 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1634 | edid = drm_get_edid(&intel_encoder->base, |
| 1635 | intel_encoder->ddc_bus); |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1636 | |
Zhao Yakui | 7c3f0a2 | 2010-01-08 10:58:20 +0800 | [diff] [blame] | 1637 | /* This is only applied to SDVO cards with multiple outputs */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1638 | if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) { |
Zhao Yakui | 7c3f0a2 | 2010-01-08 10:58:20 +0800 | [diff] [blame] | 1639 | uint8_t saved_ddc, temp_ddc; |
| 1640 | saved_ddc = sdvo_priv->ddc_bus; |
| 1641 | temp_ddc = sdvo_priv->ddc_bus >> 1; |
| 1642 | /* |
| 1643 | * Don't use the 1 as the argument of DDC bus switch to get |
| 1644 | * the EDID. It is used for SDVO SPD ROM. |
| 1645 | */ |
| 1646 | while(temp_ddc > 1) { |
| 1647 | sdvo_priv->ddc_bus = temp_ddc; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1648 | edid = drm_get_edid(&intel_encoder->base, |
| 1649 | intel_encoder->ddc_bus); |
Zhao Yakui | 7c3f0a2 | 2010-01-08 10:58:20 +0800 | [diff] [blame] | 1650 | if (edid) { |
| 1651 | /* |
| 1652 | * When we can get the EDID, maybe it is the |
| 1653 | * correct DDC bus. Update it. |
| 1654 | */ |
| 1655 | sdvo_priv->ddc_bus = temp_ddc; |
| 1656 | break; |
| 1657 | } |
| 1658 | temp_ddc >>= 1; |
| 1659 | } |
| 1660 | if (edid == NULL) |
| 1661 | sdvo_priv->ddc_bus = saved_ddc; |
| 1662 | } |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1663 | /* when there is no edid and no monitor is connected with VGA |
| 1664 | * port, try to use the CRT ddc to read the EDID for DVI-connector |
| 1665 | */ |
| 1666 | if (edid == NULL && |
| 1667 | sdvo_priv->analog_ddc_bus && |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1668 | !intel_analog_is_connected(intel_encoder->base.dev)) |
| 1669 | edid = drm_get_edid(&intel_encoder->base, |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1670 | sdvo_priv->analog_ddc_bus); |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 1671 | if (edid != NULL) { |
ling.ma@intel.com | 2b8d33f7 | 2009-07-29 11:31:18 +0800 | [diff] [blame] | 1672 | /* Don't report the output as connected if it's a DVI-I |
| 1673 | * connector with a non-digital EDID coming out. |
| 1674 | */ |
| 1675 | if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) { |
| 1676 | if (edid->input & DRM_EDID_INPUT_DIGITAL) |
| 1677 | sdvo_priv->is_hdmi = |
| 1678 | drm_detect_hdmi_monitor(edid); |
| 1679 | else |
| 1680 | status = connector_status_disconnected; |
| 1681 | } |
| 1682 | |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 1683 | kfree(edid); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1684 | intel_encoder->base.display_info.raw_edid = NULL; |
ling.ma@intel.com | 2b8d33f7 | 2009-07-29 11:31:18 +0800 | [diff] [blame] | 1685 | |
| 1686 | } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) |
| 1687 | status = connector_status_disconnected; |
| 1688 | |
| 1689 | return status; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 1690 | } |
| 1691 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1692 | static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector) |
| 1693 | { |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1694 | uint16_t response; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1695 | u8 status; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1696 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1697 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1698 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1699 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1700 | SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0); |
Zhao Yakui | d09c23d | 2009-11-06 15:39:56 +0800 | [diff] [blame] | 1701 | if (sdvo_priv->is_tv) { |
| 1702 | /* add 30ms delay when the output type is SDVO-TV */ |
| 1703 | mdelay(30); |
| 1704 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1705 | status = intel_sdvo_read_response(intel_encoder, &response, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1706 | |
Dave Airlie | 51c8b40 | 2009-08-20 13:38:04 +1000 | [diff] [blame] | 1707 | DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1708 | |
| 1709 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 1710 | return connector_status_unknown; |
| 1711 | |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1712 | if (response == 0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1713 | return connector_status_disconnected; |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1714 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1715 | if (intel_sdvo_multifunc_encoder(intel_encoder) && |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1716 | sdvo_priv->attached_output != response) { |
| 1717 | if (sdvo_priv->controlled_output != response && |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1718 | intel_sdvo_output_setup(intel_encoder, response) != true) |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 1719 | return connector_status_unknown; |
| 1720 | sdvo_priv->attached_output = response; |
| 1721 | } |
ling.ma@intel.com | 2b8d33f7 | 2009-07-29 11:31:18 +0800 | [diff] [blame] | 1722 | return intel_sdvo_hdmi_sink_detect(connector, response); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1723 | } |
| 1724 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1725 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1726 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1727 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1728 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1729 | int num_modes; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1730 | |
| 1731 | /* set the bus switch and get the modes */ |
Zhenyu Wang | 335af9a | 2010-03-30 14:39:31 +0800 | [diff] [blame^] | 1732 | num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1733 | |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1734 | /* |
| 1735 | * Mac mini hack. On this device, the DVI-I connector shares one DDC |
| 1736 | * link between analog and digital outputs. So, if the regular SDVO |
| 1737 | * DDC fails, check to see if the analog output is disconnected, in |
| 1738 | * which case we'll look there for the digital DDC data. |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1739 | */ |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1740 | if (num_modes == 0 && |
| 1741 | sdvo_priv->analog_ddc_bus && |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1742 | !intel_analog_is_connected(intel_encoder->base.dev)) { |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1743 | /* Switch to the analog ddc bus and try that |
| 1744 | */ |
Zhenyu Wang | 335af9a | 2010-03-30 14:39:31 +0800 | [diff] [blame^] | 1745 | (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1746 | } |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | /* |
| 1750 | * Set of SDVO TV modes. |
| 1751 | * Note! This is in reply order (see loop in get_tv_modes). |
| 1752 | * XXX: all 60Hz refresh? |
| 1753 | */ |
| 1754 | struct drm_display_mode sdvo_tv_modes[] = { |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1755 | { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384, |
| 1756 | 416, 0, 200, 201, 232, 233, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1757 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1758 | { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384, |
| 1759 | 416, 0, 240, 241, 272, 273, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1760 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1761 | { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464, |
| 1762 | 496, 0, 300, 301, 332, 333, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1763 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1764 | { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704, |
| 1765 | 736, 0, 350, 351, 382, 383, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1766 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1767 | { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704, |
| 1768 | 736, 0, 400, 401, 432, 433, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1769 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1770 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704, |
| 1771 | 736, 0, 480, 481, 512, 513, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1772 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1773 | { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768, |
| 1774 | 800, 0, 480, 481, 512, 513, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1775 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1776 | { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768, |
| 1777 | 800, 0, 576, 577, 608, 609, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1778 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1779 | { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784, |
| 1780 | 816, 0, 350, 351, 382, 383, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1781 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1782 | { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784, |
| 1783 | 816, 0, 400, 401, 432, 433, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1784 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1785 | { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784, |
| 1786 | 816, 0, 480, 481, 512, 513, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1787 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1788 | { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784, |
| 1789 | 816, 0, 540, 541, 572, 573, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1790 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1791 | { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784, |
| 1792 | 816, 0, 576, 577, 608, 609, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1793 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1794 | { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832, |
| 1795 | 864, 0, 576, 577, 608, 609, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1796 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1797 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864, |
| 1798 | 896, 0, 600, 601, 632, 633, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1799 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1800 | { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896, |
| 1801 | 928, 0, 624, 625, 656, 657, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1802 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1803 | { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984, |
| 1804 | 1016, 0, 766, 767, 798, 799, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1805 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1806 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088, |
| 1807 | 1120, 0, 768, 769, 800, 801, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1808 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1809 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344, |
| 1810 | 1376, 0, 1024, 1025, 1056, 1057, 0, |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1811 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1812 | }; |
| 1813 | |
| 1814 | static void intel_sdvo_get_tv_modes(struct drm_connector *connector) |
| 1815 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1816 | struct intel_encoder *output = to_intel_encoder(connector); |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1817 | struct intel_sdvo_priv *sdvo_priv = output->dev_priv; |
| 1818 | struct intel_sdvo_sdtv_resolution_request tv_res; |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1819 | uint32_t reply = 0, format_map = 0; |
| 1820 | int i; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1821 | uint8_t status; |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1822 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1823 | |
| 1824 | /* Read the list of supported input resolutions for the selected TV |
| 1825 | * format. |
| 1826 | */ |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1827 | for (i = 0; i < TV_FORMAT_NUM; i++) |
| 1828 | if (tv_format_names[i] == sdvo_priv->tv_format_name) |
| 1829 | break; |
| 1830 | |
| 1831 | format_map = (1 << i); |
| 1832 | memcpy(&tv_res, &format_map, |
| 1833 | sizeof(struct intel_sdvo_sdtv_resolution_request) > |
| 1834 | sizeof(format_map) ? sizeof(format_map) : |
| 1835 | sizeof(struct intel_sdvo_sdtv_resolution_request)); |
| 1836 | |
| 1837 | intel_sdvo_set_target_output(output, sdvo_priv->controlled_output); |
| 1838 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1839 | intel_sdvo_write_cmd(output, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1840 | &tv_res, sizeof(tv_res)); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1841 | status = intel_sdvo_read_response(output, &reply, 3); |
| 1842 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 1843 | return; |
| 1844 | |
| 1845 | for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++) |
Zhenyu Wang | 7026d4a | 2009-03-24 14:02:43 +0800 | [diff] [blame] | 1846 | if (reply & (1 << i)) { |
| 1847 | struct drm_display_mode *nmode; |
| 1848 | nmode = drm_mode_duplicate(connector->dev, |
| 1849 | &sdvo_tv_modes[i]); |
| 1850 | if (nmode) |
| 1851 | drm_mode_probed_add(connector, nmode); |
| 1852 | } |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1853 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1854 | } |
| 1855 | |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1856 | static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) |
| 1857 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1858 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1859 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1860 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1861 | struct drm_display_mode *newmode; |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1862 | |
| 1863 | /* |
| 1864 | * Attempt to get the mode list from DDC. |
| 1865 | * Assume that the preferred modes are |
| 1866 | * arranged in priority order. |
| 1867 | */ |
Zhenyu Wang | 335af9a | 2010-03-30 14:39:31 +0800 | [diff] [blame^] | 1868 | intel_ddc_get_modes(connector, intel_encoder->ddc_bus); |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1869 | if (list_empty(&connector->probed_modes) == false) |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1870 | goto end; |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1871 | |
| 1872 | /* Fetch modes from VBT */ |
| 1873 | if (dev_priv->sdvo_lvds_vbt_mode != NULL) { |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1874 | newmode = drm_mode_duplicate(connector->dev, |
| 1875 | dev_priv->sdvo_lvds_vbt_mode); |
| 1876 | if (newmode != NULL) { |
| 1877 | /* Guarantee the mode is preferred */ |
| 1878 | newmode->type = (DRM_MODE_TYPE_PREFERRED | |
| 1879 | DRM_MODE_TYPE_DRIVER); |
| 1880 | drm_mode_probed_add(connector, newmode); |
| 1881 | } |
| 1882 | } |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1883 | |
| 1884 | end: |
| 1885 | list_for_each_entry(newmode, &connector->probed_modes, head) { |
| 1886 | if (newmode->type & DRM_MODE_TYPE_PREFERRED) { |
| 1887 | sdvo_priv->sdvo_lvds_fixed_mode = |
| 1888 | drm_mode_duplicate(connector->dev, newmode); |
| 1889 | break; |
| 1890 | } |
| 1891 | } |
| 1892 | |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1893 | } |
| 1894 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1895 | static int intel_sdvo_get_modes(struct drm_connector *connector) |
| 1896 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1897 | struct intel_encoder *output = to_intel_encoder(connector); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1898 | struct intel_sdvo_priv *sdvo_priv = output->dev_priv; |
| 1899 | |
| 1900 | if (sdvo_priv->is_tv) |
| 1901 | intel_sdvo_get_tv_modes(connector); |
Ma Ling | 7086c87 | 2009-05-13 11:20:06 +0800 | [diff] [blame] | 1902 | else if (sdvo_priv->is_lvds == true) |
| 1903 | intel_sdvo_get_lvds_modes(connector); |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 1904 | else |
| 1905 | intel_sdvo_get_ddc_modes(connector); |
| 1906 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1907 | if (list_empty(&connector->probed_modes)) |
| 1908 | return 0; |
| 1909 | return 1; |
| 1910 | } |
| 1911 | |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 1912 | static |
| 1913 | void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) |
| 1914 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1915 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1916 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 1917 | struct drm_device *dev = connector->dev; |
| 1918 | |
| 1919 | if (sdvo_priv->is_tv) { |
| 1920 | if (sdvo_priv->left_property) |
| 1921 | drm_property_destroy(dev, sdvo_priv->left_property); |
| 1922 | if (sdvo_priv->right_property) |
| 1923 | drm_property_destroy(dev, sdvo_priv->right_property); |
| 1924 | if (sdvo_priv->top_property) |
| 1925 | drm_property_destroy(dev, sdvo_priv->top_property); |
| 1926 | if (sdvo_priv->bottom_property) |
| 1927 | drm_property_destroy(dev, sdvo_priv->bottom_property); |
| 1928 | if (sdvo_priv->hpos_property) |
| 1929 | drm_property_destroy(dev, sdvo_priv->hpos_property); |
| 1930 | if (sdvo_priv->vpos_property) |
| 1931 | drm_property_destroy(dev, sdvo_priv->vpos_property); |
| 1932 | } |
| 1933 | if (sdvo_priv->is_tv) { |
| 1934 | if (sdvo_priv->saturation_property) |
| 1935 | drm_property_destroy(dev, |
| 1936 | sdvo_priv->saturation_property); |
| 1937 | if (sdvo_priv->contrast_property) |
| 1938 | drm_property_destroy(dev, |
| 1939 | sdvo_priv->contrast_property); |
| 1940 | if (sdvo_priv->hue_property) |
| 1941 | drm_property_destroy(dev, sdvo_priv->hue_property); |
| 1942 | } |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 1943 | if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 1944 | if (sdvo_priv->brightness_property) |
| 1945 | drm_property_destroy(dev, |
| 1946 | sdvo_priv->brightness_property); |
| 1947 | } |
| 1948 | return; |
| 1949 | } |
| 1950 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1951 | static void intel_sdvo_destroy(struct drm_connector *connector) |
| 1952 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1953 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1954 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1955 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1956 | if (intel_encoder->i2c_bus) |
| 1957 | intel_i2c_destroy(intel_encoder->i2c_bus); |
| 1958 | if (intel_encoder->ddc_bus) |
| 1959 | intel_i2c_destroy(intel_encoder->ddc_bus); |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 1960 | if (sdvo_priv->analog_ddc_bus) |
| 1961 | intel_i2c_destroy(sdvo_priv->analog_ddc_bus); |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 1962 | |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1963 | if (sdvo_priv->sdvo_lvds_fixed_mode != NULL) |
| 1964 | drm_mode_destroy(connector->dev, |
| 1965 | sdvo_priv->sdvo_lvds_fixed_mode); |
| 1966 | |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1967 | if (sdvo_priv->tv_format_property) |
| 1968 | drm_property_destroy(connector->dev, |
| 1969 | sdvo_priv->tv_format_property); |
| 1970 | |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 1971 | if (sdvo_priv->is_tv || sdvo_priv->is_lvds) |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 1972 | intel_sdvo_destroy_enhance_property(connector); |
| 1973 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1974 | drm_sysfs_connector_remove(connector); |
| 1975 | drm_connector_cleanup(connector); |
ling.ma@intel.com | 12682a9 | 2009-06-30 11:35:35 +0800 | [diff] [blame] | 1976 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1977 | kfree(intel_encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1980 | static int |
| 1981 | intel_sdvo_set_property(struct drm_connector *connector, |
| 1982 | struct drm_property *property, |
| 1983 | uint64_t val) |
| 1984 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1985 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 1986 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
| 1987 | struct drm_encoder *encoder = &intel_encoder->enc; |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1988 | struct drm_crtc *crtc = encoder->crtc; |
| 1989 | int ret = 0; |
| 1990 | bool changed = false; |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 1991 | uint8_t cmd, status; |
| 1992 | uint16_t temp_value; |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 1993 | |
| 1994 | ret = drm_connector_property_set_value(connector, property, val); |
| 1995 | if (ret < 0) |
| 1996 | goto out; |
| 1997 | |
| 1998 | if (property == sdvo_priv->tv_format_property) { |
| 1999 | if (val >= TV_FORMAT_NUM) { |
| 2000 | ret = -EINVAL; |
| 2001 | goto out; |
| 2002 | } |
| 2003 | if (sdvo_priv->tv_format_name == |
| 2004 | sdvo_priv->tv_format_supported[val]) |
| 2005 | goto out; |
| 2006 | |
| 2007 | sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[val]; |
| 2008 | changed = true; |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2009 | } |
| 2010 | |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 2011 | if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2012 | cmd = 0; |
| 2013 | temp_value = val; |
| 2014 | if (sdvo_priv->left_property == property) { |
| 2015 | drm_connector_property_set_value(connector, |
| 2016 | sdvo_priv->right_property, val); |
| 2017 | if (sdvo_priv->left_margin == temp_value) |
| 2018 | goto out; |
| 2019 | |
| 2020 | sdvo_priv->left_margin = temp_value; |
| 2021 | sdvo_priv->right_margin = temp_value; |
| 2022 | temp_value = sdvo_priv->max_hscan - |
| 2023 | sdvo_priv->left_margin; |
| 2024 | cmd = SDVO_CMD_SET_OVERSCAN_H; |
| 2025 | } else if (sdvo_priv->right_property == property) { |
| 2026 | drm_connector_property_set_value(connector, |
| 2027 | sdvo_priv->left_property, val); |
| 2028 | if (sdvo_priv->right_margin == temp_value) |
| 2029 | goto out; |
| 2030 | |
| 2031 | sdvo_priv->left_margin = temp_value; |
| 2032 | sdvo_priv->right_margin = temp_value; |
| 2033 | temp_value = sdvo_priv->max_hscan - |
| 2034 | sdvo_priv->left_margin; |
| 2035 | cmd = SDVO_CMD_SET_OVERSCAN_H; |
| 2036 | } else if (sdvo_priv->top_property == property) { |
| 2037 | drm_connector_property_set_value(connector, |
| 2038 | sdvo_priv->bottom_property, val); |
| 2039 | if (sdvo_priv->top_margin == temp_value) |
| 2040 | goto out; |
| 2041 | |
| 2042 | sdvo_priv->top_margin = temp_value; |
| 2043 | sdvo_priv->bottom_margin = temp_value; |
| 2044 | temp_value = sdvo_priv->max_vscan - |
| 2045 | sdvo_priv->top_margin; |
| 2046 | cmd = SDVO_CMD_SET_OVERSCAN_V; |
| 2047 | } else if (sdvo_priv->bottom_property == property) { |
| 2048 | drm_connector_property_set_value(connector, |
| 2049 | sdvo_priv->top_property, val); |
| 2050 | if (sdvo_priv->bottom_margin == temp_value) |
| 2051 | goto out; |
| 2052 | sdvo_priv->top_margin = temp_value; |
| 2053 | sdvo_priv->bottom_margin = temp_value; |
| 2054 | temp_value = sdvo_priv->max_vscan - |
| 2055 | sdvo_priv->top_margin; |
| 2056 | cmd = SDVO_CMD_SET_OVERSCAN_V; |
| 2057 | } else if (sdvo_priv->hpos_property == property) { |
| 2058 | if (sdvo_priv->cur_hpos == temp_value) |
| 2059 | goto out; |
| 2060 | |
| 2061 | cmd = SDVO_CMD_SET_POSITION_H; |
| 2062 | sdvo_priv->cur_hpos = temp_value; |
| 2063 | } else if (sdvo_priv->vpos_property == property) { |
| 2064 | if (sdvo_priv->cur_vpos == temp_value) |
| 2065 | goto out; |
| 2066 | |
| 2067 | cmd = SDVO_CMD_SET_POSITION_V; |
| 2068 | sdvo_priv->cur_vpos = temp_value; |
| 2069 | } else if (sdvo_priv->saturation_property == property) { |
| 2070 | if (sdvo_priv->cur_saturation == temp_value) |
| 2071 | goto out; |
| 2072 | |
| 2073 | cmd = SDVO_CMD_SET_SATURATION; |
| 2074 | sdvo_priv->cur_saturation = temp_value; |
| 2075 | } else if (sdvo_priv->contrast_property == property) { |
| 2076 | if (sdvo_priv->cur_contrast == temp_value) |
| 2077 | goto out; |
| 2078 | |
| 2079 | cmd = SDVO_CMD_SET_CONTRAST; |
| 2080 | sdvo_priv->cur_contrast = temp_value; |
| 2081 | } else if (sdvo_priv->hue_property == property) { |
| 2082 | if (sdvo_priv->cur_hue == temp_value) |
| 2083 | goto out; |
| 2084 | |
| 2085 | cmd = SDVO_CMD_SET_HUE; |
| 2086 | sdvo_priv->cur_hue = temp_value; |
| 2087 | } else if (sdvo_priv->brightness_property == property) { |
| 2088 | if (sdvo_priv->cur_brightness == temp_value) |
| 2089 | goto out; |
| 2090 | |
| 2091 | cmd = SDVO_CMD_SET_BRIGHTNESS; |
| 2092 | sdvo_priv->cur_brightness = temp_value; |
| 2093 | } |
| 2094 | if (cmd) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2095 | intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2); |
| 2096 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2097 | NULL, 0); |
| 2098 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2099 | DRM_DEBUG_KMS("Incorrect SDVO command \n"); |
| 2100 | return -EINVAL; |
| 2101 | } |
| 2102 | changed = true; |
| 2103 | } |
| 2104 | } |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2105 | if (changed && crtc) |
| 2106 | drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, |
| 2107 | crtc->y, crtc->fb); |
| 2108 | out: |
| 2109 | return ret; |
| 2110 | } |
| 2111 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2112 | static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = { |
| 2113 | .dpms = intel_sdvo_dpms, |
| 2114 | .mode_fixup = intel_sdvo_mode_fixup, |
| 2115 | .prepare = intel_encoder_prepare, |
| 2116 | .mode_set = intel_sdvo_mode_set, |
| 2117 | .commit = intel_encoder_commit, |
| 2118 | }; |
| 2119 | |
| 2120 | static const struct drm_connector_funcs intel_sdvo_connector_funcs = { |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 2121 | .dpms = drm_helper_connector_dpms, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2122 | .save = intel_sdvo_save, |
| 2123 | .restore = intel_sdvo_restore, |
| 2124 | .detect = intel_sdvo_detect, |
| 2125 | .fill_modes = drm_helper_probe_single_connector_modes, |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2126 | .set_property = intel_sdvo_set_property, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2127 | .destroy = intel_sdvo_destroy, |
| 2128 | }; |
| 2129 | |
| 2130 | static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { |
| 2131 | .get_modes = intel_sdvo_get_modes, |
| 2132 | .mode_valid = intel_sdvo_mode_valid, |
| 2133 | .best_encoder = intel_best_encoder, |
| 2134 | }; |
| 2135 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 2136 | static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2137 | { |
| 2138 | drm_encoder_cleanup(encoder); |
| 2139 | } |
| 2140 | |
| 2141 | static const struct drm_encoder_funcs intel_sdvo_enc_funcs = { |
| 2142 | .destroy = intel_sdvo_enc_destroy, |
| 2143 | }; |
| 2144 | |
| 2145 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 2146 | /** |
| 2147 | * Choose the appropriate DDC bus for control bus switch command for this |
| 2148 | * SDVO output based on the controlled output. |
| 2149 | * |
| 2150 | * DDC bus number assignment is in a priority order of RGB outputs, then TMDS |
| 2151 | * outputs, then LVDS outputs. |
| 2152 | */ |
| 2153 | static void |
| 2154 | intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv) |
| 2155 | { |
| 2156 | uint16_t mask = 0; |
| 2157 | unsigned int num_bits; |
| 2158 | |
| 2159 | /* Make a mask of outputs less than or equal to our own priority in the |
| 2160 | * list. |
| 2161 | */ |
| 2162 | switch (dev_priv->controlled_output) { |
| 2163 | case SDVO_OUTPUT_LVDS1: |
| 2164 | mask |= SDVO_OUTPUT_LVDS1; |
| 2165 | case SDVO_OUTPUT_LVDS0: |
| 2166 | mask |= SDVO_OUTPUT_LVDS0; |
| 2167 | case SDVO_OUTPUT_TMDS1: |
| 2168 | mask |= SDVO_OUTPUT_TMDS1; |
| 2169 | case SDVO_OUTPUT_TMDS0: |
| 2170 | mask |= SDVO_OUTPUT_TMDS0; |
| 2171 | case SDVO_OUTPUT_RGB1: |
| 2172 | mask |= SDVO_OUTPUT_RGB1; |
| 2173 | case SDVO_OUTPUT_RGB0: |
| 2174 | mask |= SDVO_OUTPUT_RGB0; |
| 2175 | break; |
| 2176 | } |
| 2177 | |
| 2178 | /* Count bits to find what number we are in the priority list. */ |
| 2179 | mask &= dev_priv->caps.output_flags; |
| 2180 | num_bits = hweight16(mask); |
| 2181 | if (num_bits > 3) { |
| 2182 | /* if more than 3 outputs, default to DDC bus 3 for now */ |
| 2183 | num_bits = 3; |
| 2184 | } |
| 2185 | |
| 2186 | /* Corresponds to SDVO_CONTROL_BUS_DDCx */ |
| 2187 | dev_priv->ddc_bus = 1 << num_bits; |
| 2188 | } |
| 2189 | |
| 2190 | static bool |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2191 | intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 2192 | { |
| 2193 | struct intel_sdvo_priv *sdvo_priv = output->dev_priv; |
| 2194 | uint8_t status; |
| 2195 | |
| 2196 | intel_sdvo_set_target_output(output, sdvo_priv->controlled_output); |
| 2197 | |
| 2198 | intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0); |
| 2199 | status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1); |
| 2200 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 2201 | return false; |
| 2202 | return true; |
| 2203 | } |
| 2204 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2205 | static struct intel_encoder * |
| 2206 | intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan) |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2207 | { |
| 2208 | struct drm_device *dev = chan->drm_dev; |
| 2209 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2210 | struct intel_encoder *intel_encoder = NULL; |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2211 | |
| 2212 | list_for_each_entry(connector, |
| 2213 | &dev->mode_config.connector_list, head) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2214 | if (to_intel_encoder(connector)->ddc_bus == &chan->adapter) { |
| 2215 | intel_encoder = to_intel_encoder(connector); |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2216 | break; |
| 2217 | } |
| 2218 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2219 | return intel_encoder; |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, |
| 2223 | struct i2c_msg msgs[], int num) |
| 2224 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2225 | struct intel_encoder *intel_encoder; |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2226 | struct intel_sdvo_priv *sdvo_priv; |
| 2227 | struct i2c_algo_bit_data *algo_data; |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 2228 | const struct i2c_algorithm *algo; |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2229 | |
| 2230 | algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2231 | intel_encoder = |
| 2232 | intel_sdvo_chan_to_intel_encoder( |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2233 | (struct intel_i2c_chan *)(algo_data->data)); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2234 | if (intel_encoder == NULL) |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2235 | return -EINVAL; |
| 2236 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2237 | sdvo_priv = intel_encoder->dev_priv; |
| 2238 | algo = intel_encoder->i2c_bus->algo; |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2239 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2240 | intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus); |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2241 | return algo->master_xfer(i2c_adap, msgs, num); |
| 2242 | } |
| 2243 | |
| 2244 | static struct i2c_algorithm intel_sdvo_i2c_bit_algo = { |
| 2245 | .master_xfer = intel_sdvo_master_xfer, |
| 2246 | }; |
| 2247 | |
yakui_zhao | 714605e | 2009-05-31 17:18:07 +0800 | [diff] [blame] | 2248 | static u8 |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2249 | intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) |
yakui_zhao | 714605e | 2009-05-31 17:18:07 +0800 | [diff] [blame] | 2250 | { |
| 2251 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2252 | struct sdvo_device_mapping *my_mapping, *other_mapping; |
| 2253 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2254 | if (sdvo_reg == SDVOB) { |
yakui_zhao | 714605e | 2009-05-31 17:18:07 +0800 | [diff] [blame] | 2255 | my_mapping = &dev_priv->sdvo_mappings[0]; |
| 2256 | other_mapping = &dev_priv->sdvo_mappings[1]; |
| 2257 | } else { |
| 2258 | my_mapping = &dev_priv->sdvo_mappings[1]; |
| 2259 | other_mapping = &dev_priv->sdvo_mappings[0]; |
| 2260 | } |
| 2261 | |
| 2262 | /* If the BIOS described our SDVO device, take advantage of it. */ |
| 2263 | if (my_mapping->slave_addr) |
| 2264 | return my_mapping->slave_addr; |
| 2265 | |
| 2266 | /* If the BIOS only described a different SDVO device, use the |
| 2267 | * address that it isn't using. |
| 2268 | */ |
| 2269 | if (other_mapping->slave_addr) { |
| 2270 | if (other_mapping->slave_addr == 0x70) |
| 2271 | return 0x72; |
| 2272 | else |
| 2273 | return 0x70; |
| 2274 | } |
| 2275 | |
| 2276 | /* No SDVO device info is found for another DVO port, |
| 2277 | * so use mapping assumption we had before BIOS parsing. |
| 2278 | */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2279 | if (sdvo_reg == SDVOB) |
yakui_zhao | 714605e | 2009-05-31 17:18:07 +0800 | [diff] [blame] | 2280 | return 0x70; |
| 2281 | else |
| 2282 | return 0x72; |
| 2283 | } |
| 2284 | |
Zhao Yakui | 6070a4a | 2010-02-08 21:35:12 +0800 | [diff] [blame] | 2285 | static int intel_sdvo_bad_tv_callback(const struct dmi_system_id *id) |
| 2286 | { |
| 2287 | DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id->ident); |
| 2288 | return 1; |
| 2289 | } |
| 2290 | |
| 2291 | static struct dmi_system_id intel_sdvo_bad_tv[] = { |
| 2292 | { |
| 2293 | .callback = intel_sdvo_bad_tv_callback, |
| 2294 | .ident = "IntelG45/ICH10R/DME1737", |
| 2295 | .matches = { |
| 2296 | DMI_MATCH(DMI_SYS_VENDOR, "IBM CORPORATION"), |
| 2297 | DMI_MATCH(DMI_PRODUCT_NAME, "4800784"), |
| 2298 | }, |
| 2299 | }, |
| 2300 | |
| 2301 | { } /* terminating entry */ |
| 2302 | }; |
| 2303 | |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2304 | static bool |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2305 | intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags) |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2306 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2307 | struct drm_connector *connector = &intel_encoder->base; |
| 2308 | struct drm_encoder *encoder = &intel_encoder->enc; |
| 2309 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2310 | bool ret = true, registered = false; |
| 2311 | |
| 2312 | sdvo_priv->is_tv = false; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2313 | intel_encoder->needs_tv_clock = false; |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2314 | sdvo_priv->is_lvds = false; |
| 2315 | |
| 2316 | if (device_is_registered(&connector->kdev)) { |
| 2317 | drm_sysfs_connector_remove(connector); |
| 2318 | registered = true; |
| 2319 | } |
| 2320 | |
| 2321 | if (flags & |
| 2322 | (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) { |
| 2323 | if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0) |
| 2324 | sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0; |
| 2325 | else |
| 2326 | sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1; |
| 2327 | |
| 2328 | encoder->encoder_type = DRM_MODE_ENCODER_TMDS; |
| 2329 | connector->connector_type = DRM_MODE_CONNECTOR_DVID; |
| 2330 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2331 | if (intel_sdvo_get_supp_encode(intel_encoder, |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2332 | &sdvo_priv->encode) && |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2333 | intel_sdvo_get_digital_encoding_mode(intel_encoder) && |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2334 | sdvo_priv->is_hdmi) { |
| 2335 | /* enable hdmi encoding mode if supported */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2336 | intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI); |
| 2337 | intel_sdvo_set_colorimetry(intel_encoder, |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2338 | SDVO_COLORIMETRY_RGB256); |
| 2339 | connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2340 | intel_encoder->clone_mask = |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 2341 | (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
| 2342 | (1 << INTEL_ANALOG_CLONE_BIT); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2343 | } |
Zhao Yakui | 6070a4a | 2010-02-08 21:35:12 +0800 | [diff] [blame] | 2344 | } else if ((flags & SDVO_OUTPUT_SVID0) && |
| 2345 | !dmi_check_system(intel_sdvo_bad_tv)) { |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2346 | |
| 2347 | sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0; |
| 2348 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; |
| 2349 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; |
| 2350 | sdvo_priv->is_tv = true; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2351 | intel_encoder->needs_tv_clock = true; |
| 2352 | intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2353 | } else if (flags & SDVO_OUTPUT_RGB0) { |
| 2354 | |
| 2355 | sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0; |
| 2356 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; |
| 2357 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2358 | intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 2359 | (1 << INTEL_ANALOG_CLONE_BIT); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2360 | } else if (flags & SDVO_OUTPUT_RGB1) { |
| 2361 | |
| 2362 | sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1; |
| 2363 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; |
| 2364 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2365 | intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | |
Zhao Yakui | e270846 | 2009-09-10 15:45:48 +0800 | [diff] [blame] | 2366 | (1 << INTEL_ANALOG_CLONE_BIT); |
Zhao Yakui | 2dd8738 | 2010-01-27 16:32:46 +0800 | [diff] [blame] | 2367 | } else if (flags & SDVO_OUTPUT_CVBS0) { |
| 2368 | |
| 2369 | sdvo_priv->controlled_output = SDVO_OUTPUT_CVBS0; |
| 2370 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; |
| 2371 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; |
| 2372 | sdvo_priv->is_tv = true; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2373 | intel_encoder->needs_tv_clock = true; |
| 2374 | intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2375 | } else if (flags & SDVO_OUTPUT_LVDS0) { |
| 2376 | |
| 2377 | sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0; |
| 2378 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; |
| 2379 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; |
| 2380 | sdvo_priv->is_lvds = true; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2381 | intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 2382 | (1 << INTEL_SDVO_LVDS_CLONE_BIT); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2383 | } else if (flags & SDVO_OUTPUT_LVDS1) { |
| 2384 | |
| 2385 | sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1; |
| 2386 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; |
| 2387 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; |
| 2388 | sdvo_priv->is_lvds = true; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2389 | intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 2390 | (1 << INTEL_SDVO_LVDS_CLONE_BIT); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2391 | } else { |
| 2392 | |
| 2393 | unsigned char bytes[2]; |
| 2394 | |
| 2395 | sdvo_priv->controlled_output = 0; |
| 2396 | memcpy(bytes, &sdvo_priv->caps.output_flags, 2); |
Dave Airlie | 51c8b40 | 2009-08-20 13:38:04 +1000 | [diff] [blame] | 2397 | DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n", |
| 2398 | SDVO_NAME(sdvo_priv), |
| 2399 | bytes[0], bytes[1]); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2400 | ret = false; |
| 2401 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2402 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2403 | |
| 2404 | if (ret && registered) |
| 2405 | ret = drm_sysfs_connector_add(connector) == 0 ? true : false; |
| 2406 | |
| 2407 | |
| 2408 | return ret; |
| 2409 | |
| 2410 | } |
| 2411 | |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2412 | static void intel_sdvo_tv_create_property(struct drm_connector *connector) |
| 2413 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2414 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 2415 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2416 | struct intel_sdvo_tv_format format; |
| 2417 | uint32_t format_map, i; |
| 2418 | uint8_t status; |
| 2419 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2420 | intel_sdvo_set_target_output(intel_encoder, |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2421 | sdvo_priv->controlled_output); |
| 2422 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2423 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2424 | SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2425 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2426 | &format, sizeof(format)); |
| 2427 | if (status != SDVO_CMD_STATUS_SUCCESS) |
| 2428 | return; |
| 2429 | |
| 2430 | memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ? |
| 2431 | sizeof(format_map) : sizeof(format)); |
| 2432 | |
| 2433 | if (format_map == 0) |
| 2434 | return; |
| 2435 | |
| 2436 | sdvo_priv->format_supported_num = 0; |
| 2437 | for (i = 0 ; i < TV_FORMAT_NUM; i++) |
| 2438 | if (format_map & (1 << i)) { |
| 2439 | sdvo_priv->tv_format_supported |
| 2440 | [sdvo_priv->format_supported_num++] = |
| 2441 | tv_format_names[i]; |
| 2442 | } |
| 2443 | |
| 2444 | |
| 2445 | sdvo_priv->tv_format_property = |
| 2446 | drm_property_create( |
| 2447 | connector->dev, DRM_MODE_PROP_ENUM, |
| 2448 | "mode", sdvo_priv->format_supported_num); |
| 2449 | |
| 2450 | for (i = 0; i < sdvo_priv->format_supported_num; i++) |
| 2451 | drm_property_add_enum( |
| 2452 | sdvo_priv->tv_format_property, i, |
| 2453 | i, sdvo_priv->tv_format_supported[i]); |
| 2454 | |
| 2455 | sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[0]; |
| 2456 | drm_connector_attach_property( |
| 2457 | connector, sdvo_priv->tv_format_property, 0); |
| 2458 | |
| 2459 | } |
| 2460 | |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2461 | static void intel_sdvo_create_enhance_property(struct drm_connector *connector) |
| 2462 | { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2463 | struct intel_encoder *intel_encoder = to_intel_encoder(connector); |
| 2464 | struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2465 | struct intel_sdvo_enhancements_reply sdvo_data; |
| 2466 | struct drm_device *dev = connector->dev; |
| 2467 | uint8_t status; |
| 2468 | uint16_t response, data_value[2]; |
| 2469 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2470 | intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2471 | NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2472 | status = intel_sdvo_read_response(intel_encoder, &sdvo_data, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2473 | sizeof(sdvo_data)); |
| 2474 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2475 | DRM_DEBUG_KMS(" incorrect response is returned\n"); |
| 2476 | return; |
| 2477 | } |
| 2478 | response = *((uint16_t *)&sdvo_data); |
| 2479 | if (!response) { |
| 2480 | DRM_DEBUG_KMS("No enhancement is supported\n"); |
| 2481 | return; |
| 2482 | } |
| 2483 | if (sdvo_priv->is_tv) { |
| 2484 | /* when horizontal overscan is supported, Add the left/right |
| 2485 | * property |
| 2486 | */ |
| 2487 | if (sdvo_data.overscan_h) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2488 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2489 | SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2490 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2491 | &data_value, 4); |
| 2492 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2493 | DRM_DEBUG_KMS("Incorrect SDVO max " |
| 2494 | "h_overscan\n"); |
| 2495 | return; |
| 2496 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2497 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2498 | SDVO_CMD_GET_OVERSCAN_H, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2499 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2500 | &response, 2); |
| 2501 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2502 | DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n"); |
| 2503 | return; |
| 2504 | } |
| 2505 | sdvo_priv->max_hscan = data_value[0]; |
| 2506 | sdvo_priv->left_margin = data_value[0] - response; |
| 2507 | sdvo_priv->right_margin = sdvo_priv->left_margin; |
| 2508 | sdvo_priv->left_property = |
| 2509 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2510 | "left_margin", 2); |
| 2511 | sdvo_priv->left_property->values[0] = 0; |
| 2512 | sdvo_priv->left_property->values[1] = data_value[0]; |
| 2513 | drm_connector_attach_property(connector, |
| 2514 | sdvo_priv->left_property, |
| 2515 | sdvo_priv->left_margin); |
| 2516 | sdvo_priv->right_property = |
| 2517 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2518 | "right_margin", 2); |
| 2519 | sdvo_priv->right_property->values[0] = 0; |
| 2520 | sdvo_priv->right_property->values[1] = data_value[0]; |
| 2521 | drm_connector_attach_property(connector, |
| 2522 | sdvo_priv->right_property, |
| 2523 | sdvo_priv->right_margin); |
| 2524 | DRM_DEBUG_KMS("h_overscan: max %d, " |
| 2525 | "default %d, current %d\n", |
| 2526 | data_value[0], data_value[1], response); |
| 2527 | } |
| 2528 | if (sdvo_data.overscan_v) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2529 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2530 | SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2531 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2532 | &data_value, 4); |
| 2533 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2534 | DRM_DEBUG_KMS("Incorrect SDVO max " |
| 2535 | "v_overscan\n"); |
| 2536 | return; |
| 2537 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2538 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2539 | SDVO_CMD_GET_OVERSCAN_V, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2540 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2541 | &response, 2); |
| 2542 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2543 | DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n"); |
| 2544 | return; |
| 2545 | } |
| 2546 | sdvo_priv->max_vscan = data_value[0]; |
| 2547 | sdvo_priv->top_margin = data_value[0] - response; |
| 2548 | sdvo_priv->bottom_margin = sdvo_priv->top_margin; |
| 2549 | sdvo_priv->top_property = |
| 2550 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2551 | "top_margin", 2); |
| 2552 | sdvo_priv->top_property->values[0] = 0; |
| 2553 | sdvo_priv->top_property->values[1] = data_value[0]; |
| 2554 | drm_connector_attach_property(connector, |
| 2555 | sdvo_priv->top_property, |
| 2556 | sdvo_priv->top_margin); |
| 2557 | sdvo_priv->bottom_property = |
| 2558 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2559 | "bottom_margin", 2); |
| 2560 | sdvo_priv->bottom_property->values[0] = 0; |
| 2561 | sdvo_priv->bottom_property->values[1] = data_value[0]; |
| 2562 | drm_connector_attach_property(connector, |
| 2563 | sdvo_priv->bottom_property, |
| 2564 | sdvo_priv->bottom_margin); |
| 2565 | DRM_DEBUG_KMS("v_overscan: max %d, " |
| 2566 | "default %d, current %d\n", |
| 2567 | data_value[0], data_value[1], response); |
| 2568 | } |
| 2569 | if (sdvo_data.position_h) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2570 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2571 | SDVO_CMD_GET_MAX_POSITION_H, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2572 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2573 | &data_value, 4); |
| 2574 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2575 | DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n"); |
| 2576 | return; |
| 2577 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2578 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2579 | SDVO_CMD_GET_POSITION_H, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2580 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2581 | &response, 2); |
| 2582 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2583 | DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n"); |
| 2584 | return; |
| 2585 | } |
| 2586 | sdvo_priv->max_hpos = data_value[0]; |
| 2587 | sdvo_priv->cur_hpos = response; |
| 2588 | sdvo_priv->hpos_property = |
| 2589 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2590 | "hpos", 2); |
| 2591 | sdvo_priv->hpos_property->values[0] = 0; |
| 2592 | sdvo_priv->hpos_property->values[1] = data_value[0]; |
| 2593 | drm_connector_attach_property(connector, |
| 2594 | sdvo_priv->hpos_property, |
| 2595 | sdvo_priv->cur_hpos); |
| 2596 | DRM_DEBUG_KMS("h_position: max %d, " |
| 2597 | "default %d, current %d\n", |
| 2598 | data_value[0], data_value[1], response); |
| 2599 | } |
| 2600 | if (sdvo_data.position_v) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2601 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2602 | SDVO_CMD_GET_MAX_POSITION_V, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2603 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2604 | &data_value, 4); |
| 2605 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2606 | DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n"); |
| 2607 | return; |
| 2608 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2609 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2610 | SDVO_CMD_GET_POSITION_V, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2611 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2612 | &response, 2); |
| 2613 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2614 | DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n"); |
| 2615 | return; |
| 2616 | } |
| 2617 | sdvo_priv->max_vpos = data_value[0]; |
| 2618 | sdvo_priv->cur_vpos = response; |
| 2619 | sdvo_priv->vpos_property = |
| 2620 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2621 | "vpos", 2); |
| 2622 | sdvo_priv->vpos_property->values[0] = 0; |
| 2623 | sdvo_priv->vpos_property->values[1] = data_value[0]; |
| 2624 | drm_connector_attach_property(connector, |
| 2625 | sdvo_priv->vpos_property, |
| 2626 | sdvo_priv->cur_vpos); |
| 2627 | DRM_DEBUG_KMS("v_position: max %d, " |
| 2628 | "default %d, current %d\n", |
| 2629 | data_value[0], data_value[1], response); |
| 2630 | } |
| 2631 | } |
| 2632 | if (sdvo_priv->is_tv) { |
| 2633 | if (sdvo_data.saturation) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2634 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2635 | SDVO_CMD_GET_MAX_SATURATION, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2636 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2637 | &data_value, 4); |
| 2638 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2639 | DRM_DEBUG_KMS("Incorrect SDVO Max sat\n"); |
| 2640 | return; |
| 2641 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2642 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2643 | SDVO_CMD_GET_SATURATION, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2644 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2645 | &response, 2); |
| 2646 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2647 | DRM_DEBUG_KMS("Incorrect SDVO get sat\n"); |
| 2648 | return; |
| 2649 | } |
| 2650 | sdvo_priv->max_saturation = data_value[0]; |
| 2651 | sdvo_priv->cur_saturation = response; |
| 2652 | sdvo_priv->saturation_property = |
| 2653 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2654 | "saturation", 2); |
| 2655 | sdvo_priv->saturation_property->values[0] = 0; |
| 2656 | sdvo_priv->saturation_property->values[1] = |
| 2657 | data_value[0]; |
| 2658 | drm_connector_attach_property(connector, |
| 2659 | sdvo_priv->saturation_property, |
| 2660 | sdvo_priv->cur_saturation); |
| 2661 | DRM_DEBUG_KMS("saturation: max %d, " |
| 2662 | "default %d, current %d\n", |
| 2663 | data_value[0], data_value[1], response); |
| 2664 | } |
| 2665 | if (sdvo_data.contrast) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2666 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2667 | SDVO_CMD_GET_MAX_CONTRAST, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2668 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2669 | &data_value, 4); |
| 2670 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2671 | DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n"); |
| 2672 | return; |
| 2673 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2674 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2675 | SDVO_CMD_GET_CONTRAST, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2676 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2677 | &response, 2); |
| 2678 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2679 | DRM_DEBUG_KMS("Incorrect SDVO get contrast\n"); |
| 2680 | return; |
| 2681 | } |
| 2682 | sdvo_priv->max_contrast = data_value[0]; |
| 2683 | sdvo_priv->cur_contrast = response; |
| 2684 | sdvo_priv->contrast_property = |
| 2685 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2686 | "contrast", 2); |
| 2687 | sdvo_priv->contrast_property->values[0] = 0; |
| 2688 | sdvo_priv->contrast_property->values[1] = data_value[0]; |
| 2689 | drm_connector_attach_property(connector, |
| 2690 | sdvo_priv->contrast_property, |
| 2691 | sdvo_priv->cur_contrast); |
| 2692 | DRM_DEBUG_KMS("contrast: max %d, " |
| 2693 | "default %d, current %d\n", |
| 2694 | data_value[0], data_value[1], response); |
| 2695 | } |
| 2696 | if (sdvo_data.hue) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2697 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2698 | SDVO_CMD_GET_MAX_HUE, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2699 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2700 | &data_value, 4); |
| 2701 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2702 | DRM_DEBUG_KMS("Incorrect SDVO Max hue\n"); |
| 2703 | return; |
| 2704 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2705 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2706 | SDVO_CMD_GET_HUE, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2707 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2708 | &response, 2); |
| 2709 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2710 | DRM_DEBUG_KMS("Incorrect SDVO get hue\n"); |
| 2711 | return; |
| 2712 | } |
| 2713 | sdvo_priv->max_hue = data_value[0]; |
| 2714 | sdvo_priv->cur_hue = response; |
| 2715 | sdvo_priv->hue_property = |
| 2716 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2717 | "hue", 2); |
| 2718 | sdvo_priv->hue_property->values[0] = 0; |
| 2719 | sdvo_priv->hue_property->values[1] = |
| 2720 | data_value[0]; |
| 2721 | drm_connector_attach_property(connector, |
| 2722 | sdvo_priv->hue_property, |
| 2723 | sdvo_priv->cur_hue); |
| 2724 | DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n", |
| 2725 | data_value[0], data_value[1], response); |
| 2726 | } |
| 2727 | } |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 2728 | if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2729 | if (sdvo_data.brightness) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2730 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2731 | SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2732 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2733 | &data_value, 4); |
| 2734 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2735 | DRM_DEBUG_KMS("Incorrect SDVO Max bright\n"); |
| 2736 | return; |
| 2737 | } |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2738 | intel_sdvo_write_cmd(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2739 | SDVO_CMD_GET_BRIGHTNESS, NULL, 0); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2740 | status = intel_sdvo_read_response(intel_encoder, |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2741 | &response, 2); |
| 2742 | if (status != SDVO_CMD_STATUS_SUCCESS) { |
| 2743 | DRM_DEBUG_KMS("Incorrect SDVO get brigh\n"); |
| 2744 | return; |
| 2745 | } |
| 2746 | sdvo_priv->max_brightness = data_value[0]; |
| 2747 | sdvo_priv->cur_brightness = response; |
| 2748 | sdvo_priv->brightness_property = |
| 2749 | drm_property_create(dev, DRM_MODE_PROP_RANGE, |
| 2750 | "brightness", 2); |
| 2751 | sdvo_priv->brightness_property->values[0] = 0; |
| 2752 | sdvo_priv->brightness_property->values[1] = |
| 2753 | data_value[0]; |
| 2754 | drm_connector_attach_property(connector, |
| 2755 | sdvo_priv->brightness_property, |
| 2756 | sdvo_priv->cur_brightness); |
| 2757 | DRM_DEBUG_KMS("brightness: max %d, " |
| 2758 | "default %d, current %d\n", |
| 2759 | data_value[0], data_value[1], response); |
| 2760 | } |
| 2761 | } |
| 2762 | return; |
| 2763 | } |
| 2764 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2765 | bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2766 | { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2767 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2768 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2769 | struct intel_encoder *intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2770 | struct intel_sdvo_priv *sdvo_priv; |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 2771 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2772 | u8 ch[0x40]; |
| 2773 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2774 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2775 | intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); |
| 2776 | if (!intel_encoder) { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 2777 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2778 | } |
| 2779 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2780 | sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2781 | sdvo_priv->sdvo_reg = sdvo_reg; |
Keith Packard | 308cd3a | 2009-06-14 11:56:18 -0700 | [diff] [blame] | 2782 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2783 | intel_encoder->dev_priv = sdvo_priv; |
| 2784 | intel_encoder->type = INTEL_OUTPUT_SDVO; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2785 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2786 | /* setup the DDC bus. */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2787 | if (sdvo_reg == SDVOB) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2788 | intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB"); |
Keith Packard | 308cd3a | 2009-06-14 11:56:18 -0700 | [diff] [blame] | 2789 | else |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2790 | intel_encoder->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC"); |
Keith Packard | 308cd3a | 2009-06-14 11:56:18 -0700 | [diff] [blame] | 2791 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2792 | if (!intel_encoder->i2c_bus) |
Jonas Bonn | ad5b2a6 | 2009-05-15 09:10:41 +0200 | [diff] [blame] | 2793 | goto err_inteloutput; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2794 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2795 | sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2796 | |
Keith Packard | 308cd3a | 2009-06-14 11:56:18 -0700 | [diff] [blame] | 2797 | /* Save the bit-banging i2c functionality for use by the DDC wrapper */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2798 | intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2799 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2800 | /* Read the regs to test if we can talk to the device */ |
| 2801 | for (i = 0; i < 0x40; i++) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2802 | if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 2803 | DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2804 | sdvo_reg == SDVOB ? 'B' : 'C'); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2805 | goto err_i2c; |
| 2806 | } |
| 2807 | } |
| 2808 | |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2809 | /* setup the DDC bus. */ |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2810 | if (sdvo_reg == SDVOB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2811 | intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS"); |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 2812 | sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA, |
| 2813 | "SDVOB/VGA DDC BUS"); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2814 | dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 2815 | } else { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2816 | intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS"); |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 2817 | sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA, |
| 2818 | "SDVOC/VGA DDC BUS"); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2819 | dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 2820 | } |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2821 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2822 | if (intel_encoder->ddc_bus == NULL) |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2823 | goto err_i2c; |
| 2824 | |
Keith Packard | 308cd3a | 2009-06-14 11:56:18 -0700 | [diff] [blame] | 2825 | /* Wrap with our custom algo which switches to DDC mode */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2826 | intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; |
Ma Ling | 619ac3b | 2009-05-18 16:12:46 +0800 | [diff] [blame] | 2827 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2828 | /* In default case sdvo lvds is false */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2829 | intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2830 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2831 | if (intel_sdvo_output_setup(intel_encoder, |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2832 | sdvo_priv->caps.output_flags) != true) { |
Dave Airlie | 51c8b40 | 2009-08-20 13:38:04 +1000 | [diff] [blame] | 2833 | DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 2834 | sdvo_reg == SDVOB ? 'B' : 'C'); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2835 | goto err_i2c; |
| 2836 | } |
| 2837 | |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2838 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2839 | connector = &intel_encoder->base; |
Jonas Bonn | ad5b2a6 | 2009-05-15 09:10:41 +0200 | [diff] [blame] | 2840 | drm_connector_init(dev, connector, &intel_sdvo_connector_funcs, |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2841 | connector->connector_type); |
| 2842 | |
Jonas Bonn | ad5b2a6 | 2009-05-15 09:10:41 +0200 | [diff] [blame] | 2843 | drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); |
| 2844 | connector->interlace_allowed = 0; |
| 2845 | connector->doublescan_allowed = 0; |
| 2846 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; |
| 2847 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2848 | drm_encoder_init(dev, &intel_encoder->enc, |
| 2849 | &intel_sdvo_enc_funcs, intel_encoder->enc.encoder_type); |
ling.ma@intel.com | fb7a46f | 2009-07-23 17:11:34 +0800 | [diff] [blame] | 2850 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2851 | drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2852 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2853 | drm_mode_connector_attach_encoder(&intel_encoder->base, &intel_encoder->enc); |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 2854 | if (sdvo_priv->is_tv) |
Zhao Yakui | ce6feab | 2009-08-24 13:50:26 +0800 | [diff] [blame] | 2855 | intel_sdvo_tv_create_property(connector); |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 2856 | |
| 2857 | if (sdvo_priv->is_tv || sdvo_priv->is_lvds) |
Zhao Yakui | b9219c5 | 2009-09-10 15:45:46 +0800 | [diff] [blame] | 2858 | intel_sdvo_create_enhance_property(connector); |
Zhao Yakui | d0cbde9 | 2009-09-10 15:45:47 +0800 | [diff] [blame] | 2859 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2860 | drm_sysfs_connector_add(connector); |
| 2861 | |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 2862 | intel_sdvo_select_ddc_bus(sdvo_priv); |
| 2863 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2864 | /* Set the input timing to the screen. Assume always input 0. */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2865 | intel_sdvo_set_target_input(intel_encoder, true, false); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2866 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2867 | intel_sdvo_get_input_pixel_clock_range(intel_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2868 | &sdvo_priv->pixel_clock_min, |
| 2869 | &sdvo_priv->pixel_clock_max); |
| 2870 | |
| 2871 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 2872 | DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 2873 | "clock range %dMHz - %dMHz, " |
| 2874 | "input 1: %c, input 2: %c, " |
| 2875 | "output 1: %c, output 2: %c\n", |
| 2876 | SDVO_NAME(sdvo_priv), |
| 2877 | sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id, |
| 2878 | sdvo_priv->caps.device_rev_id, |
| 2879 | sdvo_priv->pixel_clock_min / 1000, |
| 2880 | sdvo_priv->pixel_clock_max / 1000, |
| 2881 | (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N', |
| 2882 | (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N', |
| 2883 | /* check currently supported outputs */ |
| 2884 | sdvo_priv->caps.output_flags & |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2885 | (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N', |
yakui_zhao | 342dc38 | 2009-06-02 14:12:00 +0800 | [diff] [blame] | 2886 | sdvo_priv->caps.output_flags & |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2887 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); |
| 2888 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 2889 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2890 | |
| 2891 | err_i2c: |
Keith Packard | 57cdaf9 | 2009-09-04 13:07:54 +0800 | [diff] [blame] | 2892 | if (sdvo_priv->analog_ddc_bus != NULL) |
| 2893 | intel_i2c_destroy(sdvo_priv->analog_ddc_bus); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2894 | if (intel_encoder->ddc_bus != NULL) |
| 2895 | intel_i2c_destroy(intel_encoder->ddc_bus); |
| 2896 | if (intel_encoder->i2c_bus != NULL) |
| 2897 | intel_i2c_destroy(intel_encoder->i2c_bus); |
Jonas Bonn | ad5b2a6 | 2009-05-15 09:10:41 +0200 | [diff] [blame] | 2898 | err_inteloutput: |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2899 | kfree(intel_encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2900 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 2901 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2902 | } |