1 1.1 riastrad /* $NetBSD: intel_dvo.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2006 Dave Airlie <airlied (at) linux.ie> 5 1.1 riastrad * Copyright 2006-2007 Intel Corporation 6 1.1 riastrad * 7 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 8 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 9 1.1 riastrad * to deal in the Software without restriction, including without limitation 10 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 12 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 13 1.1 riastrad * 14 1.1 riastrad * The above copyright notice and this permission notice (including the next 15 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 16 1.1 riastrad * Software. 17 1.1 riastrad * 18 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 1.1 riastrad * DEALINGS IN THE SOFTWARE. 25 1.1 riastrad * 26 1.1 riastrad * Authors: 27 1.1 riastrad * Eric Anholt <eric (at) anholt.net> 28 1.1 riastrad */ 29 1.1 riastrad 30 1.1 riastrad #include <sys/cdefs.h> 31 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: intel_dvo.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $"); 32 1.1 riastrad 33 1.1 riastrad #include <linux/i2c.h> 34 1.1 riastrad #include <linux/slab.h> 35 1.1 riastrad 36 1.1 riastrad #include <drm/drm_atomic_helper.h> 37 1.1 riastrad #include <drm/drm_crtc.h> 38 1.1 riastrad #include <drm/i915_drm.h> 39 1.1 riastrad 40 1.1 riastrad #include "i915_drv.h" 41 1.1 riastrad #include "intel_connector.h" 42 1.1 riastrad #include "intel_display_types.h" 43 1.1 riastrad #include "intel_dvo.h" 44 1.1 riastrad #include "intel_dvo_dev.h" 45 1.1 riastrad #include "intel_gmbus.h" 46 1.1 riastrad #include "intel_panel.h" 47 1.1 riastrad 48 1.1 riastrad #define INTEL_DVO_CHIP_NONE 0 49 1.1 riastrad #define INTEL_DVO_CHIP_LVDS 1 50 1.1 riastrad #define INTEL_DVO_CHIP_TMDS 2 51 1.1 riastrad #define INTEL_DVO_CHIP_TVOUT 4 52 1.1 riastrad 53 1.1 riastrad #define SIL164_ADDR 0x38 54 1.1 riastrad #define CH7xxx_ADDR 0x76 55 1.1 riastrad #define TFP410_ADDR 0x38 56 1.1 riastrad #define NS2501_ADDR 0x38 57 1.1 riastrad 58 1.1 riastrad static const struct intel_dvo_device intel_dvo_devices[] = { 59 1.1 riastrad { 60 1.1 riastrad .type = INTEL_DVO_CHIP_TMDS, 61 1.1 riastrad .name = "sil164", 62 1.1 riastrad .dvo_reg = DVOC, 63 1.1 riastrad .dvo_srcdim_reg = DVOC_SRCDIM, 64 1.1 riastrad .slave_addr = SIL164_ADDR, 65 1.1 riastrad .dev_ops = &sil164_ops, 66 1.1 riastrad }, 67 1.1 riastrad { 68 1.1 riastrad .type = INTEL_DVO_CHIP_TMDS, 69 1.1 riastrad .name = "ch7xxx", 70 1.1 riastrad .dvo_reg = DVOC, 71 1.1 riastrad .dvo_srcdim_reg = DVOC_SRCDIM, 72 1.1 riastrad .slave_addr = CH7xxx_ADDR, 73 1.1 riastrad .dev_ops = &ch7xxx_ops, 74 1.1 riastrad }, 75 1.1 riastrad { 76 1.1 riastrad .type = INTEL_DVO_CHIP_TMDS, 77 1.1 riastrad .name = "ch7xxx", 78 1.1 riastrad .dvo_reg = DVOC, 79 1.1 riastrad .dvo_srcdim_reg = DVOC_SRCDIM, 80 1.1 riastrad .slave_addr = 0x75, /* For some ch7010 */ 81 1.1 riastrad .dev_ops = &ch7xxx_ops, 82 1.1 riastrad }, 83 1.1 riastrad { 84 1.1 riastrad .type = INTEL_DVO_CHIP_LVDS, 85 1.1 riastrad .name = "ivch", 86 1.1 riastrad .dvo_reg = DVOA, 87 1.1 riastrad .dvo_srcdim_reg = DVOA_SRCDIM, 88 1.1 riastrad .slave_addr = 0x02, /* Might also be 0x44, 0x84, 0xc4 */ 89 1.1 riastrad .dev_ops = &ivch_ops, 90 1.1 riastrad }, 91 1.1 riastrad { 92 1.1 riastrad .type = INTEL_DVO_CHIP_TMDS, 93 1.1 riastrad .name = "tfp410", 94 1.1 riastrad .dvo_reg = DVOC, 95 1.1 riastrad .dvo_srcdim_reg = DVOC_SRCDIM, 96 1.1 riastrad .slave_addr = TFP410_ADDR, 97 1.1 riastrad .dev_ops = &tfp410_ops, 98 1.1 riastrad }, 99 1.1 riastrad { 100 1.1 riastrad .type = INTEL_DVO_CHIP_LVDS, 101 1.1 riastrad .name = "ch7017", 102 1.1 riastrad .dvo_reg = DVOC, 103 1.1 riastrad .dvo_srcdim_reg = DVOC_SRCDIM, 104 1.1 riastrad .slave_addr = 0x75, 105 1.1 riastrad .gpio = GMBUS_PIN_DPB, 106 1.1 riastrad .dev_ops = &ch7017_ops, 107 1.1 riastrad }, 108 1.1 riastrad { 109 1.1 riastrad .type = INTEL_DVO_CHIP_TMDS, 110 1.1 riastrad .name = "ns2501", 111 1.1 riastrad .dvo_reg = DVOB, 112 1.1 riastrad .dvo_srcdim_reg = DVOB_SRCDIM, 113 1.1 riastrad .slave_addr = NS2501_ADDR, 114 1.1 riastrad .dev_ops = &ns2501_ops, 115 1.1 riastrad } 116 1.1 riastrad }; 117 1.1 riastrad 118 1.1 riastrad struct intel_dvo { 119 1.1 riastrad struct intel_encoder base; 120 1.1 riastrad 121 1.1 riastrad struct intel_dvo_device dev; 122 1.1 riastrad 123 1.1 riastrad struct intel_connector *attached_connector; 124 1.1 riastrad 125 1.1 riastrad bool panel_wants_dither; 126 1.1 riastrad }; 127 1.1 riastrad 128 1.1 riastrad static struct intel_dvo *enc_to_dvo(struct intel_encoder *encoder) 129 1.1 riastrad { 130 1.1 riastrad return container_of(encoder, struct intel_dvo, base); 131 1.1 riastrad } 132 1.1 riastrad 133 1.1 riastrad static struct intel_dvo *intel_attached_dvo(struct intel_connector *connector) 134 1.1 riastrad { 135 1.1 riastrad return enc_to_dvo(intel_attached_encoder(connector)); 136 1.1 riastrad } 137 1.1 riastrad 138 1.1 riastrad static bool intel_dvo_connector_get_hw_state(struct intel_connector *connector) 139 1.1 riastrad { 140 1.1 riastrad struct drm_device *dev = connector->base.dev; 141 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 142 1.1 riastrad struct intel_dvo *intel_dvo = intel_attached_dvo(connector); 143 1.1 riastrad u32 tmp; 144 1.1 riastrad 145 1.1 riastrad tmp = I915_READ(intel_dvo->dev.dvo_reg); 146 1.1 riastrad 147 1.1 riastrad if (!(tmp & DVO_ENABLE)) 148 1.1 riastrad return false; 149 1.1 riastrad 150 1.1 riastrad return intel_dvo->dev.dev_ops->get_hw_state(&intel_dvo->dev); 151 1.1 riastrad } 152 1.1 riastrad 153 1.1 riastrad static bool intel_dvo_get_hw_state(struct intel_encoder *encoder, 154 1.1 riastrad enum pipe *pipe) 155 1.1 riastrad { 156 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 157 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(encoder); 158 1.1 riastrad u32 tmp; 159 1.1 riastrad 160 1.1 riastrad tmp = I915_READ(intel_dvo->dev.dvo_reg); 161 1.1 riastrad 162 1.1 riastrad *pipe = (tmp & DVO_PIPE_SEL_MASK) >> DVO_PIPE_SEL_SHIFT; 163 1.1 riastrad 164 1.1 riastrad return tmp & DVO_ENABLE; 165 1.1 riastrad } 166 1.1 riastrad 167 1.1 riastrad static void intel_dvo_get_config(struct intel_encoder *encoder, 168 1.1 riastrad struct intel_crtc_state *pipe_config) 169 1.1 riastrad { 170 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 171 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(encoder); 172 1.1 riastrad u32 tmp, flags = 0; 173 1.1 riastrad 174 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_DVO); 175 1.1 riastrad 176 1.1 riastrad tmp = I915_READ(intel_dvo->dev.dvo_reg); 177 1.1 riastrad if (tmp & DVO_HSYNC_ACTIVE_HIGH) 178 1.1 riastrad flags |= DRM_MODE_FLAG_PHSYNC; 179 1.1 riastrad else 180 1.1 riastrad flags |= DRM_MODE_FLAG_NHSYNC; 181 1.1 riastrad if (tmp & DVO_VSYNC_ACTIVE_HIGH) 182 1.1 riastrad flags |= DRM_MODE_FLAG_PVSYNC; 183 1.1 riastrad else 184 1.1 riastrad flags |= DRM_MODE_FLAG_NVSYNC; 185 1.1 riastrad 186 1.1 riastrad pipe_config->hw.adjusted_mode.flags |= flags; 187 1.1 riastrad 188 1.1 riastrad pipe_config->hw.adjusted_mode.crtc_clock = pipe_config->port_clock; 189 1.1 riastrad } 190 1.1 riastrad 191 1.1 riastrad static void intel_disable_dvo(struct intel_encoder *encoder, 192 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 193 1.1 riastrad const struct drm_connector_state *old_conn_state) 194 1.1 riastrad { 195 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 196 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(encoder); 197 1.1 riastrad i915_reg_t dvo_reg = intel_dvo->dev.dvo_reg; 198 1.1 riastrad u32 temp = I915_READ(dvo_reg); 199 1.1 riastrad 200 1.1 riastrad intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, false); 201 1.1 riastrad I915_WRITE(dvo_reg, temp & ~DVO_ENABLE); 202 1.1 riastrad I915_READ(dvo_reg); 203 1.1 riastrad } 204 1.1 riastrad 205 1.1 riastrad static void intel_enable_dvo(struct intel_encoder *encoder, 206 1.1 riastrad const struct intel_crtc_state *pipe_config, 207 1.1 riastrad const struct drm_connector_state *conn_state) 208 1.1 riastrad { 209 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 210 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(encoder); 211 1.1 riastrad i915_reg_t dvo_reg = intel_dvo->dev.dvo_reg; 212 1.1 riastrad u32 temp = I915_READ(dvo_reg); 213 1.1 riastrad 214 1.1 riastrad intel_dvo->dev.dev_ops->mode_set(&intel_dvo->dev, 215 1.1 riastrad &pipe_config->hw.mode, 216 1.1 riastrad &pipe_config->hw.adjusted_mode); 217 1.1 riastrad 218 1.1 riastrad I915_WRITE(dvo_reg, temp | DVO_ENABLE); 219 1.1 riastrad I915_READ(dvo_reg); 220 1.1 riastrad 221 1.1 riastrad intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true); 222 1.1 riastrad } 223 1.1 riastrad 224 1.1 riastrad static enum drm_mode_status 225 1.1 riastrad intel_dvo_mode_valid(struct drm_connector *connector, 226 1.1 riastrad struct drm_display_mode *mode) 227 1.1 riastrad { 228 1.1 riastrad struct intel_dvo *intel_dvo = intel_attached_dvo(to_intel_connector(connector)); 229 1.1 riastrad const struct drm_display_mode *fixed_mode = 230 1.1 riastrad to_intel_connector(connector)->panel.fixed_mode; 231 1.1 riastrad int max_dotclk = to_i915(connector->dev)->max_dotclk_freq; 232 1.1 riastrad int target_clock = mode->clock; 233 1.1 riastrad 234 1.1 riastrad if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 235 1.1 riastrad return MODE_NO_DBLESCAN; 236 1.1 riastrad 237 1.1 riastrad /* XXX: Validate clock range */ 238 1.1 riastrad 239 1.1 riastrad if (fixed_mode) { 240 1.1 riastrad if (mode->hdisplay > fixed_mode->hdisplay) 241 1.1 riastrad return MODE_PANEL; 242 1.1 riastrad if (mode->vdisplay > fixed_mode->vdisplay) 243 1.1 riastrad return MODE_PANEL; 244 1.1 riastrad 245 1.1 riastrad target_clock = fixed_mode->clock; 246 1.1 riastrad } 247 1.1 riastrad 248 1.1 riastrad if (target_clock > max_dotclk) 249 1.1 riastrad return MODE_CLOCK_HIGH; 250 1.1 riastrad 251 1.1 riastrad return intel_dvo->dev.dev_ops->mode_valid(&intel_dvo->dev, mode); 252 1.1 riastrad } 253 1.1 riastrad 254 1.1 riastrad static int intel_dvo_compute_config(struct intel_encoder *encoder, 255 1.1 riastrad struct intel_crtc_state *pipe_config, 256 1.1 riastrad struct drm_connector_state *conn_state) 257 1.1 riastrad { 258 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(encoder); 259 1.1 riastrad const struct drm_display_mode *fixed_mode = 260 1.1 riastrad intel_dvo->attached_connector->panel.fixed_mode; 261 1.1 riastrad struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 262 1.1 riastrad 263 1.1 riastrad /* 264 1.1 riastrad * If we have timings from the BIOS for the panel, put them in 265 1.1 riastrad * to the adjusted mode. The CRTC will be set up for this mode, 266 1.1 riastrad * with the panel scaling set up to source from the H/VDisplay 267 1.1 riastrad * of the original mode. 268 1.1 riastrad */ 269 1.1 riastrad if (fixed_mode) 270 1.1 riastrad intel_fixed_panel_mode(fixed_mode, adjusted_mode); 271 1.1 riastrad 272 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) 273 1.1 riastrad return -EINVAL; 274 1.1 riastrad 275 1.1 riastrad pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 276 1.1 riastrad 277 1.1 riastrad return 0; 278 1.1 riastrad } 279 1.1 riastrad 280 1.1 riastrad static void intel_dvo_pre_enable(struct intel_encoder *encoder, 281 1.1 riastrad const struct intel_crtc_state *pipe_config, 282 1.1 riastrad const struct drm_connector_state *conn_state) 283 1.1 riastrad { 284 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 285 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 286 1.1 riastrad const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 287 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(encoder); 288 1.1 riastrad enum pipe pipe = crtc->pipe; 289 1.1 riastrad u32 dvo_val; 290 1.1 riastrad i915_reg_t dvo_reg = intel_dvo->dev.dvo_reg; 291 1.1 riastrad i915_reg_t dvo_srcdim_reg = intel_dvo->dev.dvo_srcdim_reg; 292 1.1 riastrad 293 1.1 riastrad /* Save the data order, since I don't know what it should be set to. */ 294 1.1 riastrad dvo_val = I915_READ(dvo_reg) & 295 1.1 riastrad (DVO_PRESERVE_MASK | DVO_DATA_ORDER_GBRG); 296 1.1 riastrad dvo_val |= DVO_DATA_ORDER_FP | DVO_BORDER_ENABLE | 297 1.1 riastrad DVO_BLANK_ACTIVE_HIGH; 298 1.1 riastrad 299 1.1 riastrad dvo_val |= DVO_PIPE_SEL(pipe); 300 1.1 riastrad dvo_val |= DVO_PIPE_STALL; 301 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 302 1.1 riastrad dvo_val |= DVO_HSYNC_ACTIVE_HIGH; 303 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 304 1.1 riastrad dvo_val |= DVO_VSYNC_ACTIVE_HIGH; 305 1.1 riastrad 306 1.1 riastrad /*I915_WRITE(DVOB_SRCDIM, 307 1.1 riastrad (adjusted_mode->crtc_hdisplay << DVO_SRCDIM_HORIZONTAL_SHIFT) | 308 1.1 riastrad (adjusted_mode->crtc_vdisplay << DVO_SRCDIM_VERTICAL_SHIFT));*/ 309 1.1 riastrad I915_WRITE(dvo_srcdim_reg, 310 1.1 riastrad (adjusted_mode->crtc_hdisplay << DVO_SRCDIM_HORIZONTAL_SHIFT) | 311 1.1 riastrad (adjusted_mode->crtc_vdisplay << DVO_SRCDIM_VERTICAL_SHIFT)); 312 1.1 riastrad /*I915_WRITE(DVOB, dvo_val);*/ 313 1.1 riastrad I915_WRITE(dvo_reg, dvo_val); 314 1.1 riastrad } 315 1.1 riastrad 316 1.1 riastrad static enum drm_connector_status 317 1.1 riastrad intel_dvo_detect(struct drm_connector *connector, bool force) 318 1.1 riastrad { 319 1.1 riastrad struct intel_dvo *intel_dvo = intel_attached_dvo(to_intel_connector(connector)); 320 1.1 riastrad DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", 321 1.1 riastrad connector->base.id, connector->name); 322 1.1 riastrad return intel_dvo->dev.dev_ops->detect(&intel_dvo->dev); 323 1.1 riastrad } 324 1.1 riastrad 325 1.1 riastrad static int intel_dvo_get_modes(struct drm_connector *connector) 326 1.1 riastrad { 327 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(connector->dev); 328 1.1 riastrad const struct drm_display_mode *fixed_mode = 329 1.1 riastrad to_intel_connector(connector)->panel.fixed_mode; 330 1.1 riastrad 331 1.1 riastrad /* 332 1.1 riastrad * We should probably have an i2c driver get_modes function for those 333 1.1 riastrad * devices which will have a fixed set of modes determined by the chip 334 1.1 riastrad * (TV-out, for example), but for now with just TMDS and LVDS, 335 1.1 riastrad * that's not the case. 336 1.1 riastrad */ 337 1.1 riastrad intel_ddc_get_modes(connector, 338 1.1 riastrad intel_gmbus_get_adapter(dev_priv, GMBUS_PIN_DPC)); 339 1.1 riastrad if (!list_empty(&connector->probed_modes)) 340 1.1 riastrad return 1; 341 1.1 riastrad 342 1.1 riastrad if (fixed_mode) { 343 1.1 riastrad struct drm_display_mode *mode; 344 1.1 riastrad mode = drm_mode_duplicate(connector->dev, fixed_mode); 345 1.1 riastrad if (mode) { 346 1.1 riastrad drm_mode_probed_add(connector, mode); 347 1.1 riastrad return 1; 348 1.1 riastrad } 349 1.1 riastrad } 350 1.1 riastrad 351 1.1 riastrad return 0; 352 1.1 riastrad } 353 1.1 riastrad 354 1.1 riastrad static const struct drm_connector_funcs intel_dvo_connector_funcs = { 355 1.1 riastrad .detect = intel_dvo_detect, 356 1.1 riastrad .late_register = intel_connector_register, 357 1.1 riastrad .early_unregister = intel_connector_unregister, 358 1.1 riastrad .destroy = intel_connector_destroy, 359 1.1 riastrad .fill_modes = drm_helper_probe_single_connector_modes, 360 1.1 riastrad .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 361 1.1 riastrad .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 362 1.1 riastrad }; 363 1.1 riastrad 364 1.1 riastrad static const struct drm_connector_helper_funcs intel_dvo_connector_helper_funcs = { 365 1.1 riastrad .mode_valid = intel_dvo_mode_valid, 366 1.1 riastrad .get_modes = intel_dvo_get_modes, 367 1.1 riastrad }; 368 1.1 riastrad 369 1.1 riastrad static void intel_dvo_enc_destroy(struct drm_encoder *encoder) 370 1.1 riastrad { 371 1.1 riastrad struct intel_dvo *intel_dvo = enc_to_dvo(to_intel_encoder(encoder)); 372 1.1 riastrad 373 1.1 riastrad if (intel_dvo->dev.dev_ops->destroy) 374 1.1 riastrad intel_dvo->dev.dev_ops->destroy(&intel_dvo->dev); 375 1.1 riastrad 376 1.1 riastrad intel_encoder_destroy(encoder); 377 1.1 riastrad } 378 1.1 riastrad 379 1.1 riastrad static const struct drm_encoder_funcs intel_dvo_enc_funcs = { 380 1.1 riastrad .destroy = intel_dvo_enc_destroy, 381 1.1 riastrad }; 382 1.1 riastrad 383 1.1 riastrad /* 384 1.1 riastrad * Attempts to get a fixed panel timing for LVDS (currently only the i830). 385 1.1 riastrad * 386 1.1 riastrad * Other chips with DVO LVDS will need to extend this to deal with the LVDS 387 1.1 riastrad * chip being on DVOB/C and having multiple pipes. 388 1.1 riastrad */ 389 1.1 riastrad static struct drm_display_mode * 390 1.1 riastrad intel_dvo_get_current_mode(struct intel_encoder *encoder) 391 1.1 riastrad { 392 1.1 riastrad struct drm_display_mode *mode; 393 1.1 riastrad 394 1.1 riastrad mode = intel_encoder_current_mode(encoder); 395 1.1 riastrad if (mode) { 396 1.1 riastrad DRM_DEBUG_KMS("using current (BIOS) mode: "); 397 1.1 riastrad drm_mode_debug_printmodeline(mode); 398 1.1 riastrad mode->type |= DRM_MODE_TYPE_PREFERRED; 399 1.1 riastrad } 400 1.1 riastrad 401 1.1 riastrad return mode; 402 1.1 riastrad } 403 1.1 riastrad 404 1.1 riastrad static enum port intel_dvo_port(i915_reg_t dvo_reg) 405 1.1 riastrad { 406 1.1 riastrad if (i915_mmio_reg_equal(dvo_reg, DVOA)) 407 1.1 riastrad return PORT_A; 408 1.1 riastrad else if (i915_mmio_reg_equal(dvo_reg, DVOB)) 409 1.1 riastrad return PORT_B; 410 1.1 riastrad else 411 1.1 riastrad return PORT_C; 412 1.1 riastrad } 413 1.1 riastrad 414 1.1 riastrad void intel_dvo_init(struct drm_i915_private *dev_priv) 415 1.1 riastrad { 416 1.1 riastrad struct intel_encoder *intel_encoder; 417 1.1 riastrad struct intel_dvo *intel_dvo; 418 1.1 riastrad struct intel_connector *intel_connector; 419 1.1 riastrad int i; 420 1.1 riastrad int encoder_type = DRM_MODE_ENCODER_NONE; 421 1.1 riastrad 422 1.1 riastrad intel_dvo = kzalloc(sizeof(*intel_dvo), GFP_KERNEL); 423 1.1 riastrad if (!intel_dvo) 424 1.1 riastrad return; 425 1.1 riastrad 426 1.1 riastrad intel_connector = intel_connector_alloc(); 427 1.1 riastrad if (!intel_connector) { 428 1.1 riastrad kfree(intel_dvo); 429 1.1 riastrad return; 430 1.1 riastrad } 431 1.1 riastrad 432 1.1 riastrad intel_dvo->attached_connector = intel_connector; 433 1.1 riastrad 434 1.1 riastrad intel_encoder = &intel_dvo->base; 435 1.1 riastrad 436 1.1 riastrad intel_encoder->disable = intel_disable_dvo; 437 1.1 riastrad intel_encoder->enable = intel_enable_dvo; 438 1.1 riastrad intel_encoder->get_hw_state = intel_dvo_get_hw_state; 439 1.1 riastrad intel_encoder->get_config = intel_dvo_get_config; 440 1.1 riastrad intel_encoder->compute_config = intel_dvo_compute_config; 441 1.1 riastrad intel_encoder->pre_enable = intel_dvo_pre_enable; 442 1.1 riastrad intel_connector->get_hw_state = intel_dvo_connector_get_hw_state; 443 1.1 riastrad 444 1.1 riastrad /* Now, try to find a controller */ 445 1.1 riastrad for (i = 0; i < ARRAY_SIZE(intel_dvo_devices); i++) { 446 1.1 riastrad struct drm_connector *connector = &intel_connector->base; 447 1.1 riastrad const struct intel_dvo_device *dvo = &intel_dvo_devices[i]; 448 1.1 riastrad struct i2c_adapter *i2c; 449 1.1 riastrad int gpio; 450 1.1 riastrad bool dvoinit; 451 1.1 riastrad enum pipe pipe; 452 1.1 riastrad u32 dpll[I915_MAX_PIPES]; 453 1.1 riastrad enum port port; 454 1.1 riastrad 455 1.1 riastrad /* 456 1.1 riastrad * Allow the I2C driver info to specify the GPIO to be used in 457 1.1 riastrad * special cases, but otherwise default to what's defined 458 1.1 riastrad * in the spec. 459 1.1 riastrad */ 460 1.1 riastrad if (intel_gmbus_is_valid_pin(dev_priv, dvo->gpio)) 461 1.1 riastrad gpio = dvo->gpio; 462 1.1 riastrad else if (dvo->type == INTEL_DVO_CHIP_LVDS) 463 1.1 riastrad gpio = GMBUS_PIN_SSC; 464 1.1 riastrad else 465 1.1 riastrad gpio = GMBUS_PIN_DPB; 466 1.1 riastrad 467 1.1 riastrad /* 468 1.1 riastrad * Set up the I2C bus necessary for the chip we're probing. 469 1.1 riastrad * It appears that everything is on GPIOE except for panels 470 1.1 riastrad * on i830 laptops, which are on GPIOB (DVOA). 471 1.1 riastrad */ 472 1.1 riastrad i2c = intel_gmbus_get_adapter(dev_priv, gpio); 473 1.1 riastrad 474 1.1 riastrad intel_dvo->dev = *dvo; 475 1.1 riastrad 476 1.1 riastrad /* 477 1.1 riastrad * GMBUS NAK handling seems to be unstable, hence let the 478 1.1 riastrad * transmitter detection run in bit banging mode for now. 479 1.1 riastrad */ 480 1.1 riastrad intel_gmbus_force_bit(i2c, true); 481 1.1 riastrad 482 1.1 riastrad /* 483 1.1 riastrad * ns2501 requires the DVO 2x clock before it will 484 1.1 riastrad * respond to i2c accesses, so make sure we have 485 1.1 riastrad * have the clock enabled before we attempt to 486 1.1 riastrad * initialize the device. 487 1.1 riastrad */ 488 1.1 riastrad for_each_pipe(dev_priv, pipe) { 489 1.1 riastrad dpll[pipe] = I915_READ(DPLL(pipe)); 490 1.1 riastrad I915_WRITE(DPLL(pipe), dpll[pipe] | DPLL_DVO_2X_MODE); 491 1.1 riastrad } 492 1.1 riastrad 493 1.1 riastrad dvoinit = dvo->dev_ops->init(&intel_dvo->dev, i2c); 494 1.1 riastrad 495 1.1 riastrad /* restore the DVO 2x clock state to original */ 496 1.1 riastrad for_each_pipe(dev_priv, pipe) { 497 1.1 riastrad I915_WRITE(DPLL(pipe), dpll[pipe]); 498 1.1 riastrad } 499 1.1 riastrad 500 1.1 riastrad intel_gmbus_force_bit(i2c, false); 501 1.1 riastrad 502 1.1 riastrad if (!dvoinit) 503 1.1 riastrad continue; 504 1.1 riastrad 505 1.1 riastrad port = intel_dvo_port(dvo->dvo_reg); 506 1.1 riastrad drm_encoder_init(&dev_priv->drm, &intel_encoder->base, 507 1.1 riastrad &intel_dvo_enc_funcs, encoder_type, 508 1.1 riastrad "DVO %c", port_name(port)); 509 1.1 riastrad 510 1.1 riastrad intel_encoder->type = INTEL_OUTPUT_DVO; 511 1.1 riastrad intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER; 512 1.1 riastrad intel_encoder->port = port; 513 1.1 riastrad intel_encoder->pipe_mask = ~0; 514 1.1 riastrad 515 1.1 riastrad switch (dvo->type) { 516 1.1 riastrad case INTEL_DVO_CHIP_TMDS: 517 1.1 riastrad intel_encoder->cloneable = (1 << INTEL_OUTPUT_ANALOG) | 518 1.1 riastrad (1 << INTEL_OUTPUT_DVO); 519 1.1 riastrad drm_connector_init(&dev_priv->drm, connector, 520 1.1 riastrad &intel_dvo_connector_funcs, 521 1.1 riastrad DRM_MODE_CONNECTOR_DVII); 522 1.1 riastrad encoder_type = DRM_MODE_ENCODER_TMDS; 523 1.1 riastrad break; 524 1.1 riastrad case INTEL_DVO_CHIP_LVDS: 525 1.1 riastrad intel_encoder->cloneable = 0; 526 1.1 riastrad drm_connector_init(&dev_priv->drm, connector, 527 1.1 riastrad &intel_dvo_connector_funcs, 528 1.1 riastrad DRM_MODE_CONNECTOR_LVDS); 529 1.1 riastrad encoder_type = DRM_MODE_ENCODER_LVDS; 530 1.1 riastrad break; 531 1.1 riastrad } 532 1.1 riastrad 533 1.1 riastrad drm_connector_helper_add(connector, 534 1.1 riastrad &intel_dvo_connector_helper_funcs); 535 1.1 riastrad connector->display_info.subpixel_order = SubPixelHorizontalRGB; 536 1.1 riastrad connector->interlace_allowed = false; 537 1.1 riastrad connector->doublescan_allowed = false; 538 1.1 riastrad 539 1.1 riastrad intel_connector_attach_encoder(intel_connector, intel_encoder); 540 1.1 riastrad if (dvo->type == INTEL_DVO_CHIP_LVDS) { 541 1.1 riastrad /* 542 1.1 riastrad * For our LVDS chipsets, we should hopefully be able 543 1.1 riastrad * to dig the fixed panel mode out of the BIOS data. 544 1.1 riastrad * However, it's in a different format from the BIOS 545 1.1 riastrad * data on chipsets with integrated LVDS (stored in AIM 546 1.1 riastrad * headers, likely), so for now, just get the current 547 1.1 riastrad * mode being output through DVO. 548 1.1 riastrad */ 549 1.1 riastrad intel_panel_init(&intel_connector->panel, 550 1.1 riastrad intel_dvo_get_current_mode(intel_encoder), 551 1.1 riastrad NULL); 552 1.1 riastrad intel_dvo->panel_wants_dither = true; 553 1.1 riastrad } 554 1.1 riastrad 555 1.1 riastrad return; 556 1.1 riastrad } 557 1.1 riastrad 558 1.1 riastrad kfree(intel_dvo); 559 1.1 riastrad kfree(intel_connector); 560 1.1 riastrad } 561