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