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