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-2009, 2013, Intel Corporation
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 * Jesse Barnes <jesse.barnes@intel.com>
1450N/A */
1450N/A
1450N/A#include "drmP.h"
1450N/A#include "drm.h"
1450N/A#include "drm_crtc.h"
1450N/A#include "drm_edid.h"
1450N/A#include "intel_drv.h"
1450N/A#include "i915_drm.h"
1450N/A#include "i915_drv.h"
1450N/A#include "drm_sun_i2c.h" /* OSOL_i915 */
1450N/A
1450N/Astatic struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
1450N/A{
1450N/A return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
1450N/A}
1450N/A
1450N/Astatic void
1450N/Aassert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
1450N/A{
1450N/A struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A uint32_t enabled_bits;
1450N/A
1450N/A enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
1450N/A
1450N/A if (I915_READ(intel_hdmi->hdmi_reg) & enabled_bits)
1450N/A DRM_ERROR("HDMI port enabled, expecting disabled\n");
1450N/A}
1450N/A
1450N/Astruct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
1450N/A{
1450N/A struct intel_digital_port *intel_dig_port =
1450N/A container_of(encoder, struct intel_digital_port, base.base);
1450N/A return &intel_dig_port->hdmi;
1450N/A}
1450N/A
1450N/Astatic struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
1450N/A{
1450N/A return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
1450N/A}
1450N/A
1450N/Avoid intel_dip_infoframe_csum(struct dip_infoframe *frame)
1450N/A{
1450N/A uint8_t *data = (uint8_t *)frame;
1450N/A uint8_t sum = 0;
1450N/A unsigned i;
1450N/A
1450N/A frame->checksum = 0;
1450N/A frame->ecc = 0;
1450N/A
1450N/A for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
1450N/A sum += data[i];
1450N/A
1450N/A frame->checksum = 0x100 - sum;
1450N/A}
1450N/A
1450N/Astatic u32 g4x_infoframe_index(struct dip_infoframe *frame)
1450N/A{
1450N/A switch (frame->type) {
1450N/A case DIP_TYPE_AVI:
1450N/A return VIDEO_DIP_SELECT_AVI;
1450N/A case DIP_TYPE_SPD:
1450N/A return VIDEO_DIP_SELECT_SPD;
1450N/A default:
1450N/A DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
1450N/A return 0;
1450N/A }
1450N/A}
1450N/A
1450N/Astatic u32 g4x_infoframe_enable(struct dip_infoframe *frame)
1450N/A{
1450N/A switch (frame->type) {
1450N/A case DIP_TYPE_AVI:
1450N/A return VIDEO_DIP_ENABLE_AVI;
1450N/A case DIP_TYPE_SPD:
1450N/A return VIDEO_DIP_ENABLE_SPD;
1450N/A default:
1450N/A DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
1450N/A return 0;
1450N/A }
1450N/A}
1450N/A
1450N/Astatic u32 hsw_infoframe_enable(struct dip_infoframe *frame)
1450N/A{
1450N/A switch (frame->type) {
1450N/A case DIP_TYPE_AVI:
1450N/A return VIDEO_DIP_ENABLE_AVI_HSW;
1450N/A case DIP_TYPE_SPD:
1450N/A return VIDEO_DIP_ENABLE_SPD_HSW;
1450N/A default:
1450N/A DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
1450N/A return 0;
1450N/A }
1450N/A}
1450N/A
1450N/Astatic u32 hsw_infoframe_data_reg(struct dip_infoframe *frame,
1450N/A enum transcoder cpu_transcoder)
1450N/A{
1450N/A switch (frame->type) {
1450N/A case DIP_TYPE_AVI:
1450N/A return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
1450N/A case DIP_TYPE_SPD:
1450N/A return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
1450N/A default:
1450N/A DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
1450N/A return 0;
1450N/A }
1450N/A}
1450N/A
1450N/Astatic void g4x_write_infoframe(struct drm_encoder *encoder,
1450N/A struct dip_infoframe *frame)
1450N/A{
1450N/A /* LINTED */
1450N/A uint32_t *data = (uint32_t *)frame;
1450N/A struct drm_device *dev = encoder->dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A u32 val = I915_READ(VIDEO_DIP_CTL);
1450N/A unsigned i, len = DIP_HEADER_SIZE + frame->len;
1450N/A
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A DRM_ERROR("Writing DIP with CTL reg disabled\n");
1450N/A
1450N/A val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
1450N/A val |= g4x_infoframe_index(frame);
1450N/A
1450N/A val &= ~g4x_infoframe_enable(frame);
1450N/A
1450N/A I915_WRITE(VIDEO_DIP_CTL, val);
1450N/A
1450N/A// mmiowb();
1450N/A for (i = 0; i < len; i += 4) {
1450N/A I915_WRITE(VIDEO_DIP_DATA, *data);
1450N/A data++;
1450N/A }
1450N/A /* Write every possible data byte to force correct ECC calculation. */
1450N/A for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
1450N/A I915_WRITE(VIDEO_DIP_DATA, 0);
1450N/A// mmiowb();
1450N/A
1450N/A val |= g4x_infoframe_enable(frame);
1450N/A val &= ~VIDEO_DIP_FREQ_MASK;
1450N/A val |= VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A I915_WRITE(VIDEO_DIP_CTL, val);
1450N/A POSTING_READ(VIDEO_DIP_CTL);
1450N/A}
1450N/A
1450N/Astatic void ibx_write_infoframe(struct drm_encoder *encoder,
1450N/A struct dip_infoframe *frame)
1450N/A{
1450N/A /* LINTED */
1450N/A uint32_t *data = (uint32_t *)frame;
1450N/A struct drm_device *dev = encoder->dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
1450N/A unsigned i, len = DIP_HEADER_SIZE + frame->len;
1450N/A u32 val = I915_READ(reg);
1450N/A
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A DRM_ERROR("Writing DIP with CTL reg disabled\n");
1450N/A
1450N/A val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
1450N/A val |= g4x_infoframe_index(frame);
1450N/A
1450N/A val &= ~g4x_infoframe_enable(frame);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A
1450N/A// mmiowb();
1450N/A for (i = 0; i < len; i += 4) {
1450N/A I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
1450N/A data++;
1450N/A }
1450N/A /* Write every possible data byte to force correct ECC calculation. */
1450N/A for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
1450N/A I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
1450N/A// mmiowb();
1450N/A
1450N/A val |= g4x_infoframe_enable(frame);
1450N/A val &= ~VIDEO_DIP_FREQ_MASK;
1450N/A val |= VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A}
1450N/A
1450N/Astatic void cpt_write_infoframe(struct drm_encoder *encoder,
1450N/A struct dip_infoframe *frame)
1450N/A{
1450N/A /* LINTED */
1450N/A uint32_t *data = (uint32_t *)frame;
1450N/A struct drm_device *dev = encoder->dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
1450N/A unsigned i, len = DIP_HEADER_SIZE + frame->len;
1450N/A u32 val = I915_READ(reg);
1450N/A
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A DRM_ERROR("Writing DIP with CTL reg disabled\n");
1450N/A
1450N/A val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
1450N/A val |= g4x_infoframe_index(frame);
1450N/A
1450N/A /* The DIP control register spec says that we need to update the AVI
1450N/A * infoframe without clearing its enable bit */
1450N/A if (frame->type != DIP_TYPE_AVI)
1450N/A val &= ~g4x_infoframe_enable(frame);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A
1450N/A// mmiowb();
1450N/A for (i = 0; i < len; i += 4) {
1450N/A I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
1450N/A data++;
1450N/A }
1450N/A /* Write every possible data byte to force correct ECC calculation. */
1450N/A for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
1450N/A I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
1450N/A// mmiowb();
1450N/A
1450N/A val |= g4x_infoframe_enable(frame);
1450N/A val &= ~VIDEO_DIP_FREQ_MASK;
1450N/A val |= VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A}
1450N/A
1450N/Astatic void vlv_write_infoframe(struct drm_encoder *encoder,
1450N/A struct dip_infoframe *frame)
1450N/A{
1450N/A /* LINTED */
1450N/A uint32_t *data = (uint32_t *)frame;
1450N/A struct drm_device *dev = encoder->dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
1450N/A unsigned i, len = DIP_HEADER_SIZE + frame->len;
1450N/A u32 val = I915_READ(reg);
1450N/A
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A DRM_ERROR("Writing DIP with CTL reg disabled\n");
1450N/A
1450N/A val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
1450N/A val |= g4x_infoframe_index(frame);
1450N/A
1450N/A val &= ~g4x_infoframe_enable(frame);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A
1450N/A// mmiowb();
1450N/A for (i = 0; i < len; i += 4) {
1450N/A I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
1450N/A data++;
1450N/A }
1450N/A /* Write every possible data byte to force correct ECC calculation. */
1450N/A for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
1450N/A I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
1450N/A// mmiowb();
1450N/A
1450N/A val |= g4x_infoframe_enable(frame);
1450N/A val &= ~VIDEO_DIP_FREQ_MASK;
1450N/A val |= VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A}
1450N/A
1450N/Astatic void hsw_write_infoframe(struct drm_encoder *encoder,
1450N/A struct dip_infoframe *frame)
1450N/A{
1450N/A /* LINTED */
1450N/A uint32_t *data = (uint32_t *)frame;
1450N/A struct drm_device *dev = encoder->dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
1450N/A u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->config.cpu_transcoder);
1450N/A unsigned int i, len = DIP_HEADER_SIZE + frame->len;
1450N/A u32 val = I915_READ(ctl_reg);
1450N/A
1450N/A if (data_reg == 0)
1450N/A return;
1450N/A
1450N/A val &= ~hsw_infoframe_enable(frame);
1450N/A I915_WRITE(ctl_reg, val);
1450N/A
1450N/A// mmiowb();
1450N/A for (i = 0; i < len; i += 4) {
1450N/A I915_WRITE(data_reg + i, *data);
1450N/A data++;
1450N/A }
1450N/A /* Write every possible data byte to force correct ECC calculation. */
1450N/A for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
1450N/A I915_WRITE(data_reg + i, 0);
1450N/A// mmiowb();
1450N/A
1450N/A val |= hsw_infoframe_enable(frame);
1450N/A I915_WRITE(ctl_reg, val);
1450N/A POSTING_READ(ctl_reg);
1450N/A}
1450N/A
1450N/Astatic void intel_set_infoframe(struct drm_encoder *encoder,
1450N/A struct dip_infoframe *frame)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1450N/A
1450N/A intel_dip_infoframe_csum(frame);
1450N/A intel_hdmi->write_infoframe(encoder, frame);
1450N/A}
1450N/A
1450N/Astatic void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
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
1450N/A if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
1450N/A avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
1450N/A
1450N/A if (intel_hdmi->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_set_infoframe(encoder, &avi_if);
1450N/A}
1450N/A
1450N/Astatic void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
1450N/A{
1450N/A struct dip_infoframe spd_if;
1450N/A
1450N/A memset(&spd_if, 0, sizeof(spd_if));
1450N/A spd_if.type = DIP_TYPE_SPD;
1450N/A spd_if.ver = DIP_VERSION_SPD;
1450N/A spd_if.len = DIP_LEN_SPD;
1450N/A strcpy((char *)spd_if.body.spd.vn, "Intel");
1450N/A strcpy((char *)spd_if.body.spd.pd, "Integrated gfx");
1450N/A spd_if.body.spd.sdi = DIP_SPD_PC;
1450N/A
1450N/A intel_set_infoframe(encoder, &spd_if);
1450N/A}
1450N/A
1450N/Astatic void g4x_set_infoframes(struct drm_encoder *encoder,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1450N/A struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1450N/A struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1450N/A u32 reg = VIDEO_DIP_CTL;
1450N/A u32 val = I915_READ(reg);
1450N/A u32 port;
1450N/A
1450N/A assert_hdmi_port_disabled(intel_hdmi);
1450N/A
1450N/A /* If the registers were not initialized yet, they might be zeroes,
1450N/A * which means we're selecting the AVI DIP and we're setting its
1450N/A * frequency to once. This seems to really confuse the HW and make
1450N/A * things stop working (the register spec says the AVI always needs to
1450N/A * be sent every VSync). So here we avoid writing to the register more
1450N/A * than we need and also explicitly select the AVI DIP and explicitly
1450N/A * set its frequency to every VSync. Avoiding to write it twice seems to
1450N/A * be enough to solve the problem, but being defensive shouldn't hurt us
1450N/A * either. */
1450N/A val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A if (!intel_hdmi->has_hdmi_sink) {
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A return;
1450N/A val &= ~VIDEO_DIP_ENABLE;
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A return;
1450N/A }
1450N/A
1450N/A switch (intel_dig_port->port) {
1450N/A case PORT_B:
1450N/A port = VIDEO_DIP_PORT_B;
1450N/A break;
1450N/A case PORT_C:
1450N/A port = VIDEO_DIP_PORT_C;
1450N/A break;
1450N/A default:
1450N/A BUG();
1450N/A return;
1450N/A }
1450N/A
1450N/A if (port != (val & VIDEO_DIP_PORT_MASK)) {
1450N/A if (val & VIDEO_DIP_ENABLE) {
1450N/A val &= ~VIDEO_DIP_ENABLE;
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A }
1450N/A val &= ~VIDEO_DIP_PORT_MASK;
1450N/A val |= port;
1450N/A }
1450N/A
1450N/A val |= VIDEO_DIP_ENABLE;
1450N/A val &= ~VIDEO_DIP_ENABLE_VENDOR;
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A
1450N/A intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
1450N/A intel_hdmi_set_spd_infoframe(encoder);
1450N/A}
1450N/A
1450N/Astatic void ibx_set_infoframes(struct drm_encoder *encoder,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1450N/A struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1450N/A u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
1450N/A u32 val = I915_READ(reg);
1450N/A u32 port;
1450N/A
1450N/A assert_hdmi_port_disabled(intel_hdmi);
1450N/A
1450N/A /* See the big comment in g4x_set_infoframes() */
1450N/A val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A if (!intel_hdmi->has_hdmi_sink) {
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A return;
1450N/A val &= ~VIDEO_DIP_ENABLE;
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A return;
1450N/A }
1450N/A
1450N/A switch (intel_dig_port->port) {
1450N/A case PORT_B:
1450N/A port = VIDEO_DIP_PORT_B;
1450N/A break;
1450N/A case PORT_C:
1450N/A port = VIDEO_DIP_PORT_C;
1450N/A break;
1450N/A case PORT_D:
1450N/A port = VIDEO_DIP_PORT_D;
1450N/A break;
1450N/A default:
1450N/A BUG();
1450N/A return;
1450N/A }
1450N/A
1450N/A if (port != (val & VIDEO_DIP_PORT_MASK)) {
1450N/A if (val & VIDEO_DIP_ENABLE) {
1450N/A val &= ~VIDEO_DIP_ENABLE;
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A }
1450N/A val &= ~VIDEO_DIP_PORT_MASK;
1450N/A val |= port;
1450N/A }
1450N/A
1450N/A val |= VIDEO_DIP_ENABLE;
1450N/A val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
1450N/A VIDEO_DIP_ENABLE_GCP);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A
1450N/A intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
1450N/A intel_hdmi_set_spd_infoframe(encoder);
1450N/A}
1450N/A
1450N/Astatic void cpt_set_infoframes(struct drm_encoder *encoder,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1450N/A u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
1450N/A u32 val = I915_READ(reg);
1450N/A
1450N/A assert_hdmi_port_disabled(intel_hdmi);
1450N/A
1450N/A /* See the big comment in g4x_set_infoframes() */
1450N/A val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A if (!intel_hdmi->has_hdmi_sink) {
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A return;
1450N/A val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A return;
1450N/A }
1450N/A
1450N/A /* Set both together, unset both together: see the spec. */
1450N/A val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
1450N/A val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
1450N/A VIDEO_DIP_ENABLE_GCP);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A
1450N/A intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
1450N/A intel_hdmi_set_spd_infoframe(encoder);
1450N/A}
1450N/A
1450N/Astatic void vlv_set_infoframes(struct drm_encoder *encoder,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1450N/A u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
1450N/A u32 val = I915_READ(reg);
1450N/A
1450N/A assert_hdmi_port_disabled(intel_hdmi);
1450N/A
1450N/A /* See the big comment in g4x_set_infoframes() */
1450N/A val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
1450N/A
1450N/A if (!intel_hdmi->has_hdmi_sink) {
1450N/A if (!(val & VIDEO_DIP_ENABLE))
1450N/A return;
1450N/A val &= ~VIDEO_DIP_ENABLE;
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A return;
1450N/A }
1450N/A
1450N/A val |= VIDEO_DIP_ENABLE;
1450N/A val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
1450N/A VIDEO_DIP_ENABLE_GCP);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A
1450N/A intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
1450N/A intel_hdmi_set_spd_infoframe(encoder);
1450N/A}
1450N/A
1450N/Astatic void hsw_set_infoframes(struct drm_encoder *encoder,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1450N/A u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
1450N/A u32 val = I915_READ(reg);
1450N/A
1450N/A assert_hdmi_port_disabled(intel_hdmi);
1450N/A
1450N/A if (!intel_hdmi->has_hdmi_sink) {
1450N/A I915_WRITE(reg, 0);
1450N/A POSTING_READ(reg);
1450N/A return;
1450N/A }
1450N/A
1450N/A val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
1450N/A VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
1450N/A
1450N/A I915_WRITE(reg, val);
1450N/A POSTING_READ(reg);
1450N/A
1450N/A intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
1450N/A intel_hdmi_set_spd_infoframe(encoder);
1450N/A}
1450N/A
1450N/Astatic void intel_hdmi_mode_set(struct drm_encoder *encoder,
1450N/A /* LINTED */
1450N/A struct drm_display_mode *mode,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A struct drm_device *dev = encoder->dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1450N/A u32 hdmi_val;
1450N/A
1450N/A hdmi_val = SDVO_ENCODING_HDMI;
1450N/A if (!HAS_PCH_SPLIT(dev))
1450N/A hdmi_val |= intel_hdmi->color_range;
1450N/A if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1450N/A hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
1450N/A if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1450N/A hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
1450N/A
1450N/A if (intel_crtc->config.pipe_bpp > 24)
1450N/A hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
1450N/A else
1450N/A hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
1450N/A
1450N/A /* Required on CPT */
1450N/A if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
1450N/A hdmi_val |= HDMI_MODE_SELECT_HDMI;
1450N/A
1450N/A if (intel_hdmi->has_audio) {
1450N/A DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
1450N/A pipe_name(intel_crtc->pipe));
1450N/A hdmi_val |= SDVO_AUDIO_ENABLE;
1450N/A hdmi_val |= HDMI_MODE_SELECT_HDMI;
1450N/A intel_write_eld(encoder, adjusted_mode);
1450N/A }
1450N/A
1450N/A if (HAS_PCH_CPT(dev))
1450N/A hdmi_val |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe);
1450N/A else
1450N/A hdmi_val |= SDVO_PIPE_SEL(intel_crtc->pipe);
1450N/A
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A intel_hdmi->set_infoframes(encoder, adjusted_mode);
1450N/A}
1450N/A
1450N/Astatic bool intel_hdmi_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_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1450N/A u32 tmp;
1450N/A
1450N/A tmp = I915_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A if (!(tmp & SDVO_ENABLE))
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_hdmi_get_config(struct intel_encoder *encoder,
1450N/A struct intel_crtc_config *pipe_config)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1450N/A struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1450N/A u32 tmp, flags = 0;
1450N/A
1450N/A tmp = I915_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
1450N/A flags |= DRM_MODE_FLAG_PHSYNC;
1450N/A else
1450N/A flags |= DRM_MODE_FLAG_NHSYNC;
1450N/A
1450N/A if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
1450N/A flags |= DRM_MODE_FLAG_PVSYNC;
1450N/A else
1450N/A flags |= DRM_MODE_FLAG_NVSYNC;
1450N/A
1450N/A pipe_config->adjusted_mode.flags |= flags;
1450N/A}
1450N/A
1450N/Astatic void intel_enable_hdmi(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_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1450N/A u32 temp;
1450N/A u32 enable_bits = SDVO_ENABLE;
1450N/A
1450N/A if (intel_hdmi->has_audio)
1450N/A enable_bits |= SDVO_AUDIO_ENABLE;
1450N/A
1450N/A temp = I915_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A /* HW workaround for IBX, we need to move the port to transcoder A
1450N/A * before disabling it, so restore the transcoder select bit here. */
1450N/A if (HAS_PCH_IBX(dev))
1450N/A enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
1450N/A
1450N/A /* HW workaround, need to toggle enable bit off and on for 12bpc, but
1450N/A * we do this anyway which shows more stable in testing.
1450N/A */
1450N/A if (HAS_PCH_SPLIT(dev)) {
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A }
1450N/A
1450N/A temp |= enable_bits;
1450N/A
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A /* HW workaround, need to write this twice for issue that may result
1450N/A * in first write getting masked.
1450N/A */
1450N/A if (HAS_PCH_SPLIT(dev)) {
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A }
1450N/A
1450N/A if (IS_VALLEYVIEW(dev)) {
1450N/A struct intel_digital_port *dport =
1450N/A enc_to_dig_port(&encoder->base);
1450N/A int channel = vlv_dport_to_channel(dport);
1450N/A
1450N/A vlv_wait_port_ready(dev_priv, channel);
1450N/A }
1450N/A}
1450N/A
1450N/Astatic void intel_disable_hdmi(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_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1450N/A u32 temp;
1450N/A u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
1450N/A
1450N/A temp = I915_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A /* HW workaround for IBX, we need to move the port to transcoder A
1450N/A * before disabling it. */
1450N/A if (HAS_PCH_IBX(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_hdmi->hdmi_reg, temp);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A /* Again we need to write this twice. */
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp);
1450N/A POSTING_READ(intel_hdmi->hdmi_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(dev, pipe);
1450N/A else
1450N/A msleep(50);
1450N/A }
1450N/A }
1450N/A
1450N/A /* HW workaround, need to toggle enable bit off and on for 12bpc, but
1450N/A * we do this anyway which shows more stable in testing.
1450N/A */
1450N/A if (HAS_PCH_SPLIT(dev)) {
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A }
1450N/A
1450N/A temp &= ~enable_bits;
1450N/A
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A
1450N/A /* HW workaround, need to write this twice for issue that may result
1450N/A * in first write getting masked.
1450N/A */
1450N/A if (HAS_PCH_SPLIT(dev)) {
1450N/A I915_WRITE(intel_hdmi->hdmi_reg, temp);
1450N/A POSTING_READ(intel_hdmi->hdmi_reg);
1450N/A }
1450N/A}
1450N/A
1450N/Astatic int hdmi_portclock_limit(struct intel_hdmi *hdmi)
1450N/A{
1450N/A struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1450N/A
1450N/A if (IS_G4X(dev))
1450N/A return 165000;
1450N/A else if (IS_HASWELL(dev))
1450N/A return 300000;
1450N/A else
1450N/A return 225000;
1450N/A}
1450N/A
1450N/Astatic int intel_hdmi_mode_valid(struct drm_connector *connector,
1450N/A struct drm_display_mode *mode)
1450N/A{
1450N/A if (mode->clock > hdmi_portclock_limit(intel_attached_hdmi(connector)))
1450N/A return MODE_CLOCK_HIGH;
1450N/A if (mode->clock < 20000)
1450N/A return MODE_CLOCK_LOW;
1450N/A
1450N/A if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1450N/A return MODE_NO_DBLESCAN;
1450N/A
1450N/A return MODE_OK;
1450N/A}
1450N/A
1450N/Abool intel_hdmi_compute_config(struct intel_encoder *encoder,
1450N/A struct intel_crtc_config *pipe_config)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1450N/A struct drm_device *dev = encoder->base.dev;
1450N/A struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
1450N/A int clock_12bpc = pipe_config->requested_mode.clock * 3 / 2;
1450N/A int portclock_limit = hdmi_portclock_limit(intel_hdmi);
1450N/A int desired_bpp;
1450N/A
1450N/A if (intel_hdmi->color_range_auto) {
1450N/A /* See CEA-861-E - 5.1 Default Encoding Parameters */
1450N/A if (intel_hdmi->has_hdmi_sink &&
1450N/A drm_match_cea_mode(adjusted_mode) > 1)
1450N/A intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
1450N/A else
1450N/A intel_hdmi->color_range = 0;
1450N/A }
1450N/A
1450N/A if (intel_hdmi->color_range)
1450N/A pipe_config->limited_color_range = true;
1450N/A
1450N/A if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
1450N/A pipe_config->has_pch_encoder = true;
1450N/A
1450N/A /*
1450N/A * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1450N/A * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
1450N/A * outputs. We also need to check that the higher clock still fits
1450N/A * within limits.
1450N/A */
1450N/A if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= portclock_limit
1450N/A && HAS_PCH_SPLIT(dev)) {
1450N/A DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1450N/A desired_bpp = 12*3;
1450N/A
1450N/A /* Need to adjust the port link by 1.5x for 12bpc. */
1450N/A pipe_config->port_clock = clock_12bpc;
1450N/A } else {
1450N/A DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1450N/A desired_bpp = 8*3;
1450N/A }
1450N/A
1450N/A if (!pipe_config->bw_constrained) {
1450N/A DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
1450N/A pipe_config->pipe_bpp = desired_bpp;
1450N/A }
1450N/A
1450N/A if (adjusted_mode->clock > portclock_limit) {
1450N/A DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
1450N/A return false;
1450N/A }
1450N/A
1450N/A return true;
1450N/A}
1450N/A
1450N/Astatic enum drm_connector_status
1450N/Aintel_hdmi_detect(struct drm_connector *connector, bool force)
1450N/A{
1450N/A struct drm_device *dev = connector->dev;
1450N/A struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1450N/A struct intel_digital_port *intel_dig_port =
1450N/A hdmi_to_dig_port(intel_hdmi);
1450N/A struct intel_encoder *intel_encoder = &intel_dig_port->base;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct edid *edid;
1450N/A enum drm_connector_status status = connector_status_disconnected;
1450N/A
1450N/A intel_hdmi->has_hdmi_sink = false;
1450N/A intel_hdmi->has_audio = false;
1450N/A intel_hdmi->rgb_quant_range_selectable = false;
1450N/A edid = drm_get_edid(connector,
1450N/A intel_gmbus_get_adapter(dev_priv,
1450N/A intel_hdmi->ddc_bus));
1450N/A
1450N/A if (edid) {
1450N/A if (edid->input & DRM_EDID_INPUT_DIGITAL) {
1450N/A status = connector_status_connected;
1450N/A if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1450N/A intel_hdmi->has_hdmi_sink =
1450N/A drm_detect_hdmi_monitor(edid);
1450N/A intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1450N/A intel_hdmi->rgb_quant_range_selectable =
1450N/A drm_rgb_quant_range_selectable(edid);
1450N/A }
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 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1450N/A intel_hdmi->has_audio =
1450N/A (intel_hdmi->force_audio == HDMI_AUDIO_ON);
1450N/A intel_encoder->type = INTEL_OUTPUT_HDMI;
1450N/A }
1450N/A
1450N/A return status;
1450N/A}
1450N/A
1450N/Astatic int intel_hdmi_get_modes(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1450N/A struct drm_i915_private *dev_priv = connector->dev->dev_private;
1450N/A
1450N/A /* We should parse the EDID data and find out if it's an HDMI sink so
1450N/A * we can send audio to it.
1450N/A */
1450N/A
1450N/A return intel_ddc_get_modes(connector,
1450N/A intel_gmbus_get_adapter(dev_priv,
1450N/A intel_hdmi->ddc_bus));
1450N/A}
1450N/A
1450N/Astatic bool
1450N/Aintel_hdmi_detect_audio(struct drm_connector *connector)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1450N/A struct drm_i915_private *dev_priv = connector->dev->dev_private;
1450N/A struct edid *edid;
1450N/A bool has_audio = false;
1450N/A
1450N/A edid = drm_get_edid(connector,
1450N/A intel_gmbus_get_adapter(dev_priv,
1450N/A intel_hdmi->ddc_bus));
1450N/A if (edid) {
1450N/A if (edid->input & DRM_EDID_INPUT_DIGITAL)
1450N/A has_audio = drm_detect_monitor_audio(edid);
1450N/A kfree(edid, EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1));
1450N/A }
1450N/A
1450N/A return has_audio;
1450N/A}
1450N/A
1450N/Astatic int
1450N/Aintel_hdmi_set_property(struct drm_connector *connector,
1450N/A struct drm_property *property,
1450N/A uint64_t val)
1450N/A{
1450N/A struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1450N/A struct intel_digital_port *intel_dig_port =
1450N/A hdmi_to_dig_port(intel_hdmi);
1450N/A struct drm_i915_private *dev_priv = connector->dev->dev_private;
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 enum hdmi_force_audio i = (enum hdmi_force_audio) val;
1450N/A bool has_audio;
1450N/A
1450N/A if (i == intel_hdmi->force_audio)
1450N/A return 0;
1450N/A
1450N/A intel_hdmi->force_audio = i;
1450N/A
1450N/A if (i == HDMI_AUDIO_AUTO)
1450N/A has_audio = intel_hdmi_detect_audio(connector);
1450N/A else
1450N/A has_audio = (i == HDMI_AUDIO_ON);
1450N/A
1450N/A if (i == HDMI_AUDIO_OFF_DVI)
1450N/A intel_hdmi->has_hdmi_sink = 0;
1450N/A
1450N/A intel_hdmi->has_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_hdmi->color_range_auto;
1450N/A uint32_t old_range = intel_hdmi->color_range;
1450N/A
1450N/A switch (val) {
1450N/A case INTEL_BROADCAST_RGB_AUTO:
1450N/A intel_hdmi->color_range_auto = true;
1450N/A break;
1450N/A case INTEL_BROADCAST_RGB_FULL:
1450N/A intel_hdmi->color_range_auto = false;
1450N/A intel_hdmi->color_range = 0;
1450N/A break;
1450N/A case INTEL_BROADCAST_RGB_LIMITED:
1450N/A intel_hdmi->color_range_auto = false;
1450N/A intel_hdmi->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_hdmi->color_range_auto &&
1450N/A old_range == intel_hdmi->color_range)
1450N/A return 0;
1450N/A goto done;
1450N/A }
1450N/A
1450N/A return -EINVAL;
1450N/A
1450N/Adone:
1450N/A if (intel_dig_port->base.base.crtc)
1450N/A intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
1450N/A
1450N/A return 0;
1450N/A}
1450N/A
1450N/Astatic void intel_hdmi_pre_enable(struct intel_encoder *encoder)
1450N/A{
1450N/A struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1450N/A struct drm_device *dev = encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A struct intel_crtc *intel_crtc =
1450N/A to_intel_crtc(encoder->base.crtc);
1450N/A int port = vlv_dport_to_channel(dport);
1450N/A int pipe = intel_crtc->pipe;
1450N/A u32 val;
1450N/A
1450N/A if (!IS_VALLEYVIEW(dev))
1450N/A return;
1450N/A
1450N/A /* Enable clock channels for this port */
1450N/A val = vlv_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
1450N/A val = 0;
1450N/A if (pipe)
1450N/A val |= (1<<21);
1450N/A else
1450N/A val &= ~(1<<21);
1450N/A val |= 0x001000c4;
1450N/A vlv_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);
1450N/A
1450N/A /* HDMI 1.0V-2dB */
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port),
1450N/A 0x2b245f5f);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
1450N/A 0x5578b83a);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port),
1450N/A 0x0c782040);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX3_SWING_CTL4(port),
1450N/A 0x2b247878);
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
1450N/A 0x00002000);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
1450N/A DPIO_TX_OCALINIT_EN);
1450N/A
1450N/A /* Program lane clock */
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port),
1450N/A 0x00760018);
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port),
1450N/A 0x00400888);
1450N/A}
1450N/A
1450N/Astatic void intel_hdmi_pre_pll_enable(struct intel_encoder *encoder)
1450N/A{
1450N/A struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1450N/A struct drm_device *dev = encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A int port = vlv_dport_to_channel(dport);
1450N/A
1450N/A if (!IS_VALLEYVIEW(dev))
1450N/A return;
1450N/A
1450N/A /* Program Tx lane resets to default */
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_TX(port),
1450N/A DPIO_PCS_TX_LANE2_RESET |
1450N/A DPIO_PCS_TX_LANE1_RESET);
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port),
1450N/A DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1450N/A DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1450N/A (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1450N/A DPIO_PCS_CLK_SOFT_RESET);
1450N/A
1450N/A /* Fix up inter-pair skew failure */
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);
1450N/A
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
1450N/A 0x00002000);
1450N/A vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
1450N/A DPIO_TX_OCALINIT_EN);
1450N/A}
1450N/A
1450N/Astatic void intel_hdmi_post_disable(struct intel_encoder *encoder)
1450N/A{
1450N/A struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1450N/A struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1450N/A int port = vlv_dport_to_channel(dport);
1450N/A
1450N/A /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1450N/A mutex_lock(&dev_priv->dpio_lock);
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_TX(port), 0x00000000);
1450N/A vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port), 0x00e00060);
1450N/A mutex_unlock(&dev_priv->dpio_lock);
1450N/A}
1450N/Astatic void intel_hdmi_destroy(struct drm_connector *connector)
1450N/A{
1450N/A drm_connector_cleanup(connector);
1450N/A kfree(connector, sizeof(struct intel_connector));
1450N/A}
1450N/A
1450N/Astatic const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
1450N/A .mode_set = intel_hdmi_mode_set,
1450N/A};
1450N/A
1450N/Astatic const struct drm_connector_funcs intel_hdmi_connector_funcs = {
1450N/A .dpms = intel_connector_dpms,
1450N/A .detect = intel_hdmi_detect,
1450N/A .fill_modes = drm_helper_probe_single_connector_modes,
1450N/A .set_property = intel_hdmi_set_property,
1450N/A .destroy = intel_hdmi_destroy,
1450N/A};
1450N/A
1450N/Astatic const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1450N/A .get_modes = intel_hdmi_get_modes,
1450N/A .mode_valid = intel_hdmi_mode_valid,
1450N/A .best_encoder = intel_best_encoder,
1450N/A};
1450N/A
1450N/Astatic const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
1450N/A .destroy = intel_encoder_destroy,
1450N/A};
1450N/A
1450N/Astatic void
1450N/Aintel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1450N/A{
1450N/A intel_attach_force_audio_property(connector);
1450N/A intel_attach_broadcast_rgb_property(connector);
1450N/A intel_hdmi->color_range_auto = true;
1450N/A}
1450N/A
1450N/Avoid intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1450N/A struct intel_connector *intel_connector)
1450N/A{
1450N/A struct drm_connector *connector = &intel_connector->base;
1450N/A struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1450N/A struct intel_encoder *intel_encoder = &intel_dig_port->base;
1450N/A struct drm_device *dev = intel_encoder->base.dev;
1450N/A struct drm_i915_private *dev_priv = dev->dev_private;
1450N/A enum port port = intel_dig_port->port;
1450N/A
1450N/A (void) drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
1450N/A DRM_MODE_CONNECTOR_HDMIA);
1450N/A (void) drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1450N/A
1450N/A connector->interlace_allowed = 1;
1450N/A connector->doublescan_allowed = 0;
1450N/A
1450N/A switch (port) {
1450N/A case PORT_B:
1450N/A intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
1450N/A intel_encoder->hpd_pin = HPD_PORT_B;
1450N/A break;
1450N/A case PORT_C:
1450N/A intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
1450N/A intel_encoder->hpd_pin = HPD_PORT_C;
1450N/A break;
1450N/A case PORT_D:
1450N/A intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
1450N/A intel_encoder->hpd_pin = HPD_PORT_D;
1450N/A break;
1450N/A case PORT_A:
1450N/A intel_encoder->hpd_pin = HPD_PORT_A;
1450N/A /* Internal port only for eDP. */
1450N/A default:
1450N/A BUG();
1450N/A }
1450N/A
1450N/A if (IS_VALLEYVIEW(dev)) {
1450N/A intel_hdmi->write_infoframe = vlv_write_infoframe;
1450N/A intel_hdmi->set_infoframes = vlv_set_infoframes;
1450N/A } else if (!HAS_PCH_SPLIT(dev)) {
1450N/A intel_hdmi->write_infoframe = g4x_write_infoframe;
1450N/A intel_hdmi->set_infoframes = g4x_set_infoframes;
1450N/A } else if (HAS_DDI(dev)) {
1450N/A intel_hdmi->write_infoframe = hsw_write_infoframe;
1450N/A intel_hdmi->set_infoframes = hsw_set_infoframes;
1450N/A } else if (HAS_PCH_IBX(dev)) {
1450N/A intel_hdmi->write_infoframe = ibx_write_infoframe;
1450N/A intel_hdmi->set_infoframes = ibx_set_infoframes;
1450N/A } else {
1450N/A intel_hdmi->write_infoframe = cpt_write_infoframe;
1450N/A intel_hdmi->set_infoframes = cpt_set_infoframes;
1450N/A }
1450N/A
1450N/A if (HAS_DDI(dev))
1450N/A intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1450N/A else
1450N/A intel_connector->get_hw_state = intel_connector_get_hw_state;
1450N/A
1450N/A intel_hdmi_add_properties(intel_hdmi, connector);
1450N/A
1450N/A intel_connector_attach_encoder(intel_connector, intel_encoder);
1450N/A// drm_sysfs_connector_add(connector);
1450N/A
1450N/A /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1450N/A * 0xd. Failure to do so will result in spurious interrupts being
1450N/A * generated on the port when a cable is not attached.
1450N/A */
1450N/A if (IS_G4X(dev) && !IS_GM45(dev)) {
1450N/A u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1450N/A I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1450N/A }
1450N/A}
1450N/A
1450N/Avoid intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
1450N/A{
1450N/A struct intel_digital_port *intel_dig_port;
1450N/A struct intel_encoder *intel_encoder;
1450N/A struct intel_connector *intel_connector;
1450N/A
1450N/A intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
1450N/A if (!intel_dig_port)
1450N/A return;
1450N/A
1450N/A intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1450N/A if (!intel_connector) {
1450N/A kfree(intel_dig_port, sizeof(struct intel_digital_port));
1450N/A return;
1450N/A }
1450N/A
1450N/A intel_encoder = &intel_dig_port->base;
1450N/A
1450N/A drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1450N/A DRM_MODE_ENCODER_TMDS);
1450N/A
1450N/A drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
1450N/A
1450N/A intel_encoder->compute_config = intel_hdmi_compute_config;
1450N/A intel_encoder->enable = intel_enable_hdmi;
1450N/A intel_encoder->disable = intel_disable_hdmi;
1450N/A intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
1450N/A intel_encoder->get_config = intel_hdmi_get_config;
1450N/A if (IS_VALLEYVIEW(dev)) {
1450N/A intel_encoder->pre_enable = intel_hdmi_pre_enable;
1450N/A intel_encoder->pre_pll_enable = intel_hdmi_pre_pll_enable;
1450N/A intel_encoder->post_disable = intel_hdmi_post_disable;
1450N/A }
1450N/A
1450N/A intel_encoder->type = INTEL_OUTPUT_HDMI;
1450N/A intel_encoder->type_size = sizeof(struct intel_digital_port);
1450N/A intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1450N/A intel_encoder->cloneable = false;
1450N/A
1450N/A intel_dig_port->port = port;
1450N/A intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
1450N/A intel_dig_port->dp.output_reg = 0;
1450N/A
1450N/A intel_hdmi_init_connector(intel_dig_port, intel_connector);
1450N/A}