1494N/A/*
1494N/A * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
1494N/A */
1494N/A
1494N/A/*
1494N/A * Copyright (c) 2006, 2013, Intel Corporation
1494N/A *
1494N/A * Permission is hereby granted, free of charge, to any person obtaining a
1494N/A * copy of this software and associated documentation files (the "Software"),
1494N/A * to deal in the Software without restriction, including without limitation
1494N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1494N/A * and/or sell copies of the Software, and to permit persons to whom the
1494N/A * Software is furnished to do so, subject to the following conditions:
1494N/A *
1494N/A * The above copyright notice and this permission notice (including the next
1494N/A * paragraph) shall be included in all copies or substantial portions of the
1494N/A * Software.
1494N/A *
1494N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1494N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1494N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1494N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1494N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1494N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1494N/A * SOFTWARE.
1494N/A *
1494N/A * Authors:
1494N/A * Eric Anholt <eric@anholt.net>
1494N/A *
1494N/A */
1494N/A#include "drmP.h"
1494N/A#include "drm.h"
1494N/A#include "drm_dp_helper.h"
1494N/A#include "i915_drm.h"
1494N/A#include "i915_drv.h"
1494N/A#include "intel_bios.h"
1494N/A
1494N/A#define SLAVE_ADDR1 0x70
1494N/A#define SLAVE_ADDR2 0x72
1494N/A
1494N/Astatic int panel_type;
1494N/A
1494N/Astatic void *
1494N/Afind_section(struct bdb_header *bdb, int section_id)
1494N/A{
1494N/A u8 *base = (u8 *)bdb;
1494N/A int index = 0;
1494N/A u16 total, current_size;
1494N/A u8 current_id;
1494N/A
1494N/A /* skip to first section */
1494N/A index += bdb->header_size;
1494N/A total = bdb->bdb_size;
1494N/A
1494N/A /* walk the sections looking for section_id */
1494N/A while (index < total) {
1494N/A current_id = *(base + index);
1494N/A index++;
1494N/A current_size = *((u16 *)(uintptr_t)(base + index));
1494N/A index += 2;
1494N/A if (current_id == section_id)
1494N/A return base + index;
1494N/A index += current_size;
1494N/A }
1494N/A
1494N/A return NULL;
1494N/A}
1494N/A
1494N/Astatic u16
1494N/Aget_blocksize(void *p)
1494N/A{
1494N/A u16 *block_ptr, block_size;
1494N/A
1494N/A block_ptr = (u16 *)(uintptr_t)((char *)p - 2);
1494N/A block_size = *block_ptr;
1494N/A return block_size;
1494N/A}
1494N/A
1494N/Astatic void
1494N/Afill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
1494N/A const struct lvds_dvo_timing *dvo_timing)
1494N/A{
1494N/A panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
1494N/A dvo_timing->hactive_lo;
1494N/A panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
1494N/A ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
1494N/A panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
1494N/A dvo_timing->hsync_pulse_width;
1494N/A panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
1494N/A ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
1494N/A
1494N/A panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
1494N/A dvo_timing->vactive_lo;
1494N/A panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
1494N/A dvo_timing->vsync_off;
1494N/A panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
1494N/A dvo_timing->vsync_pulse_width;
1494N/A panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
1494N/A ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
1494N/A panel_fixed_mode->clock = dvo_timing->clock * 10;
1494N/A panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
1494N/A
1494N/A if (dvo_timing->hsync_positive)
1494N/A panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
1494N/A else
1494N/A panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
1494N/A
1494N/A if (dvo_timing->vsync_positive)
1494N/A panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
1494N/A else
1494N/A panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
1494N/A
1494N/A /* Some VBTs have bogus h/vtotal values */
1494N/A if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
1494N/A panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
1494N/A if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
1494N/A panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
1494N/A
1494N/A drm_mode_set_name(panel_fixed_mode);
1494N/A}
1494N/A
1494N/Astatic bool
1494N/Alvds_dvo_timing_equal_size(const struct lvds_dvo_timing *a,
1494N/A const struct lvds_dvo_timing *b)
1494N/A{
1494N/A if (a->hactive_hi != b->hactive_hi ||
1494N/A a->hactive_lo != b->hactive_lo)
1494N/A return false;
1494N/A
1494N/A if (a->hsync_off_hi != b->hsync_off_hi ||
1494N/A a->hsync_off_lo != b->hsync_off_lo)
1494N/A return false;
1494N/A
1494N/A if (a->hsync_pulse_width != b->hsync_pulse_width)
1494N/A return false;
1494N/A
1494N/A if (a->hblank_hi != b->hblank_hi ||
1494N/A a->hblank_lo != b->hblank_lo)
1494N/A return false;
1494N/A
1494N/A if (a->vactive_hi != b->vactive_hi ||
1494N/A a->vactive_lo != b->vactive_lo)
1494N/A return false;
1494N/A
1494N/A if (a->vsync_off != b->vsync_off)
1494N/A return false;
1494N/A
1494N/A if (a->vsync_pulse_width != b->vsync_pulse_width)
1494N/A return false;
1494N/A
1494N/A if (a->vblank_hi != b->vblank_hi ||
1494N/A a->vblank_lo != b->vblank_lo)
1494N/A return false;
1494N/A
1494N/A return true;
1494N/A}
1494N/A
1494N/Astatic const struct lvds_dvo_timing *
1494N/Aget_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
1494N/A const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
1494N/A int index)
1494N/A{
1494N/A /*
1494N/A * the size of fp_timing varies on the different platform.
1494N/A * So calculate the DVO timing relative offset in LVDS data
1494N/A * entry to get the DVO timing entry
1494N/A */
1494N/A
1494N/A int lfp_data_size =
1494N/A lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
1494N/A lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
1494N/A int dvo_timing_offset =
1494N/A lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
1494N/A lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
1494N/A char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
1494N/A
1494N/A return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
1494N/A}
1494N/A
1494N/A/* get lvds_fp_timing entry
1494N/A * this function may return NULL if the corresponding entry is invalid
1494N/A */
1494N/Astatic const struct lvds_fp_timing *
1494N/Aget_lvds_fp_timing(const struct bdb_header *bdb,
1494N/A const struct bdb_lvds_lfp_data *data,
1494N/A const struct bdb_lvds_lfp_data_ptrs *ptrs,
1494N/A int index)
1494N/A{
1494N/A /* LINTED */
1494N/A size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
1494N/A /* LINTED */
1494N/A u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
1494N/A size_t ofs;
1494N/A
1494N/A if (index >= ARRAY_SIZE(ptrs->ptr))
1494N/A return NULL;
1494N/A ofs = ptrs->ptr[index].fp_timing_offset;
1494N/A if (ofs < data_ofs ||
1494N/A ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
1494N/A return NULL;
1494N/A return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
1494N/A}
1494N/A
1494N/A/* Try to find integrated panel data */
1494N/Astatic void
1494N/Aparse_lfp_panel_data(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A const struct bdb_lvds_options *lvds_options;
1494N/A const struct bdb_lvds_lfp_data *lvds_lfp_data;
1494N/A const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
1494N/A const struct lvds_dvo_timing *panel_dvo_timing;
1494N/A const struct lvds_fp_timing *fp_timing;
1494N/A struct drm_display_mode *panel_fixed_mode;
1494N/A int i, downclock;
1494N/A
1494N/A lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
1494N/A if (!lvds_options)
1494N/A return;
1494N/A
1494N/A dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
1494N/A if (lvds_options->panel_type == 0xff)
1494N/A return;
1494N/A
1494N/A panel_type = lvds_options->panel_type;
1494N/A
1494N/A lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
1494N/A if (!lvds_lfp_data)
1494N/A return;
1494N/A
1494N/A lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
1494N/A if (!lvds_lfp_data_ptrs)
1494N/A return;
1494N/A
1494N/A dev_priv->vbt.lvds_vbt = 1;
1494N/A
1494N/A panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
1494N/A lvds_lfp_data_ptrs,
1494N/A lvds_options->panel_type);
1494N/A
1494N/A panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
1494N/A if (!panel_fixed_mode)
1494N/A return;
1494N/A
1494N/A fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
1494N/A
1494N/A dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
1494N/A
1494N/A DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
1494N/A drm_mode_debug_printmodeline(panel_fixed_mode);
1494N/A
1494N/A /*
1494N/A * enumerate the LVDS panel timing info entry in VBT to check whether
1494N/A * the LVDS downclock is found.
1494N/A */
1494N/A downclock = panel_dvo_timing->clock;
1494N/A for (i = 0; i < 16; i++) {
1494N/A const struct lvds_dvo_timing *dvo_timing;
1494N/A
1494N/A dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
1494N/A lvds_lfp_data_ptrs,
1494N/A i);
1494N/A if (lvds_dvo_timing_equal_size(dvo_timing, panel_dvo_timing) &&
1494N/A dvo_timing->clock < downclock)
1494N/A downclock = dvo_timing->clock;
1494N/A }
1494N/A
1494N/A if (downclock < panel_dvo_timing->clock && i915_lvds_downclock) {
1494N/A dev_priv->lvds_downclock_avail = 1;
1494N/A dev_priv->lvds_downclock = downclock * 10;
1494N/A DRM_DEBUG_KMS("LVDS downclock is found in VBT. "
1494N/A "Normal Clock %dKHz, downclock %dKHz\n",
1494N/A panel_fixed_mode->clock, 10*downclock);
1494N/A }
1494N/A
1494N/A fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
1494N/A lvds_lfp_data_ptrs,
1494N/A lvds_options->panel_type);
1494N/A if (fp_timing) {
1494N/A /* check the resolution, just to be sure */
1494N/A if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
1494N/A fp_timing->y_res == panel_fixed_mode->vdisplay) {
1494N/A dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
1494N/A DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
1494N/A dev_priv->vbt.bios_lvds_val);
1494N/A }
1494N/A }
1494N/A}
1494N/A
1494N/A/* Try to find sdvo panel data */
1494N/Astatic void
1494N/Aparse_sdvo_panel_data(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A struct lvds_dvo_timing *dvo_timing;
1494N/A struct drm_display_mode *panel_fixed_mode;
1494N/A int index;
1494N/A
1494N/A index = i915_vbt_sdvo_panel_type;
1494N/A if (index == -2) {
1494N/A DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
1494N/A return;
1494N/A }
1494N/A
1494N/A if (index == -1) {
1494N/A struct bdb_sdvo_lvds_options *sdvo_lvds_options;
1494N/A
1494N/A sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
1494N/A if (!sdvo_lvds_options)
1494N/A return;
1494N/A
1494N/A index = sdvo_lvds_options->panel_type;
1494N/A }
1494N/A
1494N/A dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
1494N/A if (!dvo_timing)
1494N/A return;
1494N/A
1494N/A panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
1494N/A if (!panel_fixed_mode)
1494N/A return;
1494N/A
1494N/A fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
1494N/A
1494N/A dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
1494N/A
1494N/A DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
1494N/A drm_mode_debug_printmodeline(panel_fixed_mode);
1494N/A}
1494N/A
1494N/Astatic int intel_bios_ssc_frequency(struct drm_device *dev,
1494N/A bool alternate)
1494N/A{
1494N/A switch (INTEL_INFO(dev)->gen) {
1494N/A case 2:
1494N/A return alternate ? 66 : 48;
1494N/A case 3:
1494N/A case 4:
1494N/A return alternate ? 100 : 96;
1494N/A default:
1494N/A return alternate ? 100 : 120;
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aparse_general_features(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A struct drm_device *dev = dev_priv->dev;
1494N/A struct bdb_general_features *general;
1494N/A
1494N/A general = find_section(bdb, BDB_GENERAL_FEATURES);
1494N/A if (general) {
1494N/A dev_priv->vbt.int_tv_support = general->int_tv_support;
1494N/A dev_priv->vbt.int_crt_support = general->int_crt_support;
1494N/A dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
1494N/A dev_priv->vbt.lvds_ssc_freq =
1494N/A intel_bios_ssc_frequency(dev, general->ssc_freq);
1494N/A dev_priv->vbt.display_clock_mode = general->display_clock_mode;
1494N/A dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
1494N/A DRM_DEBUG_KMS("BDB_GENERAL_FEATURES int_tv_support %d int_crt_support"
1494N/A " %d lvds_use_ssc %d lvds_ssc_freq %d display_clock_mode"
1494N/A " %d fdi_rx_polarity_inverted %d\n",
1494N/A dev_priv->vbt.int_tv_support,
1494N/A dev_priv->vbt.int_crt_support,
1494N/A dev_priv->vbt.lvds_use_ssc,
1494N/A dev_priv->vbt.lvds_ssc_freq,
1494N/A dev_priv->vbt.display_clock_mode,
1494N/A dev_priv->vbt.fdi_rx_polarity_inverted);
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aparse_general_definitions(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A struct bdb_general_definitions *general;
1494N/A
1494N/A general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1494N/A if (general) {
1494N/A u16 block_size = get_blocksize(general);
1494N/A if (block_size >= sizeof(*general)) {
1494N/A int bus_pin = general->crt_ddc_gmbus_pin;
1494N/A DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
1494N/A if (intel_gmbus_is_port_valid(bus_pin))
1494N/A dev_priv->vbt.crt_ddc_pin = bus_pin;
1494N/A } else {
1494N/A DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
1494N/A block_size);
1494N/A }
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aparse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A struct sdvo_device_mapping *p_mapping;
1494N/A struct bdb_general_definitions *p_defs;
1494N/A struct child_device_config *p_child;
1494N/A int i, child_device_num, count;
1494N/A u16 block_size;
1494N/A
1494N/A p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1494N/A if (!p_defs) {
1494N/A DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
1494N/A return;
1494N/A }
1494N/A /* judge whether the size of child device meets the requirements.
1494N/A * If the child device size obtained from general definition block
1494N/A * is different with sizeof(struct child_device_config), skip the
1494N/A * parsing of sdvo device info
1494N/A */
1494N/A if (p_defs->child_dev_size != sizeof(*p_child)) {
1494N/A /* different child dev size . Ignore it */
1494N/A DRM_DEBUG_KMS("different child size is found. Invalid.\n");
1494N/A return;
1494N/A }
1494N/A /* get the block size of general definitions */
1494N/A block_size = get_blocksize(p_defs);
1494N/A /* get the number of child device */
1494N/A child_device_num = (block_size - sizeof(*p_defs)) /
1494N/A sizeof(*p_child);
1494N/A count = 0;
1494N/A for (i = 0; i < child_device_num; i++) {
1494N/A p_child = &(((struct __bdb_general_definitions *)p_defs)->devices[i]);
1494N/A if (!p_child->device_type) {
1494N/A /* skip the device block if device type is invalid */
1494N/A continue;
1494N/A }
1494N/A if (p_child->slave_addr != SLAVE_ADDR1 &&
1494N/A p_child->slave_addr != SLAVE_ADDR2) {
1494N/A /*
1494N/A * If the slave address is neither 0x70 nor 0x72,
1494N/A * it is not a SDVO device. Skip it.
1494N/A */
1494N/A continue;
1494N/A }
1494N/A if (p_child->dvo_port != DEVICE_PORT_DVOB &&
1494N/A p_child->dvo_port != DEVICE_PORT_DVOC) {
1494N/A /* skip the incorrect SDVO port */
1494N/A DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
1494N/A continue;
1494N/A }
1494N/A DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
1494N/A " %s port\n",
1494N/A p_child->slave_addr,
1494N/A (p_child->dvo_port == DEVICE_PORT_DVOB) ?
1494N/A "SDVOB" : "SDVOC");
1494N/A p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
1494N/A if (!p_mapping->initialized) {
1494N/A p_mapping->dvo_port = p_child->dvo_port;
1494N/A p_mapping->slave_addr = p_child->slave_addr;
1494N/A p_mapping->dvo_wiring = p_child->dvo_wiring;
1494N/A p_mapping->ddc_pin = p_child->ddc_pin;
1494N/A p_mapping->i2c_pin = p_child->i2c_pin;
1494N/A p_mapping->initialized = 1;
1494N/A DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
1494N/A p_mapping->dvo_port,
1494N/A p_mapping->slave_addr,
1494N/A p_mapping->dvo_wiring,
1494N/A p_mapping->ddc_pin,
1494N/A p_mapping->i2c_pin);
1494N/A } else {
1494N/A DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
1494N/A "two SDVO device.\n");
1494N/A }
1494N/A if (p_child->slave2_addr) {
1494N/A /* Maybe this is a SDVO device with multiple inputs */
1494N/A /* And the mapping info is not added */
1494N/A DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
1494N/A " is a SDVO device with multiple inputs.\n");
1494N/A }
1494N/A count++;
1494N/A }
1494N/A
1494N/A if (!count) {
1494N/A /* No SDVO device info is found */
1494N/A DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
1494N/A }
1494N/A return;
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aparse_driver_features(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A struct drm_device *dev = dev_priv->dev;
1494N/A struct bdb_driver_features *driver;
1494N/A
1494N/A driver = find_section(bdb, BDB_DRIVER_FEATURES);
1494N/A if (!driver)
1494N/A return;
1494N/A
1494N/A if (SUPPORTS_EDP(dev) &&
1494N/A driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
1494N/A dev_priv->vbt.edp_support = 1;
1494N/A
1494N/A if (driver->dual_frequency)
1494N/A dev_priv->render_reclock_avail = true;
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aparse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
1494N/A{
1494N/A struct bdb_edp *edp;
1494N/A struct edp_power_seq *edp_pps;
1494N/A struct edp_link_params *edp_link_params;
1494N/A
1494N/A edp = find_section(bdb, BDB_EDP);
1494N/A if (!edp) {
1494N/A if (SUPPORTS_EDP(dev_priv->dev) && dev_priv->vbt.edp_support)
1494N/A DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
1494N/A return;
1494N/A }
1494N/A
1494N/A switch ((edp->color_depth >> (panel_type * 2)) & 3) {
1494N/A case EDP_18BPP:
1494N/A dev_priv->vbt.edp_bpp = 18;
1494N/A break;
1494N/A case EDP_24BPP:
1494N/A dev_priv->vbt.edp_bpp = 24;
1494N/A break;
1494N/A case EDP_30BPP:
1494N/A dev_priv->vbt.edp_bpp = 30;
1494N/A break;
1494N/A }
1494N/A
1494N/A /* Get the eDP sequencing and link info */
1494N/A edp_pps = &edp->power_seqs[panel_type];
1494N/A edp_link_params = &edp->link_params[panel_type];
1494N/A
1494N/A dev_priv->vbt.edp_pps = *edp_pps;
1494N/A
1494N/A dev_priv->vbt.edp_rate = edp_link_params->rate ? DP_LINK_BW_2_7 :
1494N/A DP_LINK_BW_1_62;
1494N/A switch (edp_link_params->lanes) {
1494N/A case 0:
1494N/A dev_priv->vbt.edp_lanes = 1;
1494N/A break;
1494N/A case 1:
1494N/A dev_priv->vbt.edp_lanes = 2;
1494N/A break;
1494N/A case 3:
1494N/A default:
1494N/A dev_priv->vbt.edp_lanes = 4;
1494N/A break;
1494N/A }
1494N/A switch (edp_link_params->preemphasis) {
1494N/A case 0:
1494N/A dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
1494N/A break;
1494N/A case 1:
1494N/A dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
1494N/A break;
1494N/A case 2:
1494N/A dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
1494N/A break;
1494N/A case 3:
1494N/A dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
1494N/A break;
1494N/A }
1494N/A switch (edp_link_params->vswing) {
1494N/A case 0:
1494N/A dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_400;
1494N/A break;
1494N/A case 1:
1494N/A dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_600;
1494N/A break;
1494N/A case 2:
1494N/A dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_800;
1494N/A break;
1494N/A case 3:
1494N/A dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_1200;
1494N/A break;
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aparse_device_mapping(struct drm_i915_private *dev_priv,
1494N/A struct bdb_header *bdb)
1494N/A{
1494N/A struct bdb_general_definitions *p_defs;
1494N/A struct child_device_config *p_child, *child_dev_ptr;
1494N/A int i, child_device_num, count;
1494N/A u16 block_size;
1494N/A
1494N/A p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1494N/A if (!p_defs) {
1494N/A DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
1494N/A return;
1494N/A }
1494N/A /* judge whether the size of child device meets the requirements.
1494N/A * If the child device size obtained from general definition block
1494N/A * is different with sizeof(struct child_device_config), skip the
1494N/A * parsing of sdvo device info
1494N/A */
1494N/A if (p_defs->child_dev_size != sizeof(*p_child)) {
1494N/A /* different child dev size . Ignore it */
1494N/A DRM_DEBUG_KMS("different child size is found. Invalid.\n");
1494N/A return;
1494N/A }
1494N/A /* get the block size of general definitions */
1494N/A block_size = get_blocksize(p_defs);
1494N/A /* get the number of child device */
1494N/A child_device_num = (block_size - sizeof(*p_defs)) /
1494N/A sizeof(*p_child);
1494N/A count = 0;
1494N/A /* get the number of child device that is present */
1494N/A for (i = 0; i < child_device_num; i++) {
1494N/A p_child = &(((struct __bdb_general_definitions *)p_defs)->devices[i]);
1494N/A if (!p_child->device_type) {
1494N/A /* skip the device block if device type is invalid */
1494N/A continue;
1494N/A }
1494N/A count++;
1494N/A }
1494N/A if (!count) {
1494N/A DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
1494N/A return;
1494N/A }
1494N/A dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
1494N/A if (!dev_priv->vbt.child_dev) {
1494N/A DRM_DEBUG_KMS("No memory space for child device\n");
1494N/A return;
1494N/A }
1494N/A
1494N/A dev_priv->vbt.child_dev_num = count;
1494N/A count = 0;
1494N/A for (i = 0; i < child_device_num; i++) {
1494N/A p_child = &(((struct __bdb_general_definitions *)p_defs)->devices[i]);
1494N/A if (!p_child->device_type) {
1494N/A /* skip the device block if device type is invalid */
1494N/A continue;
1494N/A }
1494N/A child_dev_ptr = dev_priv->vbt.child_dev + count;
1494N/A count++;
1494N/A (void) memcpy((void *)child_dev_ptr, (void *)p_child,
1494N/A sizeof(*p_child));
1494N/A }
1494N/A return;
1494N/A}
1494N/A
1494N/Astatic void
1494N/Ainit_vbt_defaults(struct drm_i915_private *dev_priv)
1494N/A{
1494N/A struct drm_device *dev = dev_priv->dev;
1494N/A
1494N/A dev_priv->vbt.crt_ddc_pin = GMBUS_PORT_VGADDC;
1494N/A
1494N/A /* LFP panel data */
1494N/A dev_priv->vbt.lvds_dither = 1;
1494N/A dev_priv->vbt.lvds_vbt = 0;
1494N/A
1494N/A /* SDVO panel data */
1494N/A dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
1494N/A
1494N/A /* general features */
1494N/A dev_priv->vbt.int_tv_support = 1;
1494N/A dev_priv->vbt.int_crt_support = 1;
1494N/A
1494N/A /* Default to using SSC */
1494N/A dev_priv->vbt.lvds_use_ssc = 1;
1494N/A dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev, 1);
1494N/A DRM_DEBUG_KMS("Set default to SSC at %dMHz\n", dev_priv->vbt.lvds_ssc_freq);
1494N/A}
1494N/A
1494N/A/**
1494N/A * intel_init_bios - initialize VBIOS settings & find VBT
1494N/A * @dev: DRM device
1494N/A *
1494N/A * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
1494N/A * to appropriate values.
1494N/A *
1494N/A * Returns 0 on success, nonzero on failure.
1494N/A */
1494N/Aint
1494N/Aintel_parse_bios(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct pci_dev *pdev = dev->pdev;
1494N/A struct bdb_header *bdb = NULL;
1494N/A u8 __iomem *bios = NULL;
1494N/A
1494N/A if (HAS_PCH_NOP(dev))
1494N/A return -ENODEV;
1494N/A
1494N/A init_vbt_defaults(dev_priv);
1494N/A
1494N/A /* XXX Should this validation be moved to intel_opregion.c? */
1494N/A if (dev_priv->opregion.vbt) {
1494N/A struct vbt_header *vbt = dev_priv->opregion.vbt;
1494N/A if (memcmp(vbt->signature, "$VBT", 4) == 0) {
1494N/A DRM_DEBUG_KMS("Using VBT from OpRegion: %20s\n",
1494N/A vbt->signature);
1494N/A bdb = (struct bdb_header *)(uintptr_t)((char *)vbt + vbt->bdb_offset);
1494N/A } else
1494N/A dev_priv->opregion.vbt = NULL;
1494N/A }
1494N/A
1494N/A if (bdb == NULL) {
1494N/A struct vbt_header *vbt = NULL;
1494N/A size_t size;
1494N/A int i;
1494N/A
1494N/A bios = pci_map_rom(pdev, &size);
1494N/A if (!bios)
1494N/A return -1;
1494N/A
1494N/A /* Scour memory looking for the VBT signature */
1494N/A for (i = 0; i + 4 < size; i++) {
1494N/A if (!memcmp(bios + i, "$VBT", 4)) {
1494N/A vbt = (struct vbt_header *)(bios + i);
1494N/A break;
1494N/A }
1494N/A }
1494N/A
1494N/A if (!vbt) {
1494N/A DRM_ERROR("VBT signature missing\n");
1494N/A pci_unmap_rom(pdev, bios);
1494N/A return -1;
1494N/A }
1494N/A
1494N/A bdb = (struct bdb_header *)(uintptr_t)(bios + i + vbt->bdb_offset);
1494N/A }
1494N/A
1494N/A /* Grab useful general definitions */
1494N/A parse_general_features(dev_priv, bdb);
1494N/A parse_general_definitions(dev_priv, bdb);
1494N/A parse_lfp_panel_data(dev_priv, bdb);
1494N/A parse_sdvo_panel_data(dev_priv, bdb);
1494N/A parse_sdvo_device_mapping(dev_priv, bdb);
1494N/A parse_device_mapping(dev_priv, bdb);
1494N/A parse_driver_features(dev_priv, bdb);
1494N/A parse_edp(dev_priv, bdb);
1494N/A
1494N/A if (bios)
1494N/A pci_unmap_rom(pdev, bios);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/A/* Ensure that vital registers have been initialised, even if the BIOS
1494N/A * is absent or just failing to do its job.
1494N/A */
1494N/Avoid intel_setup_bios(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A /* Set the Panel Power On/Off timings if uninitialized. */
1494N/A if (!HAS_PCH_SPLIT(dev) &&
1494N/A I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
1494N/A /* Set T2 to 40ms and T5 to 200ms */
1494N/A I915_WRITE(PP_ON_DELAYS, 0x019007d0);
1494N/A
1494N/A /* Set T3 to 35ms and Tx to 200ms */
1494N/A I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
1494N/A }
1494N/A}