intel_sdvo.c revision 1450
1450N/A/*
1450N/A * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A
1450N/A/*
1450N/A * Copyright 2006 Dave Airlie <airlied@linux.ie>
1450N/A * Copyright (c) 2006-2007, 2013, Intel Corporation
1450N/A * Jesse Barnes <jesse.barnes@intel.com>
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the "Software"),
1450N/A * to deal in the Software without restriction, including without limitation
1450N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1450N/A * and/or sell copies of the Software, and to permit persons to whom the
1450N/A * Software is furnished to do so, subject to the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the next
1450N/A * paragraph) shall be included in all copies or substantial portions of the
1450N/A * Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1450N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1450N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1450N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1450N/A * DEALINGS IN THE SOFTWARE.
1450N/A *
1450N/A * Authors:
1450N/A * Eric Anholt <eric@anholt.net>
1450N/A */
1450N/A#include "drmP.h"
1450N/A#include "drm.h"
1450N/A#include "drm_crtc.h"
1450N/A#include "drm_sun_i2c.h" /* OSOL_i915 */
1450N/A#include "intel_drv.h"
1450N/A#include "drm_edid.h"
1450N/A#include "i915_drm.h"
1450N/A#include "i915_drv.h"
1450N/A#include "intel_sdvo_regs.h"
1450N/A
1450N/A#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
1450N/A#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
1450N/A#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
1450N/A#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
1450N/A
1450N/A#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
1450N/A SDVO_TV_MASK)
1450N/A
1450N/A#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
1450N/A#define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
1450N/A#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
1450N/A#define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
1450N/A#define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
1450N/A
1450N/A
1450N/Astatic const char *tv_format_names[] = {
1450N/A "NTSC_M" , "NTSC_J" , "NTSC_443",
1450N/A "PAL_B" , "PAL_D" , "PAL_G" ,
1450N/A "PAL_H" , "PAL_I" , "PAL_M" ,
1450N/A "PAL_N" , "PAL_NC" , "PAL_60" ,
1450N/A "SECAM_B" , "SECAM_D" , "SECAM_G" ,
1450N/A "SECAM_K" , "SECAM_K1", "SECAM_L" ,
1450N/A "SECAM_60"
1450N/A};
1450N/A
1450N/A#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
1450N/A
1450N/Astruct intel_sdvo {
1450N/A struct intel_encoder base;
1450N/A
1450N/A struct i2c_adapter *i2c;
1450N/A u8 slave_addr;
1450N/A
1450N/A struct i2c_adapter ddc;
1450N/A
1450N/A /* Register for the SDVO device: SDVOB or SDVOC */
1450N/A uint32_t sdvo_reg;
1450N/A
1450N/A /* Active outputs controlled by this SDVO output */
1450N/A uint16_t controlled_output;
1450N/A
1450N/A /*
1450N/A * Capabilities of the SDVO device returned by
1450N/A * i830_sdvo_get_capabilities()
1450N/A */
1450N/A struct intel_sdvo_caps caps;
1450N/A
1450N/A /* Pixel clock limitations reported by the SDVO device, in kHz */
1450N/A int pixel_clock_min, pixel_clock_max;
1450N/A
1450N/A /*
1450N/A * For multiple function SDVO device,
1450N/A * this is for current attached outputs.
1450N/A */
1450N/A uint16_t attached_output;
1450N/A
1450N/A /*
1450N/A * Hotplug activation bits for this device
1450N/A */
1450N/A uint16_t hotplug_active;
1450N/A
1450N/A /**
1450N/A * This is used to select the color range of RBG outputs in HDMI mode.
1450N/A * It is only valid when using TMDS encoding and 8 bit per color mode.
1450N/A */
1450N/A uint32_t color_range;
1450N/A bool color_range_auto;
1450N/A
1450N/A /**
1450N/A * This is set if we're going to treat the device as TV-out.
1450N/A *
1450N/A * While we have these nice friendly flags for output types that ought
1450N/A * to decide this for us, the S-Video output on our HDMI+S-Video card
1450N/A * shows up as RGB1 (VGA).
1450N/A */
1450N/A bool is_tv;
1450N/A
1450N/A /* On different gens SDVOB is at different places. */
1450N/A bool is_sdvob;
1450N/A
1450N/A /* This is for current tv format name */
1450N/A int tv_format_index;
1450N/A
1450N/A /**
1450N/A * This is set if we treat the device as HDMI, instead of DVI.
1450N/A */
1450N/A bool is_hdmi;
1450N/A bool has_hdmi_monitor;
1450N/A bool has_hdmi_audio;
1450N/A bool rgb_quant_range_selectable;
1450N/A
1450N/A /**
1450N/A * This is set if we detect output of sdvo device as LVDS.
1450N/A * have a valid fixed mode to use with the panel.
1450N/A */
1450N/A bool is_lvds;
1450N/A
1450N/A /**
1450N/A * This is sdvo fixed pannel mode pointer
1450N/A */
1450N/A struct drm_display_mode *sdvo_lvds_fixed_mode;
1450N/A
1450N/A /* DDC bus used by this SDVO encoder */
1450N/A uint8_t ddc_bus;
1450N/A
1450N/A /*
1450N/A * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
1450N/A */
1450N/A uint8_t dtd_sdvo_flags;
1450N/A};
1450N/A
1450N/Astruct intel_sdvo_connector {
1450N/A struct intel_connector base;
1450N/A
1450N/A /* Mark the type of connector */
1450N/A uint16_t output_flag;
1450N/A
1450N/A enum hdmi_force_audio force_audio;
1450N/A
1450N/A /* This contains all current supported TV format */
1450N/A u8 tv_format_supported[TV_FORMAT_NUM];
1450N/A int format_supported_num;
1450N/A struct drm_property *tv_format;
1450N/A
1450N/A /* add the property for the SDVO-TV */
1450N/A struct drm_property *left;
1450N/A struct drm_property *right;
1450N/A struct drm_property *top;
1450N/A struct drm_property *bottom;
1450N/A struct drm_property *hpos;
1450N/A struct drm_property *vpos;
1450N/A struct drm_property *contrast;
1450N/A struct drm_property *saturation;
1450N/A struct drm_property *hue;
1450N/A struct drm_property *sharpness;
1450N/A struct drm_property *flicker_filter;
1450N/A struct drm_property *flicker_filter_adaptive;
1450N/A struct drm_property *flicker_filter_2d;
1450N/A struct drm_property *tv_chroma_filter;
1450N/A struct drm_property *tv_luma_filter;
1450N/A struct drm_property *dot_crawl;
1450N/A
1450N/A /* add the property for the SDVO-TV/LVDS */
1450N/A struct drm_property *brightness;
1450N/A
1450N/A /* Add variable to record current setting for the above property */
1450N/A u32 left_margin, right_margin, top_margin, bottom_margin;
1450N/A
1450N/A /* this is to get the range of margin.*/
1450N/A u32 max_hscan, max_vscan;
1450N/A u32 max_hpos, cur_hpos;
1450N/A u32 max_vpos, cur_vpos;
1450N/A u32 cur_brightness, max_brightness;
1450N/A u32 cur_contrast, max_contrast;
1450N/A u32 cur_saturation, max_saturation;
1450N/A u32 cur_hue, max_hue;
1450N/A u32 cur_sharpness, max_sharpness;
1450N/A u32 cur_flicker_filter, max_flicker_filter;
1450N/A u32 cur_flicker_filter_adaptive, max_flicker_filter_adaptive;
1450N/A u32 cur_flicker_filter_2d, max_flicker_filter_2d;
1450N/A u32 cur_tv_chroma_filter, max_tv_chroma_filter;
1450N/A u32 cur_tv_luma_filter, max_tv_luma_filter;
1450N/A u32 cur_dot_crawl, max_dot_crawl;
1450N/A};
1450N/A
1450N/Astatic struct intel_sdvo *to_intel_sdvo(struct drm_encoder *encoder)
1450N/A{
1450N/A return container_of(encoder, struct intel_sdvo, base.base);
1450N/A}
1450N/A
1450N/Astatic struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector)
1450N/A{
1450N/A return container_of(intel_attached_encoder(connector),
1450N/A struct intel_sdvo, base);
1450N/A}
1450N/A
1450N/Astatic struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector)
1450N/A{
1450N/A return container_of(to_intel_connector(connector), struct intel_sdvo_connector, base);
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags);
1450N/Astatic bool
1450N/Aintel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *intel_sdvo_connector,
1450N/A int type);
1450N/Astatic bool
1450N/Aintel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *intel_sdvo_connector);
1450N/A
1450N/A/**
1450N/A * Writes the SDVOB or SDVOC with the given value, but always writes both
1450N/A * SDVOB and SDVOC to work around apparent hardware issues (according to
1450N/A * comments in the BIOS).
1450N/A */
1450N/Astatic void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
1450N/A{
1450N/A struct drm_device *dev = intel_sdvo->base.base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A u32 bval = val, cval = val;
1450N/A int i;
1450N/A
1450N/A if (intel_sdvo->sdvo_reg == PCH_SDVOB) {
1450N/A I915_WRITE(intel_sdvo->sdvo_reg, val);
1450N/A I915_READ(intel_sdvo->sdvo_reg);
1450N/A return;
1450N/A }
1450N/A
1450N/A if (intel_sdvo->sdvo_reg == GEN3_SDVOB)
1450N/A cval = I915_READ(GEN3_SDVOC);
1450N/A else
1450N/A bval = I915_READ(GEN3_SDVOB);
1450N/A
1450N/A /*
1450N/A * Write the registers twice for luck. Sometimes,
1450N/A * writing them only once doesn't appear to 'stick'.
1450N/A * The BIOS does this too. Yay, magic
1450N/A */
1450N/A for (i = 0; i < 2; i++)
1450N/A {
1450N/A I915_WRITE(GEN3_SDVOB, bval);
1450N/A I915_READ(GEN3_SDVOB);
1450N/A I915_WRITE(GEN3_SDVOC, cval);
1450N/A I915_READ(GEN3_SDVOC);
1450N/A }
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
1450N/A{
1450N/A struct i2c_msg msgs[] = {
1450N/A {
1450N/A .addr = intel_sdvo->slave_addr,
1450N/A .flags = 0,
1450N/A .len = 1,
1450N/A .buf = &addr,
1450N/A },
1450N/A {
1450N/A .addr = intel_sdvo->slave_addr,
1450N/A .flags = I2C_M_RD,
1450N/A .len = 1,
1450N/A .buf = ch,
1450N/A }
1450N/A };
1450N/A int ret;
1450N/A
1450N/A if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
1450N/A return true;
1450N/A
1450N/A DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
1450N/A return false;
1450N/A}
1450N/A
1450N/A#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
1450N/A/** Mapping of command numbers to names, for debug output */
1450N/Astatic const struct _sdvo_cmd_name {
1450N/A u8 cmd;
1450N/A const char *name;
1450N/A} sdvo_cmd_names[] = {
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
1450N/A
1450N/A /* Add the op code for SDVO enhancements */
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER),
1450N/A
1450N/A /* HDMI op code */
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
1450N/A SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
1450N/A};
1450N/A
1450N/A#define SDVO_NAME(svdo) ((svdo)->is_sdvob ? "SDVOB" : "SDVOC")
1450N/A
1450N/Astatic void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
1450N/A const void *args, int args_len)
1450N/A{
1450N/A int i;
1450N/A
1450N/A DRM_DEBUG_KMS("%s: W: %02X ",
1450N/A SDVO_NAME(intel_sdvo), cmd);
1450N/A for (i = 0; i < args_len; i++)
1450N/A DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
1450N/A for (; i < 8; i++)
1450N/A DRM_LOG_KMS(" ");
1450N/A for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
1450N/A if (cmd == sdvo_cmd_names[i].cmd) {
1450N/A DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
1450N/A break;
1450N/A }
1450N/A }
1450N/A if (i == ARRAY_SIZE(sdvo_cmd_names))
1450N/A DRM_LOG_KMS("(%02X)", cmd);
1450N/A DRM_LOG_KMS("\n");
1450N/A}
1450N/A
1450N/Astatic const char *cmd_status_names[] = {
1450N/A "Power on",
1450N/A "Success",
1450N/A "Not supported",
1450N/A "Invalid arg",
1450N/A "Pending",
1450N/A "Target not specified",
1450N/A "Scaling not supported"
1450N/A};
1450N/A
1450N/Astatic bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
1450N/A const void *args, int args_len)
1450N/A{
1450N/A u8 *buf, status;
1450N/A struct i2c_msg *msgs;
1450N/A int i, ret = true;
1450N/A
1450N/A /* Would be simpler to allocate both in one go ? */
1450N/A buf = (u8 *)kzalloc(args_len * 2 + 2, GFP_KERNEL);
1450N/A if (!buf)
1450N/A return false;
1450N/A
1450N/A msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
1450N/A if (!msgs) {
1450N/A kfree(buf, args_len * 2 + 2);
1450N/A return false;
1450N/A }
1450N/A
1450N/A intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
1450N/A
1450N/A for (i = 0; i < args_len; i++) {
1450N/A msgs[i].addr = intel_sdvo->slave_addr;
1450N/A msgs[i].flags = 0;
1450N/A msgs[i].len = 2;
1450N/A msgs[i].buf = buf + 2 *i;
1450N/A buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
1450N/A buf[2*i + 1] = ((u8*)args)[i];
1450N/A }
1450N/A msgs[i].addr = intel_sdvo->slave_addr;
1450N/A msgs[i].flags = 0;
1450N/A msgs[i].len = 2;
1450N/A msgs[i].buf = buf + 2*i;
1450N/A buf[2*i + 0] = SDVO_I2C_OPCODE;
1450N/A buf[2*i + 1] = cmd;
1450N/A
1450N/A /* the following two are to read the response */
1450N/A status = SDVO_I2C_CMD_STATUS;
1450N/A msgs[i+1].addr = intel_sdvo->slave_addr;
1450N/A msgs[i+1].flags = 0;
1450N/A msgs[i+1].len = 1;
1450N/A msgs[i+1].buf = &status;
1450N/A
1450N/A msgs[i+2].addr = intel_sdvo->slave_addr;
1450N/A msgs[i+2].flags = I2C_M_RD;
1450N/A msgs[i+2].len = 1;
1450N/A msgs[i+2].buf = &status;
1450N/A
1450N/A ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
1450N/A if (ret < 0) {
1450N/A DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
1450N/A ret = false;
1450N/A goto out;
1450N/A }
1450N/A if (ret != i+3) {
1450N/A /* failure in I2C transfer */
1450N/A DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
1450N/A ret = false;
1450N/A }
1450N/A
1450N/Aout:
1450N/A kfree(msgs, (args_len + 3) * sizeof(*msgs));
1450N/A kfree(buf, args_len * 2 + 2);
1450N/A return ret;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
1450N/A void *response, int response_len)
1450N/A{
1450N/A u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
1450N/A u8 status;
1450N/A int i;
1450N/A
1450N/A DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo));
1450N/A
1450N/A /*
1450N/A * The documentation states that all commands will be
1450N/A * processed within 15µs, and that we need only poll
1450N/A * the status byte a maximum of 3 times in order for the
1450N/A * command to be complete.
1450N/A *
1450N/A * Check 5 times in case the hardware failed to read the docs.
1450N/A *
1450N/A * Also beware that the first response by many devices is to
1450N/A * reply PENDING and stall for time. TVs are notorious for
1450N/A * requiring longer than specified to complete their replies.
1450N/A * Originally (in the DDX long ago), the delay was only ever 15ms
1450N/A * with an additional delay of 30ms applied for TVs added later after
1450N/A * many experiments. To accommodate both sets of delays, we do a
1450N/A * sequence of slow checks if the device is falling behind and fails
1450N/A * to reply within 5*15us.
1450N/A */
1450N/A if (!intel_sdvo_read_byte(intel_sdvo,
1450N/A SDVO_I2C_CMD_STATUS,
1450N/A &status))
1450N/A goto log_fail;
1450N/A
1450N/A while (status == SDVO_CMD_STATUS_PENDING && --retry) {
1450N/A if (retry < 10)
1450N/A msleep(15);
1450N/A else
1450N/A udelay(15);
1450N/A
1450N/A if (!intel_sdvo_read_byte(intel_sdvo,
1450N/A SDVO_I2C_CMD_STATUS,
1450N/A &status))
1450N/A goto log_fail;
1450N/A }
1450N/A
1450N/A if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
1450N/A DRM_LOG_KMS("(%s)", cmd_status_names[status]);
1450N/A else
1450N/A DRM_LOG_KMS("(??? %d)", status);
1450N/A
1450N/A if (status != SDVO_CMD_STATUS_SUCCESS)
1450N/A goto log_fail;
1450N/A
1450N/A /* Read the command response */
1450N/A for (i = 0; i < response_len; i++) {
1450N/A if (!intel_sdvo_read_byte(intel_sdvo,
1450N/A SDVO_I2C_RETURN_0 + i,
1450N/A &((u8 *)response)[i]))
1450N/A goto log_fail;
1450N/A DRM_LOG_KMS(" %02X", ((u8 *)response)[i]);
1450N/A }
1450N/A DRM_LOG_KMS("\n");
1450N/A return true;
1450N/A
1450N/Alog_fail:
1450N/A DRM_LOG_KMS("... failed\n");
1450N/A return false;
1450N/A}
1450N/A
1450N/Astatic int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
1450N/A{
1450N/A if (mode->clock >= 100000)
1450N/A return 1;
1450N/A else if (mode->clock >= 50000)
1450N/A return 2;
1450N/A else
1450N/A return 4;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
1450N/A u8 ddc_bus)
1450N/A{
1450N/A /* This must be the immediately preceding write before the i2c xfer */
1450N/A return intel_sdvo_write_cmd(intel_sdvo,
1450N/A SDVO_CMD_SET_CONTROL_BUS_SWITCH,
1450N/A &ddc_bus, 1);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
1450N/A{
1450N/A if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
1450N/A return false;
1450N/A
1450N/A return intel_sdvo_read_response(intel_sdvo, NULL, 0);
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
1450N/A{
1450N/A if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
1450N/A return false;
1450N/A
1450N/A return intel_sdvo_read_response(intel_sdvo, value, len);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A struct intel_sdvo_set_target_input_args targets = {0};
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_TARGET_INPUT,
1450N/A &targets, sizeof(targets));
1450N/A}
1450N/A
1450N/A/**
1450N/A * Return whether each input is trained.
1450N/A *
1450N/A * This function is making an assumption about the layout of the response,
1450N/A * which should be checked against the docs.
1450N/A */
1450N/Astatic bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
1450N/A{
1450N/A struct intel_sdvo_get_trained_inputs_response response;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
1450N/A &response, sizeof(response)))
1450N/A return false;
1450N/A
1450N/A *input_1 = response.input0_trained;
1450N/A *input_2 = response.input1_trained;
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
1450N/A u16 outputs)
1450N/A{
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_ACTIVE_OUTPUTS,
1450N/A &outputs, sizeof(outputs));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
1450N/A u16 *outputs)
1450N/A{
1450N/A return intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_ACTIVE_OUTPUTS,
1450N/A outputs, sizeof(*outputs));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
1450N/A int mode)
1450N/A{
1450N/A u8 state = SDVO_ENCODER_STATE_ON;
1450N/A
1450N/A switch (mode) {
1450N/A case DRM_MODE_DPMS_ON:
1450N/A state = SDVO_ENCODER_STATE_ON;
1450N/A break;
1450N/A case DRM_MODE_DPMS_STANDBY:
1450N/A state = SDVO_ENCODER_STATE_STANDBY;
1450N/A break;
1450N/A case DRM_MODE_DPMS_SUSPEND:
1450N/A state = SDVO_ENCODER_STATE_SUSPEND;
1450N/A break;
1450N/A case DRM_MODE_DPMS_OFF:
1450N/A state = SDVO_ENCODER_STATE_OFF;
1450N/A break;
1450N/A }
1450N/A
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
1450N/A int *clock_min,
1450N/A int *clock_max)
1450N/A{
1450N/A struct intel_sdvo_pixel_clock_range clocks;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
1450N/A &clocks, sizeof(clocks)))
1450N/A return false;
1450N/A
1450N/A /* Convert the values from units of 10 kHz to kHz. */
1450N/A *clock_min = clocks.min * 10;
1450N/A *clock_max = clocks.max * 10;
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
1450N/A u16 outputs)
1450N/A{
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_TARGET_OUTPUT,
1450N/A &outputs, sizeof(outputs));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
1450N/A struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
1450N/A intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
1450N/A struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
1450N/A intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A return intel_sdvo_set_timing(intel_sdvo,
1450N/A SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A return intel_sdvo_set_timing(intel_sdvo,
1450N/A SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A return intel_sdvo_get_timing(intel_sdvo,
1450N/A SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
1450N/A uint16_t clock,
1450N/A uint16_t width,
1450N/A uint16_t height)
1450N/A{
1450N/A struct intel_sdvo_preferred_input_timing_args args;
1450N/A
1450N/A (void) memset(&args, 0, sizeof(args));
1450N/A args.clock = clock;
1450N/A args.width = width;
1450N/A args.height = height;
1450N/A args.interlace = 0;
1450N/A
1450N/A if (intel_sdvo->is_lvds &&
1450N/A (intel_sdvo->sdvo_lvds_fixed_mode->hdisplay != width ||
1450N/A intel_sdvo->sdvo_lvds_fixed_mode->vdisplay != height))
1450N/A args.scaled = 1;
1450N/A
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
1450N/A &args, sizeof(args));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
1450N/A &dtd->part1, sizeof(dtd->part1)) &&
1450N/A intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
1450N/A &dtd->part2, sizeof(dtd->part2));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
1450N/A{
1450N/A return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
1450N/A const struct drm_display_mode *mode)
1450N/A{
1450N/A uint16_t width, height;
1450N/A uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
1450N/A uint16_t h_sync_offset, v_sync_offset;
1450N/A int mode_clock;
1450N/A
1450N/A width = mode->hdisplay;
1450N/A height = mode->vdisplay;
1450N/A
1450N/A /* do some mode translations */
1450N/A h_blank_len = mode->htotal - mode->hdisplay;
1450N/A h_sync_len = mode->hsync_end - mode->hsync_start;
1450N/A
1450N/A v_blank_len = mode->vtotal - mode->vdisplay;
1450N/A v_sync_len = mode->vsync_end - mode->vsync_start;
1450N/A
1450N/A h_sync_offset = mode->hsync_start - mode->hdisplay;
1450N/A v_sync_offset = mode->vsync_start - mode->vdisplay;
1450N/A
1450N/A mode_clock = mode->clock;
1450N/A mode_clock /= 10;
1450N/A dtd->part1.clock = (u16) mode_clock;
1450N/A
1450N/A dtd->part1.h_active = width & 0xff;
1450N/A dtd->part1.h_blank = h_blank_len & 0xff;
1450N/A dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
1450N/A ((h_blank_len >> 8) & 0xf);
1450N/A dtd->part1.v_active = height & 0xff;
1450N/A dtd->part1.v_blank = v_blank_len & 0xff;
1450N/A dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
1450N/A ((v_blank_len >> 8) & 0xf);
1450N/A
1450N/A dtd->part2.h_sync_off = h_sync_offset & 0xff;
1450N/A dtd->part2.h_sync_width = h_sync_len & 0xff;
1450N/A dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
1450N/A (v_sync_len & 0xf);
1450N/A dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
1450N/A ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
1450N/A ((v_sync_len & 0x30) >> 4);
1450N/A
1450N/A dtd->part2.dtd_flags = 0x18;
1450N/A if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1450N/A dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
1450N/A if (mode->flags & DRM_MODE_FLAG_PHSYNC)
1450N/A dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
1450N/A if (mode->flags & DRM_MODE_FLAG_PVSYNC)
1450N/A dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
1450N/A
1450N/A dtd->part2.sdvo_flags = 0;
1450N/A dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
1450N/A dtd->part2.reserved = 0;
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
1450N/A const struct intel_sdvo_dtd *dtd)
1450N/A{
1450N/A mode->hdisplay = dtd->part1.h_active;
1450N/A mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
1450N/A mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
1450N/A mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
1450N/A mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
1450N/A mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
1450N/A mode->htotal = mode->hdisplay + dtd->part1.h_blank;
1450N/A mode->htotal += (dtd->part1.h_high & 0xf) << 8;
1450N/A
1450N/A mode->vdisplay = dtd->part1.v_active;
1450N/A mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
1450N/A mode->vsync_start = mode->vdisplay;
1450N/A mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
1450N/A mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
1450N/A mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
1450N/A mode->vsync_end = mode->vsync_start +
1450N/A (dtd->part2.v_sync_off_width & 0xf);
1450N/A mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
1450N/A mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
1450N/A mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
1450N/A
1450N/A mode->clock = dtd->part1.clock * 10;
1450N/A
1450N/A mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
1450N/A if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
1450N/A mode->flags |= DRM_MODE_FLAG_INTERLACE;
1450N/A if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1450N/A mode->flags |= DRM_MODE_FLAG_PHSYNC;
1450N/A if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1450N/A mode->flags |= DRM_MODE_FLAG_PVSYNC;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A struct intel_sdvo_encode encode;
1450N/A
1450N/A return intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_SUPP_ENCODE,
1450N/A &encode, sizeof(encode));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
1450N/A uint8_t mode)
1450N/A{
1450N/A return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
1450N/A uint8_t mode)
1450N/A{
1450N/A return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
1450N/A}
1450N/A
1450N/A#if 0
1450N/Astatic void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A int i, j;
1450N/A uint8_t set_buf_index[2];
1450N/A uint8_t av_split;
1450N/A uint8_t buf_size;
1450N/A uint8_t buf[48];
1450N/A uint8_t *pos;
1450N/A
1450N/A intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
1450N/A
1450N/A for (i = 0; i <= av_split; i++) {
1450N/A set_buf_index[0] = i; set_buf_index[1] = 0;
1450N/A intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
1450N/A set_buf_index, 2);
1450N/A intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
1450N/A intel_sdvo_read_response(encoder, &buf_size, 1);
1450N/A
1450N/A pos = buf;
1450N/A for (j = 0; j <= buf_size; j += 8) {
1450N/A intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
1450N/A NULL, 0);
1450N/A intel_sdvo_read_response(encoder, pos, 8);
1450N/A pos += 8;
1450N/A }
1450N/A }
1450N/A}
1450N/A#endif
1450N/A
1450N/Astatic bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
1450N/A unsigned if_index, uint8_t tx_rate,
1450N/A uint8_t *data, unsigned length)
1450N/A{
1450N/A uint8_t set_buf_index[2] = {(uint8_t) if_index, 0 };
1450N/A uint8_t hbuf_size, tmp[8];
1450N/A int i;
1450N/A
1450N/A if (!intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_HBUF_INDEX,
1450N/A set_buf_index, 2))
1450N/A return false;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
1450N/A &hbuf_size, 1))
1450N/A return false;
1450N/A
1450N/A /* Buffer size is 0 based, hooray! */
1450N/A hbuf_size++;
1450N/A
1450N/A DRM_DEBUG_KMS("writing sdvo hbuf: %i, hbuf_size %i, hbuf_size: %i\n",
1450N/A if_index, length, hbuf_size);
1450N/A
1450N/A for (i = 0; i < hbuf_size; i += 8) {
1450N/A (void) memset(tmp, 0, 8);
1450N/A if (i < length)
1450N/A (void) memcpy(tmp, data + i, min(8, length - i));
1450N/A
1450N/A if (!intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_HBUF_DATA,
1450N/A tmp, 8))
1450N/A return false;
1450N/A }
1450N/A
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_HBUF_TXRATE,
1450N/A &tx_rate, 1);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
1450N/A const struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct dip_infoframe avi_if = {
1450N/A .type = DIP_TYPE_AVI,
1450N/A .ver = DIP_VERSION_AVI,
1450N/A .len = DIP_LEN_AVI,
1450N/A };
1450N/A uint8_t sdvo_data[4 + sizeof(avi_if.body.avi)];
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(intel_sdvo->base.base.crtc);
1450N/A
1450N/A if (intel_sdvo->rgb_quant_range_selectable) {
1450N/A if (intel_crtc->config.limited_color_range)
1450N/A avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED;
1450N/A else
1450N/A avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL;
1450N/A }
1450N/A
1450N/A avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode);
1450N/A
1450N/A intel_dip_infoframe_csum(&avi_if);
1450N/A
1450N/A /* sdvo spec says that the ecc is handled by the hw, and it looks like
1450N/A * we must not send the ecc field, either. */
1450N/A (void) memcpy(sdvo_data, &avi_if, 3);
1450N/A sdvo_data[3] = avi_if.checksum;
1450N/A (void) memcpy(&sdvo_data[4], &avi_if.body, sizeof(avi_if.body.avi));
1450N/A
1450N/A return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
1450N/A SDVO_HBUF_TX_VSYNC,
1450N/A sdvo_data, sizeof(sdvo_data));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A struct intel_sdvo_tv_format format;
1450N/A uint32_t format_map;
1450N/A
1450N/A format_map = 1 << intel_sdvo->tv_format_index;
1450N/A memset(&format, 0, sizeof(format));
1450N/A (void) memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
1450N/A
1450N/A return intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_TV_FORMAT,
1450N/A &format, sizeof(format));
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
1450N/A const struct drm_display_mode *mode)
1450N/A{
1450N/A struct intel_sdvo_dtd output_dtd;
1450N/A
1450N/A if (!intel_sdvo_set_target_output(intel_sdvo,
1450N/A intel_sdvo->attached_output))
1450N/A return false;
1450N/A
1450N/A intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1450N/A if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1450N/A return false;
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/A/* Asks the sdvo controller for the preferred input mode given the output mode.
1450N/A * Unfortunately we have to set up the full output mode to do that. */
1450N/Astatic bool
1450N/Aintel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
1450N/A const struct drm_display_mode *mode,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct intel_sdvo_dtd input_dtd;
1450N/A
1450N/A /* Reset the input timing to the screen. Assume always input 0. */
1450N/A if (!intel_sdvo_set_target_input(intel_sdvo))
1450N/A return false;
1450N/A
1450N/A if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
1450N/A mode->clock / 10,
1450N/A mode->hdisplay,
1450N/A mode->vdisplay))
1450N/A return false;
1450N/A
1450N/A if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
1450N/A &input_dtd))
1450N/A return false;
1450N/A
1450N/A intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1450N/A intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_config *pipe_config)
1450N/A{
1450N/A unsigned dotclock = pipe_config->adjusted_mode.clock;
1450N/A struct dpll *clock = &pipe_config->dpll;
1450N/A
1450N/A /* SDVO TV has fixed PLL values depend on its clock range,
1450N/A this mirrors vbios setting. */
1450N/A if (dotclock >= 100000 && dotclock < 140500) {
1450N/A clock->p1 = 2;
1450N/A clock->p2 = 10;
1450N/A clock->n = 3;
1450N/A clock->m1 = 16;
1450N/A clock->m2 = 8;
1450N/A } else if (dotclock >= 140500 && dotclock <= 200000) {
1450N/A clock->p1 = 1;
1450N/A clock->p2 = 10;
1450N/A clock->n = 6;
1450N/A clock->m1 = 12;
1450N/A clock->m2 = 8;
1450N/A } else {
1450N/A DRM_ERROR("SDVO TV clock out of range: %i\n", dotclock);
1450N/A }
1450N/A
1450N/A pipe_config->clock_set = true;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_compute_config(struct intel_encoder *encoder,
1450N/A struct intel_crtc_config *pipe_config)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1450N/A struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
1450N/A struct drm_display_mode *mode = &pipe_config->requested_mode;
1450N/A
1450N/A DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
1450N/A pipe_config->pipe_bpp = 8*3;
1450N/A
1450N/A if (HAS_PCH_SPLIT(encoder->base.dev))
1450N/A pipe_config->has_pch_encoder = true;
1450N/A
1450N/A /* We need to construct preferred input timings based on our
1450N/A * output timings. To do that, we have to set the output
1450N/A * timings, even though this isn't really the right place in
1450N/A * the sequence to do it. Oh well.
1450N/A */
1450N/A if (intel_sdvo->is_tv) {
1450N/A if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
1450N/A return false;
1450N/A
1450N/A (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1450N/A mode,
1450N/A adjusted_mode);
1450N/A pipe_config->sdvo_tv_clock = true;
1450N/A } else if (intel_sdvo->is_lvds) {
1450N/A if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
1450N/A intel_sdvo->sdvo_lvds_fixed_mode))
1450N/A return false;
1450N/A
1450N/A (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
1450N/A mode,
1450N/A adjusted_mode);
1450N/A }
1450N/A
1450N/A /* Make the CRTC code factor in the SDVO pixel multiplier. The
1450N/A * SDVO device will factor out the multiplier during mode_set.
1450N/A */
1450N/A pipe_config->pixel_multiplier =
1450N/A intel_sdvo_get_pixel_multiplier(adjusted_mode);
1450N/A adjusted_mode->clock *= pipe_config->pixel_multiplier;
1450N/A
1450N/A if (intel_sdvo->color_range_auto) {
1450N/A /* See CEA-861-E - 5.1 Default Encoding Parameters */
1450N/A /* FIXME: This bit is only valid when using TMDS encoding and 8
1450N/A * bit per color mode. */
1450N/A if (intel_sdvo->has_hdmi_monitor &&
1450N/A drm_match_cea_mode(adjusted_mode) > 1)
1450N/A intel_sdvo->color_range = HDMI_COLOR_RANGE_16_235;
1450N/A else
1450N/A intel_sdvo->color_range = 0;
1450N/A }
1450N/A
1450N/A if (intel_sdvo->color_range)
1450N/A pipe_config->limited_color_range = true;
1450N/A
1450N/A /* Clock computation needs to happen after pixel multiplier. */
1450N/A if (intel_sdvo->is_tv)
1450N/A i9xx_adjust_sdvo_tv_clock(pipe_config);
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_mode_set(struct intel_encoder *intel_encoder)
1450N/A{
1450N/A struct drm_device *dev = intel_encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct drm_crtc *crtc = intel_encoder->base.crtc;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1450N/A struct drm_display_mode *adjusted_mode =
1450N/A &intel_crtc->config.adjusted_mode;
1450N/A struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&intel_encoder->base);
1450N/A u32 sdvox;
1450N/A struct intel_sdvo_in_out_map in_out;
1450N/A struct intel_sdvo_dtd input_dtd, output_dtd;
1450N/A int rate;
1450N/A
1450N/A if (!mode)
1450N/A return;
1450N/A
1450N/A /* First, set the input mapping for the first input to our controlled
1450N/A * output. This is only correct if we're a single-input device, in
1450N/A * which case the first input is the output from the appropriate SDVO
1450N/A * channel on the motherboard. In a two-input device, the first input
1450N/A * will be SDVOB and the second SDVOC.
1450N/A */
1450N/A in_out.in0 = intel_sdvo->attached_output;
1450N/A in_out.in1 = 0;
1450N/A
1450N/A intel_sdvo_set_value(intel_sdvo,
1450N/A SDVO_CMD_SET_IN_OUT_MAP,
1450N/A &in_out, sizeof(in_out));
1450N/A
1450N/A /* Set the output timings to the screen */
1450N/A if (!intel_sdvo_set_target_output(intel_sdvo,
1450N/A intel_sdvo->attached_output))
1450N/A return;
1450N/A
1450N/A /* lvds has a special fixed output timing. */
1450N/A if (intel_sdvo->is_lvds)
1450N/A intel_sdvo_get_dtd_from_mode(&output_dtd,
1450N/A intel_sdvo->sdvo_lvds_fixed_mode);
1450N/A else
1450N/A intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1450N/A if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
1450N/A DRM_INFO("Setting output timings on %s failed\n",
1450N/A SDVO_NAME(intel_sdvo));
1450N/A
1450N/A /* Set the input timing to the screen. Assume always input 0. */
1450N/A if (!intel_sdvo_set_target_input(intel_sdvo))
1450N/A return;
1450N/A
1450N/A if (intel_sdvo->has_hdmi_monitor) {
1450N/A (void) intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
1450N/A (void) intel_sdvo_set_colorimetry(intel_sdvo,
1450N/A SDVO_COLORIMETRY_RGB256);
1450N/A (void) intel_sdvo_set_avi_infoframe(intel_sdvo, adjusted_mode);
1450N/A } else
1450N/A (void) intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
1450N/A
1450N/A if (intel_sdvo->is_tv &&
1450N/A !intel_sdvo_set_tv_format(intel_sdvo))
1450N/A return;
1450N/A
1450N/A /* We have tried to get input timing in mode_fixup, and filled into
1450N/A * adjusted_mode.
1450N/A */
1450N/A intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1450N/A if (intel_sdvo->is_tv || intel_sdvo->is_lvds)
1450N/A input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
1450N/A if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
1450N/A DRM_INFO("Setting input timings on %s failed\n",
1450N/A SDVO_NAME(intel_sdvo));
1450N/A
1450N/A switch (intel_crtc->config.pixel_multiplier) {
1450N/A default:
1450N/A DRM_ERROR("unknown pixel mutlipler specified\n");
1450N/A case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
1450N/A case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
1450N/A case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
1450N/A }
1450N/A if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
1450N/A return;
1450N/A
1450N/A /* Set the SDVO control regs. */
1450N/A if (INTEL_INFO(dev)->gen >= 4) {
1450N/A /* The real mode polarity is set by the SDVO commands, using
1450N/A * struct intel_sdvo_dtd. */
1450N/A sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
1450N/A if (!HAS_PCH_SPLIT(dev) && intel_sdvo->is_hdmi)
1450N/A sdvox |= intel_sdvo->color_range;
1450N/A if (INTEL_INFO(dev)->gen < 5)
1450N/A sdvox |= SDVO_BORDER_ENABLE;
1450N/A } else {
1450N/A sdvox = I915_READ(intel_sdvo->sdvo_reg);
1450N/A switch (intel_sdvo->sdvo_reg) {
1450N/A case GEN3_SDVOB:
1450N/A sdvox &= SDVOB_PRESERVE_MASK;
1450N/A break;
1450N/A case GEN3_SDVOC:
1450N/A sdvox &= SDVOC_PRESERVE_MASK;
1450N/A break;
1450N/A }
1450N/A sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1450N/A }
1450N/A
1450N/A if (INTEL_PCH_TYPE(dev) >= PCH_CPT)
1450N/A sdvox |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe);
1450N/A else
1450N/A sdvox |= SDVO_PIPE_SEL(intel_crtc->pipe);
1450N/A
1450N/A if (intel_sdvo->has_hdmi_audio)
1450N/A sdvox |= SDVO_AUDIO_ENABLE;
1450N/A
1450N/A /*LINTED E_NOP_IF_STMT*/
1450N/A if (INTEL_INFO(dev)->gen >= 4) {
1450N/A /* done in crtc_mode_set as the dpll_md reg must be written early */
1450N/A /*LINTED E_NOP_IF_STMT*/
1450N/A } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1450N/A /* done in crtc_mode_set as it lives inside the dpll register */
1450N/A } else {
1450N/A sdvox |= (intel_crtc->config.pixel_multiplier - 1)
1450N/A << SDVO_PORT_MULTIPLY_SHIFT;
1450N/A }
1450N/A
1450N/A if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
1450N/A INTEL_INFO(dev)->gen < 5)
1450N/A sdvox |= SDVO_STALL_SELECT;
1450N/A intel_sdvo_write_sdvox(intel_sdvo, sdvox);
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
1450N/A{
1450N/A struct intel_sdvo_connector *intel_sdvo_connector =
1450N/A to_intel_sdvo_connector(&connector->base);
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
1450N/A u16 active_outputs = 0;
1450N/A
1450N/A intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1450N/A
1450N/A if (active_outputs & intel_sdvo_connector->output_flag)
1450N/A return true;
1450N/A else
1450N/A return false;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
1450N/A enum pipe *pipe)
1450N/A{
1450N/A struct drm_device *dev = encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1450N/A u16 active_outputs = 0;
1450N/A u32 tmp;
1450N/A
1450N/A tmp = I915_READ(intel_sdvo->sdvo_reg);
1450N/A intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
1450N/A
1450N/A if (!(tmp & SDVO_ENABLE) && (active_outputs == 0))
1450N/A return false;
1450N/A
1450N/A if (HAS_PCH_CPT(dev))
1450N/A *pipe = PORT_TO_PIPE_CPT(tmp);
1450N/A else
1450N/A *pipe = PORT_TO_PIPE(tmp);
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_get_config(struct intel_encoder *encoder,
1450N/A struct intel_crtc_config *pipe_config)
1450N/A{
1450N/A struct drm_device *dev = encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1450N/A struct intel_sdvo_dtd dtd;
1450N/A int encoder_pixel_multiplier = 0;
1450N/A u32 flags = 0, sdvox;
1450N/A u8 val;
1450N/A bool ret;
1450N/A
1450N/A ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
1450N/A if (!ret) {
1450N/A /* Some sdvo encoders are not spec compliant and don't
1450N/A * implement the mandatory get_timings function. */
1450N/A DRM_DEBUG_DRIVER("failed to retrieve SDVO DTD\n");
1450N/A pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
1450N/A } else {
1450N/A if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
1450N/A flags |= DRM_MODE_FLAG_PHSYNC;
1450N/A else
1450N/A flags |= DRM_MODE_FLAG_NHSYNC;
1450N/A
1450N/A if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
1450N/A flags |= DRM_MODE_FLAG_PVSYNC;
1450N/A else
1450N/A flags |= DRM_MODE_FLAG_NVSYNC;
1450N/A }
1450N/A
1450N/A pipe_config->adjusted_mode.flags |= flags;
1450N/A
1450N/A /*
1450N/A * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
1450N/A * the sdvo port register, on all other platforms it is part of the dpll
1450N/A * state. Since the general pipe state readout happens before the
1450N/A * encoder->get_config we so already have a valid pixel multplier on all
1450N/A * other platfroms.
1450N/A */
1450N/A if (IS_I915G(dev) || IS_I915GM(dev)) {
1450N/A sdvox = I915_READ(intel_sdvo->sdvo_reg);
1450N/A pipe_config->pixel_multiplier =
1450N/A ((sdvox & SDVO_PORT_MULTIPLY_MASK)
1450N/A >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
1450N/A }
1450N/A
1450N/A /* Cross check the port pixel multiplier with the sdvo encoder state. */
1450N/A intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
1450N/A switch (val) {
1450N/A case SDVO_CLOCK_RATE_MULT_1X:
1450N/A encoder_pixel_multiplier = 1;
1450N/A break;
1450N/A case SDVO_CLOCK_RATE_MULT_2X:
1450N/A encoder_pixel_multiplier = 2;
1450N/A break;
1450N/A case SDVO_CLOCK_RATE_MULT_4X:
1450N/A encoder_pixel_multiplier = 4;
1450N/A break;
1450N/A }
1450N/A
1450N/A if(HAS_PCH_SPLIT(dev))
1450N/A return; /* no pixel multiplier readout support yet */
1450N/A
1450N/A if(encoder_pixel_multiplier != pipe_config->pixel_multiplier)
1450N/A DRM_ERROR("SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
1450N/A pipe_config->pixel_multiplier, encoder_pixel_multiplier);
1450N/A}
1450N/A
1450N/Astatic void intel_disable_sdvo(struct intel_encoder *encoder)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1450N/A u32 temp;
1450N/A
1450N/A intel_sdvo_set_active_outputs(intel_sdvo, 0);
1450N/A if (0)
1450N/A intel_sdvo_set_encoder_power_state(intel_sdvo,
1450N/A DRM_MODE_DPMS_OFF);
1450N/A
1450N/A temp = I915_READ(intel_sdvo->sdvo_reg);
1450N/A if ((temp & SDVO_ENABLE) != 0) {
1450N/A /* HW workaround for IBX, we need to move the port to
1450N/A * transcoder A before disabling it. */
1450N/A if (HAS_PCH_IBX(encoder->base.dev)) {
1450N/A struct drm_crtc *crtc = encoder->base.crtc;
1450N/A int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
1450N/A
1450N/A if (temp & SDVO_PIPE_B_SELECT) {
1450N/A temp &= ~SDVO_PIPE_B_SELECT;
1450N/A I915_WRITE(intel_sdvo->sdvo_reg, temp);
1450N/A POSTING_READ(intel_sdvo->sdvo_reg);
1450N/A
1450N/A /* Again we need to write this twice. */
1450N/A I915_WRITE(intel_sdvo->sdvo_reg, temp);
1450N/A POSTING_READ(intel_sdvo->sdvo_reg);
1450N/A
1450N/A /* Transcoder selection bits only update
1450N/A * effectively on vblank. */
1450N/A if (crtc)
1450N/A intel_wait_for_vblank(encoder->base.dev, pipe);
1450N/A else
1450N/A msleep(50);
1450N/A }
1450N/A }
1450N/A
1450N/A intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
1450N/A }
1450N/A}
1450N/A
1450N/Astatic void intel_enable_sdvo(struct intel_encoder *encoder)
1450N/A{
1450N/A struct drm_device *dev = encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1450N/A u32 temp;
1450N/A bool input1, input2;
1450N/A int i;
1450N/A u8 status;
1450N/A
1450N/A temp = I915_READ(intel_sdvo->sdvo_reg);
1450N/A if ((temp & SDVO_ENABLE) == 0) {
1450N/A /* HW workaround for IBX, we need to move the port
1450N/A * to transcoder A before disabling it, so restore it here. */
1450N/A if (HAS_PCH_IBX(dev))
1450N/A temp |= SDVO_PIPE_SEL(intel_crtc->pipe);
1450N/A
1450N/A intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
1450N/A }
1450N/A for (i = 0; i < 2; i++)
1450N/A intel_wait_for_vblank(dev, intel_crtc->pipe);
1450N/A
1450N/A status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
1450N/A /* Warn if the device reported failure to sync.
1450N/A * A lot of SDVO devices fail to notify of sync, but it's
1450N/A * a given it the status is a success, we succeeded.
1450N/A */
1450N/A if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
1450N/A DRM_DEBUG_KMS("First %s output reported failure to "
1450N/A "sync\n", SDVO_NAME(intel_sdvo));
1450N/A }
1450N/A
1450N/A if (0)
1450N/A (void) intel_sdvo_set_encoder_power_state(intel_sdvo,
1450N/A DRM_MODE_DPMS_ON);
1450N/A (void) intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_dpms(struct drm_connector *connector, int mode)
1450N/A{
1450N/A struct drm_crtc *crtc;
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A
1450N/A /* dvo supports only 2 dpms states. */
1450N/A if (mode != DRM_MODE_DPMS_ON)
1450N/A mode = DRM_MODE_DPMS_OFF;
1450N/A
1450N/A if (mode == connector->dpms)
1450N/A return;
1450N/A
1450N/A connector->dpms = mode;
1450N/A
1450N/A /* Only need to change hw state when actually enabled */
1450N/A crtc = intel_sdvo->base.base.crtc;
1450N/A if (!crtc) {
1450N/A intel_sdvo->base.connectors_active = false;
1450N/A return;
1450N/A }
1450N/A
1450N/A /* We set active outputs manually below in case pipe dpms doesn't change
1450N/A * due to cloning. */
1450N/A if (mode != DRM_MODE_DPMS_ON) {
1450N/A intel_sdvo_set_active_outputs(intel_sdvo, 0);
1450N/A if (0)
1450N/A intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1450N/A
1450N/A intel_sdvo->base.connectors_active = false;
1450N/A
1450N/A intel_crtc_update_dpms(crtc);
1450N/A } else {
1450N/A intel_sdvo->base.connectors_active = true;
1450N/A
1450N/A intel_crtc_update_dpms(crtc);
1450N/A
1450N/A if (0)
1450N/A intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
1450N/A intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
1450N/A }
1450N/A
1450N/A intel_modeset_check_state(connector->dev);
1450N/A}
1450N/A
1450N/Astatic int intel_sdvo_mode_valid(struct drm_connector *connector,
1450N/A struct drm_display_mode *mode)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A
1450N/A if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1450N/A return MODE_NO_DBLESCAN;
1450N/A
1450N/A if (intel_sdvo->pixel_clock_min > mode->clock)
1450N/A return MODE_CLOCK_LOW;
1450N/A
1450N/A if (intel_sdvo->pixel_clock_max < mode->clock)
1450N/A return MODE_CLOCK_HIGH;
1450N/A
1450N/A if (intel_sdvo->is_lvds) {
1450N/A if (mode->hdisplay > intel_sdvo->sdvo_lvds_fixed_mode->hdisplay)
1450N/A return MODE_PANEL;
1450N/A
1450N/A if (mode->vdisplay > intel_sdvo->sdvo_lvds_fixed_mode->vdisplay)
1450N/A return MODE_PANEL;
1450N/A }
1450N/A
1450N/A return MODE_OK;
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
1450N/A{
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_DEVICE_CAPS,
1450N/A caps, sizeof(*caps)))
1450N/A return false;
1450N/A
1450N/A DRM_DEBUG_KMS("SDVO capabilities:\n"
1450N/A " vendor_id: %d\n"
1450N/A " device_id: %d\n"
1450N/A " device_rev_id: %d\n"
1450N/A " sdvo_version_major: %d\n"
1450N/A " sdvo_version_minor: %d\n"
1450N/A " sdvo_inputs_mask: %d\n"
1450N/A " smooth_scaling: %d\n"
1450N/A " sharp_scaling: %d\n"
1450N/A " up_scaling: %d\n"
1450N/A " down_scaling: %d\n"
1450N/A " stall_support: %d\n"
1450N/A " output_flags: %d\n",
1450N/A caps->vendor_id,
1450N/A caps->device_id,
1450N/A caps->device_rev_id,
1450N/A caps->sdvo_version_major,
1450N/A caps->sdvo_version_minor,
1450N/A caps->sdvo_inputs_mask,
1450N/A caps->smooth_scaling,
1450N/A caps->sharp_scaling,
1450N/A caps->up_scaling,
1450N/A caps->down_scaling,
1450N/A caps->stall_support,
1450N/A caps->output_flags);
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic uint16_t intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A struct drm_device *dev = intel_sdvo->base.base.dev;
1450N/A uint16_t hotplug;
1450N/A
1450N/A /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1450N/A * on the line. */
1450N/A if (IS_I945G(dev) || IS_I945GM(dev))
1450N/A return 0;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1450N/A &hotplug, sizeof(hotplug)))
1450N/A return 0;
1450N/A
1450N/A return hotplug;
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
1450N/A
1450N/A intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
1450N/A &intel_sdvo->hotplug_active, 2);
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A /* Is there more than one type of output? */
1450N/A return hweight16(intel_sdvo->caps.output_flags) > 1;
1450N/A}
1450N/A
1450N/Astatic struct edid *
1450N/Aintel_sdvo_get_edid(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
1450N/A return drm_get_edid(connector, &sdvo->ddc);
1450N/A}
1450N/A
1450N/A/* Mac mini hack -- use the same DDC as the analog connector */
1450N/Astatic struct edid *
1450N/Aintel_sdvo_get_analog_edid(struct drm_connector *connector)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = connector->dev->dev_private;
1450N/A
1450N/A return drm_get_edid(connector,
1450N/A intel_gmbus_get_adapter(dev_priv,
1450N/A dev_priv->vbt.crt_ddc_pin));
1450N/A}
1450N/A
1450N/Astatic enum drm_connector_status
1450N/Aintel_sdvo_tmds_sink_detect(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A enum drm_connector_status status;
1450N/A struct edid *edid;
1450N/A
1450N/A edid = intel_sdvo_get_edid(connector);
1450N/A
1450N/A if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
1450N/A u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
1450N/A
1450N/A /*
1450N/A * Don't use the 1 as the argument of DDC bus switch to get
1450N/A * the EDID. It is used for SDVO SPD ROM.
1450N/A */
1450N/A for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
1450N/A intel_sdvo->ddc_bus = ddc;
1450N/A edid = intel_sdvo_get_edid(connector);
1450N/A if (edid)
1450N/A break;
1450N/A }
1450N/A /*
1450N/A * If we found the EDID on the other bus,
1450N/A * assume that is the correct DDC bus.
1450N/A */
1450N/A if (edid == NULL)
1450N/A intel_sdvo->ddc_bus = saved_ddc;
1450N/A }
1450N/A
1450N/A /*
1450N/A * When there is no edid and no monitor is connected with VGA
1450N/A * port, try to use the CRT ddc to read the EDID for DVI-connector.
1450N/A */
1450N/A if (edid == NULL)
1450N/A edid = intel_sdvo_get_analog_edid(connector);
1450N/A
1450N/A status = connector_status_unknown;
1450N/A if (edid != NULL) {
1450N/A /* DDC bus is shared, match EDID to connector type */
1450N/A if (edid->input & DRM_EDID_INPUT_DIGITAL) {
1450N/A status = connector_status_connected;
1450N/A if (intel_sdvo->is_hdmi) {
1450N/A intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
1450N/A intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
1450N/A intel_sdvo->rgb_quant_range_selectable =
1450N/A drm_rgb_quant_range_selectable(edid);
1450N/A }
1450N/A } else
1450N/A status = connector_status_disconnected;
1450N/A kfree(edid, EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1));
1450N/A }
1450N/A
1450N/A if (status == connector_status_connected) {
1450N/A struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1450N/A if (intel_sdvo_connector->force_audio != HDMI_AUDIO_AUTO)
1450N/A intel_sdvo->has_hdmi_audio = (intel_sdvo_connector->force_audio == HDMI_AUDIO_ON);
1450N/A }
1450N/A
1450N/A return status;
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
1450N/A struct edid *edid)
1450N/A{
1450N/A bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
1450N/A bool connector_is_digital = !!IS_DIGITAL(sdvo);
1450N/A
1450N/A DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
1450N/A connector_is_digital, monitor_is_digital);
1450N/A return connector_is_digital == monitor_is_digital;
1450N/A}
1450N/A
1450N/Astatic enum drm_connector_status
1450N/Aintel_sdvo_detect(struct drm_connector *connector, bool force)
1450N/A{
1450N/A uint16_t response;
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1450N/A enum drm_connector_status ret;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_ATTACHED_DISPLAYS,
1450N/A &response, 2))
1450N/A return connector_status_unknown;
1450N/A
1450N/A DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
1450N/A response & 0xff, response >> 8,
1450N/A intel_sdvo_connector->output_flag);
1450N/A
1450N/A if (response == 0)
1450N/A return connector_status_disconnected;
1450N/A
1450N/A intel_sdvo->attached_output = response;
1450N/A
1450N/A intel_sdvo->has_hdmi_monitor = false;
1450N/A intel_sdvo->has_hdmi_audio = false;
1450N/A intel_sdvo->rgb_quant_range_selectable = false;
1450N/A
1450N/A if ((intel_sdvo_connector->output_flag & response) == 0)
1450N/A ret = connector_status_disconnected;
1450N/A else if (IS_TMDS(intel_sdvo_connector))
1450N/A ret = intel_sdvo_tmds_sink_detect(connector);
1450N/A else {
1450N/A struct edid *edid;
1450N/A
1450N/A /* if we have an edid check it matches the connection */
1450N/A edid = intel_sdvo_get_edid(connector);
1450N/A if (edid == NULL)
1450N/A edid = intel_sdvo_get_analog_edid(connector);
1450N/A if (edid != NULL) {
1450N/A if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
1450N/A edid))
1450N/A ret = connector_status_connected;
1450N/A else
1450N/A ret = connector_status_disconnected;
1450N/A
1450N/A kfree(edid, EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1));
1450N/A } else
1450N/A ret = connector_status_connected;
1450N/A }
1450N/A
1450N/A /* May update encoder flag for like clock for SDVO TV, etc.*/
1450N/A if (ret == connector_status_connected) {
1450N/A intel_sdvo->is_tv = false;
1450N/A intel_sdvo->is_lvds = false;
1450N/A
1450N/A if (response & SDVO_TV_MASK)
1450N/A intel_sdvo->is_tv = true;
1450N/A if (response & SDVO_LVDS_MASK)
1450N/A intel_sdvo->is_lvds = intel_sdvo->sdvo_lvds_fixed_mode != NULL;
1450N/A }
1450N/A
1450N/A return ret;
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
1450N/A{
1450N/A struct edid *edid;
1450N/A
1450N/A /* set the bus switch and get the modes */
1450N/A edid = intel_sdvo_get_edid(connector);
1450N/A
1450N/A /*
1450N/A * Mac mini hack. On this device, the DVI-I connector shares one DDC
1450N/A * link between analog and digital outputs. So, if the regular SDVO
1450N/A * DDC fails, check to see if the analog output is disconnected, in
1450N/A * which case we'll look there for the digital DDC data.
1450N/A */
1450N/A if (edid == NULL)
1450N/A edid = intel_sdvo_get_analog_edid(connector);
1450N/A
1450N/A if (edid != NULL) {
1450N/A if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
1450N/A edid)) {
1450N/A (void) drm_mode_connector_update_edid_property(connector, edid);
1450N/A (void) drm_add_edid_modes(connector, edid);
1450N/A }
1450N/A
1450N/A kfree(edid, EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1));
1450N/A }
1450N/A}
1450N/A
1450N/A/*
1450N/A * Set of SDVO TV modes.
1450N/A * Note! This is in reply order (see loop in get_tv_modes).
1450N/A * XXX: all 60Hz refresh?
1450N/A */
1450N/Astatic const struct drm_display_mode sdvo_tv_modes[] = {
1450N/A { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1450N/A 416, 0, 200, 201, 232, 233, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1450N/A 416, 0, 240, 241, 272, 273, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1450N/A 496, 0, 300, 301, 332, 333, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1450N/A 736, 0, 350, 351, 382, 383, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1450N/A 736, 0, 400, 401, 432, 433, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1450N/A 736, 0, 480, 481, 512, 513, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1450N/A 800, 0, 480, 481, 512, 513, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1450N/A 800, 0, 576, 577, 608, 609, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1450N/A 816, 0, 350, 351, 382, 383, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1450N/A 816, 0, 400, 401, 432, 433, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1450N/A 816, 0, 480, 481, 512, 513, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1450N/A 816, 0, 540, 541, 572, 573, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1450N/A 816, 0, 576, 577, 608, 609, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1450N/A 864, 0, 576, 577, 608, 609, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1450N/A 896, 0, 600, 601, 632, 633, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1450N/A 928, 0, 624, 625, 656, 657, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1450N/A 1016, 0, 766, 767, 798, 799, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1450N/A 1120, 0, 768, 769, 800, 801, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1450N/A 1376, 0, 1024, 1025, 1056, 1057, 0,
1450N/A DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1450N/A};
1450N/A
1450N/Astatic void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A struct intel_sdvo_sdtv_resolution_request tv_res;
1450N/A uint32_t reply = 0, format_map = 0;
1450N/A int i;
1450N/A
1450N/A /* Read the list of supported input resolutions for the selected TV
1450N/A * format.
1450N/A */
1450N/A format_map = 1 << intel_sdvo->tv_format_index;
1450N/A memcpy(&tv_res, &format_map,
1450N/A min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
1450N/A
1450N/A if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
1450N/A return;
1450N/A
1450N/A if (!intel_sdvo_write_cmd(intel_sdvo,
1450N/A SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
1450N/A &tv_res, sizeof(tv_res)))
1450N/A return;
1450N/A if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
1450N/A return;
1450N/A
1450N/A for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
1450N/A if (reply & (1 << i)) {
1450N/A struct drm_display_mode *nmode;
1450N/A nmode = drm_mode_duplicate(connector->dev,
1450N/A &sdvo_tv_modes[i]);
1450N/A if (nmode)
1450N/A drm_mode_probed_add(connector, nmode);
1450N/A }
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A struct drm_i915_private *dev_priv = connector->dev->dev_private;
1450N/A struct drm_display_mode *newmode;
1450N/A
1450N/A /*
1450N/A * Fetch modes from VBT. For SDVO prefer the VBT mode since some
1450N/A * SDVO->LVDS transcoders can't cope with the EDID mode.
1450N/A */
1450N/A if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
1450N/A newmode = drm_mode_duplicate(connector->dev,
1450N/A dev_priv->vbt.sdvo_lvds_vbt_mode);
1450N/A if (newmode != NULL) {
1450N/A /* Guarantee the mode is preferred */
1450N/A newmode->type = (DRM_MODE_TYPE_PREFERRED |
1450N/A DRM_MODE_TYPE_DRIVER);
1450N/A drm_mode_probed_add(connector, newmode);
1450N/A }
1450N/A }
1450N/A
1450N/A /*
1450N/A * Attempt to get the mode list from DDC.
1450N/A * Assume that the preferred modes are
1450N/A * arranged in priority order.
1450N/A */
1450N/A intel_ddc_get_modes(connector, &intel_sdvo->ddc);
1450N/A
1450N/A list_for_each_entry(newmode, struct drm_display_mode, &connector->probed_modes, head) {
1450N/A if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1450N/A intel_sdvo->sdvo_lvds_fixed_mode =
1450N/A drm_mode_duplicate(connector->dev, newmode);
1450N/A
1450N/A intel_sdvo->is_lvds = true;
1450N/A break;
1450N/A }
1450N/A }
1450N/A
1450N/A}
1450N/A
1450N/Astatic int intel_sdvo_get_modes(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1450N/A
1450N/A if (IS_TV(intel_sdvo_connector))
1450N/A intel_sdvo_get_tv_modes(connector);
1450N/A else if (IS_LVDS(intel_sdvo_connector))
1450N/A intel_sdvo_get_lvds_modes(connector);
1450N/A else
1450N/A intel_sdvo_get_ddc_modes(connector);
1450N/A
1450N/A return !list_empty(&connector->probed_modes);
1450N/A}
1450N/A
1450N/Astatic void
1450N/Aintel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1450N/A struct drm_device *dev = connector->dev;
1450N/A
1450N/A if (intel_sdvo_connector->left)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->left);
1450N/A if (intel_sdvo_connector->right)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->right);
1450N/A if (intel_sdvo_connector->top)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->top);
1450N/A if (intel_sdvo_connector->bottom)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->bottom);
1450N/A if (intel_sdvo_connector->hpos)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->hpos);
1450N/A if (intel_sdvo_connector->vpos)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->vpos);
1450N/A if (intel_sdvo_connector->saturation)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->saturation);
1450N/A if (intel_sdvo_connector->contrast)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->contrast);
1450N/A if (intel_sdvo_connector->hue)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->hue);
1450N/A if (intel_sdvo_connector->sharpness)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->sharpness);
1450N/A if (intel_sdvo_connector->flicker_filter)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->flicker_filter);
1450N/A if (intel_sdvo_connector->flicker_filter_2d)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_2d);
1450N/A if (intel_sdvo_connector->flicker_filter_adaptive)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_adaptive);
1450N/A if (intel_sdvo_connector->tv_luma_filter)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->tv_luma_filter);
1450N/A if (intel_sdvo_connector->tv_chroma_filter)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->tv_chroma_filter);
1450N/A if (intel_sdvo_connector->dot_crawl)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->dot_crawl);
1450N/A if (intel_sdvo_connector->brightness)
1450N/A drm_property_destroy(dev, intel_sdvo_connector->brightness);
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_destroy(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1450N/A
1450N/A if (intel_sdvo_connector->tv_format)
1450N/A drm_property_destroy(connector->dev,
1450N/A intel_sdvo_connector->tv_format);
1450N/A
1450N/A intel_sdvo_destroy_enhance_property(connector);
1450N/A drm_connector_cleanup(connector);
1450N/A kfree(intel_sdvo_connector, sizeof(struct intel_sdvo_connector));
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_detect_hdmi_audio(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A struct edid *edid;
1450N/A bool has_audio = false;
1450N/A
1450N/A if (!intel_sdvo->is_hdmi)
1450N/A return false;
1450N/A
1450N/A edid = intel_sdvo_get_edid(connector);
1450N/A if (edid != NULL && edid->input & DRM_EDID_INPUT_DIGITAL)
1450N/A has_audio = drm_detect_monitor_audio(edid);
1450N/A if (edid != NULL)
1450N/A kfree(edid, EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1));
1450N/A
1450N/A return has_audio;
1450N/A}
1450N/A
1450N/Astatic int
1450N/Aintel_sdvo_set_property(struct drm_connector *connector,
1450N/A struct drm_property *property,
1450N/A uint64_t val)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
1450N/A struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1450N/A struct drm_i915_private *dev_priv = connector->dev->dev_private;
1450N/A uint16_t temp_value;
1450N/A uint8_t cmd;
1450N/A int ret;
1450N/A
1450N/A ret = drm_object_property_set_value(&connector->base, property, val);
1450N/A if (ret)
1450N/A return ret;
1450N/A
1450N/A if (property == dev_priv->force_audio_property) {
1450N/A int i = (int)val;
1450N/A bool has_audio;
1450N/A
1450N/A if (i == intel_sdvo_connector->force_audio)
1450N/A return 0;
1450N/A
1450N/A intel_sdvo_connector->force_audio = i;
1450N/A
1450N/A if (i == HDMI_AUDIO_AUTO)
1450N/A has_audio = intel_sdvo_detect_hdmi_audio(connector);
1450N/A else
1450N/A has_audio = (i == HDMI_AUDIO_ON);
1450N/A
1450N/A if (has_audio == intel_sdvo->has_hdmi_audio)
1450N/A return 0;
1450N/A
1450N/A intel_sdvo->has_hdmi_audio = has_audio;
1450N/A goto done;
1450N/A }
1450N/A
1450N/A if (property == dev_priv->broadcast_rgb_property) {
1450N/A bool old_auto = intel_sdvo->color_range_auto;
1450N/A uint32_t old_range = intel_sdvo->color_range;
1450N/A
1450N/A switch (val) {
1450N/A case INTEL_BROADCAST_RGB_AUTO:
1450N/A intel_sdvo->color_range_auto = true;
1450N/A break;
1450N/A case INTEL_BROADCAST_RGB_FULL:
1450N/A intel_sdvo->color_range_auto = false;
1450N/A intel_sdvo->color_range = 0;
1450N/A break;
1450N/A case INTEL_BROADCAST_RGB_LIMITED:
1450N/A intel_sdvo->color_range_auto = false;
1450N/A /* FIXME: this bit is only valid when using TMDS
1450N/A * encoding and 8 bit per color mode. */
1450N/A intel_sdvo->color_range = HDMI_COLOR_RANGE_16_235;
1450N/A break;
1450N/A default:
1450N/A return -EINVAL;
1450N/A }
1450N/A
1450N/A if (old_auto == intel_sdvo->color_range_auto &&
1450N/A old_range == intel_sdvo->color_range)
1450N/A return 0;
1450N/A
1450N/A goto done;
1450N/A }
1450N/A
1450N/A#define CHECK_PROPERTY(name, NAME) \
1450N/A if (intel_sdvo_connector->name == property) { \
1450N/A if (intel_sdvo_connector->cur_##name == temp_value) return 0; \
1450N/A if (intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
1450N/A cmd = SDVO_CMD_SET_##NAME; \
1450N/A intel_sdvo_connector->cur_##name = temp_value; \
1450N/A goto set_value; \
1450N/A }
1450N/A
1450N/A if (property == intel_sdvo_connector->tv_format) {
1450N/A if (val >= TV_FORMAT_NUM)
1450N/A return -EINVAL;
1450N/A
1450N/A if (intel_sdvo->tv_format_index ==
1450N/A intel_sdvo_connector->tv_format_supported[val])
1450N/A return 0;
1450N/A
1450N/A intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[val];
1450N/A goto done;
1450N/A } else if (IS_TV_OR_LVDS(intel_sdvo_connector)) {
1450N/A temp_value = (uint16_t)val;
1450N/A if (intel_sdvo_connector->left == property) {
1450N/A drm_object_property_set_value(&connector->base,
1450N/A intel_sdvo_connector->right, val);
1450N/A if (intel_sdvo_connector->left_margin == temp_value)
1450N/A return 0;
1450N/A
1450N/A intel_sdvo_connector->left_margin = temp_value;
1450N/A intel_sdvo_connector->right_margin = temp_value;
1450N/A temp_value = intel_sdvo_connector->max_hscan -
1450N/A intel_sdvo_connector->left_margin;
1450N/A cmd = SDVO_CMD_SET_OVERSCAN_H;
1450N/A goto set_value;
1450N/A } else if (intel_sdvo_connector->right == property) {
1450N/A drm_object_property_set_value(&connector->base,
1450N/A intel_sdvo_connector->left, val);
1450N/A if (intel_sdvo_connector->right_margin == temp_value)
1450N/A return 0;
1450N/A
1450N/A intel_sdvo_connector->left_margin = temp_value;
1450N/A intel_sdvo_connector->right_margin = temp_value;
1450N/A temp_value = intel_sdvo_connector->max_hscan -
1450N/A intel_sdvo_connector->left_margin;
1450N/A cmd = SDVO_CMD_SET_OVERSCAN_H;
1450N/A goto set_value;
1450N/A } else if (intel_sdvo_connector->top == property) {
1450N/A drm_object_property_set_value(&connector->base,
1450N/A intel_sdvo_connector->bottom, val);
1450N/A if (intel_sdvo_connector->top_margin == temp_value)
1450N/A return 0;
1450N/A
1450N/A intel_sdvo_connector->top_margin = temp_value;
1450N/A intel_sdvo_connector->bottom_margin = temp_value;
1450N/A temp_value = intel_sdvo_connector->max_vscan -
1450N/A intel_sdvo_connector->top_margin;
1450N/A cmd = SDVO_CMD_SET_OVERSCAN_V;
1450N/A goto set_value;
1450N/A } else if (intel_sdvo_connector->bottom == property) {
1450N/A drm_object_property_set_value(&connector->base,
1450N/A intel_sdvo_connector->top, val);
1450N/A if (intel_sdvo_connector->bottom_margin == temp_value)
1450N/A return 0;
1450N/A
1450N/A intel_sdvo_connector->top_margin = temp_value;
1450N/A intel_sdvo_connector->bottom_margin = temp_value;
1450N/A temp_value = intel_sdvo_connector->max_vscan -
1450N/A intel_sdvo_connector->top_margin;
1450N/A cmd = SDVO_CMD_SET_OVERSCAN_V;
1450N/A goto set_value;
1450N/A }
1450N/A CHECK_PROPERTY(hpos, HPOS)
1450N/A CHECK_PROPERTY(vpos, VPOS)
1450N/A CHECK_PROPERTY(saturation, SATURATION)
1450N/A CHECK_PROPERTY(contrast, CONTRAST)
1450N/A CHECK_PROPERTY(hue, HUE)
1450N/A CHECK_PROPERTY(brightness, BRIGHTNESS)
1450N/A CHECK_PROPERTY(sharpness, SHARPNESS)
1450N/A CHECK_PROPERTY(flicker_filter, FLICKER_FILTER)
1450N/A CHECK_PROPERTY(flicker_filter_2d, FLICKER_FILTER_2D)
1450N/A CHECK_PROPERTY(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE)
1450N/A CHECK_PROPERTY(tv_chroma_filter, TV_CHROMA_FILTER)
1450N/A CHECK_PROPERTY(tv_luma_filter, TV_LUMA_FILTER)
1450N/A CHECK_PROPERTY(dot_crawl, DOT_CRAWL)
1450N/A }
1450N/A
1450N/A return -EINVAL; /* unknown property */
1450N/A
1450N/Aset_value:
1450N/A if (!intel_sdvo_set_value(intel_sdvo, cmd, &temp_value, 2))
1450N/A return -EIO;
1450N/A
1450N/A
1450N/Adone:
1450N/A if (intel_sdvo->base.base.crtc)
1450N/A intel_crtc_restore_mode(intel_sdvo->base.base.crtc);
1450N/A
1450N/A return 0;
1450N/A#undef CHECK_PROPERTY
1450N/A}
1450N/A
1450N/Astatic const struct drm_connector_funcs intel_sdvo_connector_funcs = {
1450N/A .dpms = intel_sdvo_dpms,
1450N/A .detect = intel_sdvo_detect,
1450N/A .fill_modes = drm_helper_probe_single_connector_modes,
1450N/A .set_property = intel_sdvo_set_property,
1450N/A .destroy = intel_sdvo_destroy,
1450N/A};
1450N/A
1450N/Astatic const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
1450N/A .get_modes = intel_sdvo_get_modes,
1450N/A .mode_valid = intel_sdvo_mode_valid,
1450N/A .best_encoder = intel_best_encoder,
1450N/A};
1450N/A
1450N/Astatic void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
1450N/A{
1450N/A struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
1450N/A
1450N/A if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
1450N/A drm_mode_destroy(encoder->dev,
1450N/A intel_sdvo->sdvo_lvds_fixed_mode);
1450N/A
1450N/A /* OSOL i2c_del_adapter(&intel_sdvo->ddc); */
1450N/A intel_encoder_destroy(encoder);
1450N/A}
1450N/A
1450N/Astatic const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
1450N/A .destroy = intel_sdvo_enc_destroy,
1450N/A};
1450N/A
1450N/Astatic void
1450N/Aintel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
1450N/A{
1450N/A uint16_t mask = 0;
1450N/A unsigned int num_bits;
1450N/A
1450N/A /* Make a mask of outputs less than or equal to our own priority in the
1450N/A * list.
1450N/A */
1450N/A switch (sdvo->controlled_output) {
1450N/A case SDVO_OUTPUT_LVDS1:
1450N/A mask |= SDVO_OUTPUT_LVDS1;
1450N/A case SDVO_OUTPUT_LVDS0:
1450N/A mask |= SDVO_OUTPUT_LVDS0;
1450N/A case SDVO_OUTPUT_TMDS1:
1450N/A mask |= SDVO_OUTPUT_TMDS1;
1450N/A case SDVO_OUTPUT_TMDS0:
1450N/A mask |= SDVO_OUTPUT_TMDS0;
1450N/A case SDVO_OUTPUT_RGB1:
1450N/A mask |= SDVO_OUTPUT_RGB1;
1450N/A case SDVO_OUTPUT_RGB0:
1450N/A mask |= SDVO_OUTPUT_RGB0;
1450N/A break;
1450N/A }
1450N/A
1450N/A /* Count bits to find what number we are in the priority list. */
1450N/A mask &= sdvo->caps.output_flags;
1450N/A num_bits = hweight16(mask);
1450N/A /* If more than 3 outputs, default to DDC bus 3 for now. */
1450N/A if (num_bits > 3)
1450N/A num_bits = 3;
1450N/A
1450N/A /* Corresponds to SDVO_CONTROL_BUS_DDCx */
1450N/A sdvo->ddc_bus = 1 << num_bits;
1450N/A}
1450N/A
1450N/A/**
1450N/A * Choose the appropriate DDC bus for control bus switch command for this
1450N/A * SDVO output based on the controlled output.
1450N/A *
1450N/A * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
1450N/A * outputs, then LVDS outputs.
1450N/A */
1450N/Astatic void
1450N/Aintel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
1450N/A struct intel_sdvo *sdvo, u32 reg)
1450N/A{
1450N/A struct sdvo_device_mapping *mapping;
1450N/A
1450N/A if (sdvo->is_sdvob)
1450N/A mapping = &(dev_priv->sdvo_mappings[0]);
1450N/A else
1450N/A mapping = &(dev_priv->sdvo_mappings[1]);
1450N/A
1450N/A if (mapping->initialized)
1450N/A sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
1450N/A else
1450N/A intel_sdvo_guess_ddc_bus(sdvo);
1450N/A}
1450N/A
1450N/Astatic void
1450N/Aintel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
1450N/A struct intel_sdvo *sdvo, u32 reg)
1450N/A{
1450N/A struct sdvo_device_mapping *mapping;
1450N/A u8 pin;
1450N/A
1450N/A if (sdvo->is_sdvob)
1450N/A mapping = &dev_priv->sdvo_mappings[0];
1450N/A else
1450N/A mapping = &dev_priv->sdvo_mappings[1];
1450N/A
1450N/A if (mapping->initialized && intel_gmbus_is_port_valid(mapping->i2c_pin))
1450N/A pin = mapping->i2c_pin;
1450N/A else
1450N/A pin = GMBUS_PORT_DPB;
1450N/A
1450N/A sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
1450N/A
1450N/A /* With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
1450N/A * our code totally fails once we start using gmbus. Hence fall back to
1450N/A * bit banging for now. */
1450N/A intel_gmbus_force_bit(sdvo->i2c, true);
1450N/A}
1450N/A
1450N/A/* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
1450N/Astatic void
1450N/Aintel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
1450N/A{
1450N/A intel_gmbus_force_bit(sdvo->i2c, false);
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)
1450N/A{
1450N/A return intel_sdvo_check_supp_encode(intel_sdvo);
1450N/A}
1450N/A
1450N/Astatic u8
1450N/Aintel_sdvo_get_slave_addr(struct drm_device *dev, struct intel_sdvo *sdvo)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct sdvo_device_mapping *my_mapping, *other_mapping;
1450N/A
1450N/A if (sdvo->is_sdvob) {
1450N/A my_mapping = &dev_priv->sdvo_mappings[0];
1450N/A other_mapping = &dev_priv->sdvo_mappings[1];
1450N/A } else {
1450N/A my_mapping = &dev_priv->sdvo_mappings[1];
1450N/A other_mapping = &dev_priv->sdvo_mappings[0];
1450N/A }
1450N/A
1450N/A /* If the BIOS described our SDVO device, take advantage of it. */
1450N/A if (my_mapping->slave_addr)
1450N/A return my_mapping->slave_addr;
1450N/A
1450N/A /* If the BIOS only described a different SDVO device, use the
1450N/A * address that it isn't using.
1450N/A */
1450N/A if (other_mapping->slave_addr) {
1450N/A if (other_mapping->slave_addr == 0x70)
1450N/A return 0x72;
1450N/A else
1450N/A return 0x70;
1450N/A }
1450N/A
1450N/A /* No SDVO device info is found for another DVO port,
1450N/A * so use mapping assumption we had before BIOS parsing.
1450N/A */
1450N/A if (sdvo->is_sdvob)
1450N/A return 0x70;
1450N/A else
1450N/A return 0x72;
1450N/A}
1450N/A
1450N/Astatic void
1450N/Aintel_sdvo_connector_init(struct intel_sdvo_connector *connector,
1450N/A struct intel_sdvo *encoder)
1450N/A{
1450N/A (void) drm_connector_init(encoder->base.base.dev,
1450N/A &connector->base.base,
1450N/A &intel_sdvo_connector_funcs,
1450N/A connector->base.base.connector_type);
1450N/A
1450N/A drm_connector_helper_add(&connector->base.base,
1450N/A &intel_sdvo_connector_helper_funcs);
1450N/A
1450N/A connector->base.base.interlace_allowed = 1;
1450N/A connector->base.base.doublescan_allowed = 0;
1450N/A connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
1450N/A connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
1450N/A
1450N/A intel_connector_attach_encoder(&connector->base, &encoder->base);
1450N/A}
1450N/A
1450N/Astatic void
1450N/Aintel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *connector)
1450N/A{
1450N/A struct drm_device *dev = connector->base.base.dev;
1450N/A
1450N/A intel_attach_force_audio_property(&connector->base.base);
1450N/A if (INTEL_INFO(dev)->gen >= 4 && IS_MOBILE(dev)) {
1450N/A intel_attach_broadcast_rgb_property(&connector->base.base);
1450N/A intel_sdvo->color_range_auto = true;
1450N/A }
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
1450N/A{
1450N/A struct drm_encoder *encoder = &intel_sdvo->base.base;
1450N/A struct drm_connector *connector;
1450N/A struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1450N/A struct intel_connector *intel_connector;
1450N/A struct intel_sdvo_connector *intel_sdvo_connector;
1450N/A
1450N/A intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
1450N/A if (!intel_sdvo_connector)
1450N/A return false;
1450N/A
1450N/A if (device == 0) {
1450N/A intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
1450N/A intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
1450N/A } else if (device == 1) {
1450N/A intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
1450N/A intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
1450N/A }
1450N/A
1450N/A intel_connector = &intel_sdvo_connector->base;
1450N/A connector = &intel_connector->base;
1450N/A if (intel_sdvo_get_hotplug_support(intel_sdvo) &
1450N/A intel_sdvo_connector->output_flag) {
1450N/A intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
1450N/A /* Some SDVO devices have one-shot hotplug interrupts.
1450N/A * Ensure that they get re-enabled when an interrupt happens.
1450N/A */
1450N/A intel_encoder->hot_plug = intel_sdvo_enable_hotplug;
1450N/A intel_sdvo_enable_hotplug(intel_encoder);
1450N/A } else {
1450N/A intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
1450N/A }
1450N/A encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
1450N/A connector->connector_type = DRM_MODE_CONNECTOR_DVID;
1450N/A
1450N/A if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
1450N/A connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
1450N/A intel_sdvo->is_hdmi = true;
1450N/A }
1450N/A
1450N/A intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
1450N/A if (intel_sdvo->is_hdmi)
1450N/A intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
1450N/A{
1450N/A struct drm_encoder *encoder = &intel_sdvo->base.base;
1450N/A struct drm_connector *connector;
1450N/A struct intel_connector *intel_connector;
1450N/A struct intel_sdvo_connector *intel_sdvo_connector;
1450N/A
1450N/A intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
1450N/A if (!intel_sdvo_connector)
1450N/A return false;
1450N/A
1450N/A intel_connector = &intel_sdvo_connector->base;
1450N/A connector = &intel_connector->base;
1450N/A encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
1450N/A connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
1450N/A
1450N/A intel_sdvo->controlled_output |= type;
1450N/A intel_sdvo_connector->output_flag = (u16)type;
1450N/A
1450N/A intel_sdvo->is_tv = true;
1450N/A
1450N/A intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
1450N/A
1450N/A if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
1450N/A goto err;
1450N/A
1450N/A if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
1450N/A goto err;
1450N/A
1450N/A return true;
1450N/A
1450N/Aerr:
1450N/A intel_sdvo_destroy(connector);
1450N/A return false;
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
1450N/A{
1450N/A struct drm_encoder *encoder = &intel_sdvo->base.base;
1450N/A struct drm_connector *connector;
1450N/A struct intel_connector *intel_connector;
1450N/A struct intel_sdvo_connector *intel_sdvo_connector;
1450N/A
1450N/A intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
1450N/A if (!intel_sdvo_connector)
1450N/A return false;
1450N/A
1450N/A intel_connector = &intel_sdvo_connector->base;
1450N/A connector = &intel_connector->base;
1450N/A intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1450N/A encoder->encoder_type = DRM_MODE_ENCODER_DAC;
1450N/A connector->connector_type = DRM_MODE_CONNECTOR_VGA;
1450N/A
1450N/A if (device == 0) {
1450N/A intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
1450N/A intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
1450N/A } else if (device == 1) {
1450N/A intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
1450N/A intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
1450N/A }
1450N/A
1450N/A intel_sdvo_connector_init(intel_sdvo_connector,
1450N/A intel_sdvo);
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
1450N/A{
1450N/A struct drm_encoder *encoder = &intel_sdvo->base.base;
1450N/A struct drm_connector *connector;
1450N/A struct intel_connector *intel_connector;
1450N/A struct intel_sdvo_connector *intel_sdvo_connector;
1450N/A
1450N/A intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
1450N/A if (!intel_sdvo_connector)
1450N/A return false;
1450N/A
1450N/A intel_connector = &intel_sdvo_connector->base;
1450N/A connector = &intel_connector->base;
1450N/A encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
1450N/A connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
1450N/A
1450N/A if (device == 0) {
1450N/A intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
1450N/A intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
1450N/A } else if (device == 1) {
1450N/A intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
1450N/A intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
1450N/A }
1450N/A
1450N/A intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
1450N/A if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
1450N/A goto err;
1450N/A
1450N/A return true;
1450N/A
1450N/Aerr:
1450N/A intel_sdvo_destroy(connector);
1450N/A return false;
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
1450N/A{
1450N/A intel_sdvo->is_tv = false;
1450N/A intel_sdvo->is_lvds = false;
1450N/A
1450N/A /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
1450N/A
1450N/A if (flags & SDVO_OUTPUT_TMDS0)
1450N/A if (!intel_sdvo_dvi_init(intel_sdvo, 0))
1450N/A return false;
1450N/A
1450N/A if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
1450N/A if (!intel_sdvo_dvi_init(intel_sdvo, 1))
1450N/A return false;
1450N/A
1450N/A /* TV has no XXX1 function block */
1450N/A if (flags & SDVO_OUTPUT_SVID0)
1450N/A if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
1450N/A return false;
1450N/A
1450N/A if (flags & SDVO_OUTPUT_CVBS0)
1450N/A if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
1450N/A return false;
1450N/A
1450N/A if (flags & SDVO_OUTPUT_YPRPB0)
1450N/A if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
1450N/A return false;
1450N/A
1450N/A if (flags & SDVO_OUTPUT_RGB0)
1450N/A if (!intel_sdvo_analog_init(intel_sdvo, 0))
1450N/A return false;
1450N/A
1450N/A if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
1450N/A if (!intel_sdvo_analog_init(intel_sdvo, 1))
1450N/A return false;
1450N/A
1450N/A if (flags & SDVO_OUTPUT_LVDS0)
1450N/A if (!intel_sdvo_lvds_init(intel_sdvo, 0))
1450N/A return false;
1450N/A
1450N/A if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
1450N/A if (!intel_sdvo_lvds_init(intel_sdvo, 1))
1450N/A return false;
1450N/A
1450N/A if ((flags & SDVO_OUTPUT_MASK) == 0) {
1450N/A unsigned char bytes[2];
1450N/A
1450N/A intel_sdvo->controlled_output = 0;
1450N/A memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
1450N/A DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
1450N/A SDVO_NAME(intel_sdvo),
1450N/A bytes[0], bytes[1]);
1450N/A return false;
1450N/A }
1450N/A intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
1450N/A{
1450N/A struct drm_device *dev = intel_sdvo->base.base.dev;
1450N/A struct drm_connector *connector, *tmp;
1450N/A
1450N/A list_for_each_entry_safe(connector, tmp, struct drm_connector,
1450N/A &dev->mode_config.connector_list, head) {
1450N/A if (intel_attached_encoder(connector) == &intel_sdvo->base)
1450N/A intel_sdvo_destroy(connector);
1450N/A }
1450N/A}
1450N/A
1450N/Astatic bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *intel_sdvo_connector,
1450N/A int type)
1450N/A{
1450N/A struct drm_device *dev = intel_sdvo->base.base.dev;
1450N/A struct intel_sdvo_tv_format format;
1450N/A uint32_t format_map, i;
1450N/A
1450N/A if (!intel_sdvo_set_target_output(intel_sdvo, type))
1450N/A return false;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
1450N/A &format, sizeof(format)))
1450N/A return false;
1450N/A
1450N/A memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
1450N/A
1450N/A if (format_map == 0)
1450N/A return false;
1450N/A
1450N/A intel_sdvo_connector->format_supported_num = 0;
1450N/A for (i = 0 ; i < TV_FORMAT_NUM; i++)
1450N/A if (format_map & (1 << i))
1450N/A intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = (u8)i;
1450N/A
1450N/A
1450N/A intel_sdvo_connector->tv_format =
1450N/A drm_property_create(dev, DRM_MODE_PROP_ENUM,
1450N/A "mode", intel_sdvo_connector->format_supported_num);
1450N/A if (!intel_sdvo_connector->tv_format)
1450N/A return false;
1450N/A
1450N/A for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
1450N/A drm_property_add_enum(
1450N/A intel_sdvo_connector->tv_format, i,
1450N/A i, tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
1450N/A
1450N/A intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[0];
1450N/A drm_object_attach_property(&intel_sdvo_connector->base.base.base,
1450N/A intel_sdvo_connector->tv_format, 0);
1450N/A return true;
1450N/A
1450N/A}
1450N/A
1450N/A#define ENHANCEMENT(name, NAME) do { \
1450N/A if (enhancements.name) { \
1450N/A if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
1450N/A !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
1450N/A return false; \
1450N/A intel_sdvo_connector->max_##name = data_value[0]; \
1450N/A intel_sdvo_connector->cur_##name = response; \
1450N/A intel_sdvo_connector->name = \
1450N/A drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
1450N/A if (!intel_sdvo_connector->name) return false; \
1450N/A drm_object_attach_property(&connector->base, \
1450N/A intel_sdvo_connector->name, \
1450N/A intel_sdvo_connector->cur_##name); \
1450N/A DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
1450N/A data_value[0], data_value[1], response); \
1450N/A } \
1450N/A} while(0)
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *intel_sdvo_connector,
1450N/A struct intel_sdvo_enhancements_reply enhancements)
1450N/A{
1450N/A struct drm_device *dev = intel_sdvo->base.base.dev;
1450N/A struct drm_connector *connector = &intel_sdvo_connector->base.base;
1450N/A uint16_t response, data_value[2];
1450N/A
1450N/A /* when horizontal overscan is supported, Add the left/right property */
1450N/A if (enhancements.overscan_h) {
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_MAX_OVERSCAN_H,
1450N/A &data_value, 4))
1450N/A return false;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_OVERSCAN_H,
1450N/A &response, 2))
1450N/A return false;
1450N/A
1450N/A intel_sdvo_connector->max_hscan = data_value[0];
1450N/A intel_sdvo_connector->left_margin = data_value[0] - response;
1450N/A intel_sdvo_connector->right_margin = intel_sdvo_connector->left_margin;
1450N/A intel_sdvo_connector->left =
1450N/A drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
1450N/A if (!intel_sdvo_connector->left)
1450N/A return false;
1450N/A
1450N/A drm_object_attach_property(&connector->base,
1450N/A intel_sdvo_connector->left,
1450N/A intel_sdvo_connector->left_margin);
1450N/A
1450N/A intel_sdvo_connector->right =
1450N/A drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
1450N/A if (!intel_sdvo_connector->right)
1450N/A return false;
1450N/A
1450N/A drm_object_attach_property(&connector->base,
1450N/A intel_sdvo_connector->right,
1450N/A intel_sdvo_connector->right_margin);
1450N/A DRM_DEBUG_KMS("h_overscan: max %d, "
1450N/A "default %d, current %d\n",
1450N/A data_value[0], data_value[1], response);
1450N/A }
1450N/A
1450N/A if (enhancements.overscan_v) {
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_MAX_OVERSCAN_V,
1450N/A &data_value, 4))
1450N/A return false;
1450N/A
1450N/A if (!intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_OVERSCAN_V,
1450N/A &response, 2))
1450N/A return false;
1450N/A
1450N/A intel_sdvo_connector->max_vscan = data_value[0];
1450N/A intel_sdvo_connector->top_margin = data_value[0] - response;
1450N/A intel_sdvo_connector->bottom_margin = intel_sdvo_connector->top_margin;
1450N/A intel_sdvo_connector->top =
1450N/A drm_property_create_range(dev, 0,
1450N/A "top_margin", 0, data_value[0]);
1450N/A if (!intel_sdvo_connector->top)
1450N/A return false;
1450N/A
1450N/A drm_object_attach_property(&connector->base,
1450N/A intel_sdvo_connector->top,
1450N/A intel_sdvo_connector->top_margin);
1450N/A
1450N/A intel_sdvo_connector->bottom =
1450N/A drm_property_create_range(dev, 0,
1450N/A "bottom_margin", 0, data_value[0]);
1450N/A if (!intel_sdvo_connector->bottom)
1450N/A return false;
1450N/A
1450N/A drm_object_attach_property(&connector->base,
1450N/A intel_sdvo_connector->bottom,
1450N/A intel_sdvo_connector->bottom_margin);
1450N/A DRM_DEBUG_KMS("v_overscan: max %d, "
1450N/A "default %d, current %d\n",
1450N/A data_value[0], data_value[1], response);
1450N/A }
1450N/A
1450N/A ENHANCEMENT(hpos, HPOS);
1450N/A ENHANCEMENT(vpos, VPOS);
1450N/A ENHANCEMENT(saturation, SATURATION);
1450N/A ENHANCEMENT(contrast, CONTRAST);
1450N/A ENHANCEMENT(hue, HUE);
1450N/A ENHANCEMENT(sharpness, SHARPNESS);
1450N/A ENHANCEMENT(brightness, BRIGHTNESS);
1450N/A ENHANCEMENT(flicker_filter, FLICKER_FILTER);
1450N/A ENHANCEMENT(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
1450N/A ENHANCEMENT(flicker_filter_2d, FLICKER_FILTER_2D);
1450N/A ENHANCEMENT(tv_chroma_filter, TV_CHROMA_FILTER);
1450N/A ENHANCEMENT(tv_luma_filter, TV_LUMA_FILTER);
1450N/A
1450N/A if (enhancements.dot_crawl) {
1450N/A if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
1450N/A return false;
1450N/A
1450N/A intel_sdvo_connector->max_dot_crawl = 1;
1450N/A intel_sdvo_connector->cur_dot_crawl = response & 0x1;
1450N/A intel_sdvo_connector->dot_crawl =
1450N/A drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
1450N/A if (!intel_sdvo_connector->dot_crawl)
1450N/A return false;
1450N/A
1450N/A drm_object_attach_property(&connector->base,
1450N/A intel_sdvo_connector->dot_crawl,
1450N/A intel_sdvo_connector->cur_dot_crawl);
1450N/A DRM_DEBUG_KMS("dot crawl: current %d\n", response);
1450N/A }
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *intel_sdvo_connector,
1450N/A struct intel_sdvo_enhancements_reply enhancements)
1450N/A{
1450N/A struct drm_device *dev = intel_sdvo->base.base.dev;
1450N/A struct drm_connector *connector = &intel_sdvo_connector->base.base;
1450N/A uint16_t response, data_value[2];
1450N/A
1450N/A ENHANCEMENT(brightness, BRIGHTNESS);
1450N/A
1450N/A return true;
1450N/A}
1450N/A#undef ENHANCEMENT
1450N/A
1450N/Astatic bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
1450N/A struct intel_sdvo_connector *intel_sdvo_connector)
1450N/A{
1450N/A union {
1450N/A struct intel_sdvo_enhancements_reply reply;
1450N/A uint16_t response;
1450N/A } enhancements;
1450N/A
1450N/A enhancements.response = 0;
1450N/A (void) intel_sdvo_get_value(intel_sdvo,
1450N/A SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
1450N/A &enhancements, sizeof(enhancements));
1450N/A if (enhancements.response == 0) {
1450N/A DRM_DEBUG_KMS("No enhancement is supported\n");
1450N/A return true;
1450N/A }
1450N/A
1450N/A if (IS_TV(intel_sdvo_connector))
1450N/A return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
1450N/A else if(IS_LVDS(intel_sdvo_connector))
1450N/A return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
1450N/A else
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
1450N/A struct i2c_msg *msgs,
1450N/A int num)
1450N/A{
1450N/A struct intel_sdvo *sdvo = adapter->algo_data;
1450N/A
1450N/A if (!intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
1450N/A return -EIO;
1450N/A
1450N/A return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
1450N/A}
1450N/A
1450N/Astatic u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
1450N/A{
1450N/A struct intel_sdvo *sdvo = adapter->algo_data;
1450N/A return sdvo->i2c->algo->functionality(sdvo->i2c);
1450N/A}
1450N/A
1450N/Astruct i2c_algorithm intel_sdvo_ddc_proxy = {
1450N/A .master_xfer = intel_sdvo_ddc_proxy_xfer,
1450N/A .functionality = intel_sdvo_ddc_proxy_func
1450N/A};
1450N/A
1450N/Astatic bool
1450N/Aintel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
1450N/A struct drm_device *dev)
1450N/A{
1450N/A /* OSOL_i915: sdvo->ddc.owner = THIS_MODULE; */
1450N/A /* OSOL_i915: sdvo->ddc.class = I2C_CLASS_DDC; */
1450N/A snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
1450N/A /* OSOL_i915: sdvo->ddc.dev.parent = &dev->pdev->dev; */
1450N/A sdvo->ddc.algo_data = sdvo;
1450N/A sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
1450N/A return 1;
1450N/A /* OSOL_i915: return i2c_add_adapter(&sdvo->ddc) == 0; */
1450N/A}
1450N/A
1450N/Abool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_encoder *intel_encoder;
1450N/A struct intel_sdvo *intel_sdvo;
1450N/A int i;
1450N/A intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
1450N/A if (!intel_sdvo)
1450N/A return false;
1450N/A
1450N/A intel_sdvo->sdvo_reg = sdvo_reg;
1450N/A intel_sdvo->is_sdvob = is_sdvob;
1450N/A intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, intel_sdvo) >> 1;
1450N/A intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg);
1450N/A if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev))
1450N/A goto err_i2c_bus;
1450N/A
1450N/A /* encoder type will be decided later */
1450N/A intel_encoder = &intel_sdvo->base;
1450N/A intel_encoder->type = INTEL_OUTPUT_SDVO;
1450N/A intel_encoder->type_size = sizeof(struct intel_sdvo);
1450N/A drm_encoder_init(dev, &intel_encoder->base, &intel_sdvo_enc_funcs, 0);
1450N/A
1450N/A /* Read the regs to test if we can talk to the device */
1450N/A for (i = 0; i < 0x40; i++) {
1450N/A u8 byte;
1450N/A
1450N/A if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
1450N/A DRM_DEBUG_KMS("No SDVO device found on %s\n",
1450N/A SDVO_NAME(intel_sdvo));
1450N/A goto err;
1450N/A }
1450N/A }
1450N/A
1450N/A intel_encoder->compute_config = intel_sdvo_compute_config;
1450N/A intel_encoder->disable = intel_disable_sdvo;
1450N/A intel_encoder->mode_set = intel_sdvo_mode_set;
1450N/A intel_encoder->enable = intel_enable_sdvo;
1450N/A intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
1450N/A intel_encoder->get_config = intel_sdvo_get_config;
1450N/A
1450N/A /* In default case sdvo lvds is false */
1450N/A if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
1450N/A goto err;
1450N/A
1450N/A if (intel_sdvo_output_setup(intel_sdvo,
1450N/A intel_sdvo->caps.output_flags) != true) {
1450N/A DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
1450N/A SDVO_NAME(intel_sdvo));
1450N/A /* Output_setup can leave behind connectors! */
1450N/A goto err_output;
1450N/A }
1450N/A
1450N/A /* Only enable the hotplug irq if we need it, to work around noisy
1450N/A * hotplug lines.
1450N/A */
1450N/A if (intel_sdvo->hotplug_active) {
1450N/A intel_encoder->hpd_pin =
1450N/A intel_sdvo->is_sdvob ? HPD_SDVO_B : HPD_SDVO_C;
1450N/A }
1450N/A
1450N/A /*
1450N/A * Cloning SDVO with anything is often impossible, since the SDVO
1450N/A * encoder can request a special input timing mode. And even if that's
1450N/A * not the case we have evidence that cloning a plain unscaled mode with
1450N/A * VGA doesn't really work. Furthermore the cloning flags are way too
1450N/A * simplistic anyway to express such constraints, so just give up on
1450N/A * cloning for SDVO encoders.
1450N/A */
1450N/A intel_sdvo->base.cloneable = false;
1450N/A
1450N/A intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
1450N/A
1450N/A /* Set the input timing to the screen. Assume always input 0. */
1450N/A if (!intel_sdvo_set_target_input(intel_sdvo))
1450N/A goto err_output;
1450N/A
1450N/A if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
1450N/A &intel_sdvo->pixel_clock_min,
1450N/A &intel_sdvo->pixel_clock_max))
1450N/A goto err_output;
1450N/A
1450N/A DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
1450N/A "clock range %dMHz - %dMHz, "
1450N/A "input 1: %c, input 2: %c, "
1450N/A "output 1: %c, output 2: %c\n",
1450N/A SDVO_NAME(intel_sdvo),
1450N/A intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
1450N/A intel_sdvo->caps.device_rev_id,
1450N/A intel_sdvo->pixel_clock_min / 1000,
1450N/A intel_sdvo->pixel_clock_max / 1000,
1450N/A (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
1450N/A (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
1450N/A /* check currently supported outputs */
1450N/A intel_sdvo->caps.output_flags &
1450N/A (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
1450N/A intel_sdvo->caps.output_flags &
1450N/A (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
1450N/A return true;
1450N/A
1450N/Aerr_output:
1450N/A intel_sdvo_output_cleanup(intel_sdvo);
1450N/A
1450N/Aerr:
1450N/A drm_encoder_cleanup(&intel_encoder->base);
1450N/A// i2c_del_adapter(&intel_sdvo->ddc);
1450N/Aerr_i2c_bus:
1450N/A intel_sdvo_unselect_i2c_bus(intel_sdvo);
1450N/A kfree(intel_sdvo, sizeof(*intel_sdvo));
1450N/A
1450N/A return false;
1450N/A}