Path: blob/master/drivers/gpu/drm/i915/intel_lvds.c
15112 views
/*1* Copyright © 2006-2007 Intel Corporation2* Copyright (c) 2006 Dave Airlie <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Authors:24* Eric Anholt <[email protected]>25* Dave Airlie <[email protected]>26* Jesse Barnes <[email protected]>27*/2829#include <acpi/button.h>30#include <linux/dmi.h>31#include <linux/i2c.h>32#include <linux/slab.h>33#include "drmP.h"34#include "drm.h"35#include "drm_crtc.h"36#include "drm_edid.h"37#include "intel_drv.h"38#include "i915_drm.h"39#include "i915_drv.h"40#include <linux/acpi.h>4142/* Private structure for the integrated LVDS support */43struct intel_lvds {44struct intel_encoder base;4546struct edid *edid;4748int fitting_mode;49u32 pfit_control;50u32 pfit_pgm_ratios;51bool pfit_dirty;5253struct drm_display_mode *fixed_mode;54};5556static struct intel_lvds *to_intel_lvds(struct drm_encoder *encoder)57{58return container_of(encoder, struct intel_lvds, base.base);59}6061static struct intel_lvds *intel_attached_lvds(struct drm_connector *connector)62{63return container_of(intel_attached_encoder(connector),64struct intel_lvds, base);65}6667/**68* Sets the power state for the panel.69*/70static void intel_lvds_enable(struct intel_lvds *intel_lvds)71{72struct drm_device *dev = intel_lvds->base.base.dev;73struct drm_i915_private *dev_priv = dev->dev_private;74u32 ctl_reg, lvds_reg;7576if (HAS_PCH_SPLIT(dev)) {77ctl_reg = PCH_PP_CONTROL;78lvds_reg = PCH_LVDS;79} else {80ctl_reg = PP_CONTROL;81lvds_reg = LVDS;82}8384I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);8586if (intel_lvds->pfit_dirty) {87/*88* Enable automatic panel scaling so that non-native modes89* fill the screen. The panel fitter should only be90* adjusted whilst the pipe is disabled, according to91* register description and PRM.92*/93DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",94intel_lvds->pfit_control,95intel_lvds->pfit_pgm_ratios);96if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000)) {97DRM_ERROR("timed out waiting for panel to power off\n");98} else {99I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);100I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);101intel_lvds->pfit_dirty = false;102}103}104105I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);106POSTING_READ(lvds_reg);107108intel_panel_enable_backlight(dev);109}110111static void intel_lvds_disable(struct intel_lvds *intel_lvds)112{113struct drm_device *dev = intel_lvds->base.base.dev;114struct drm_i915_private *dev_priv = dev->dev_private;115u32 ctl_reg, lvds_reg;116117if (HAS_PCH_SPLIT(dev)) {118ctl_reg = PCH_PP_CONTROL;119lvds_reg = PCH_LVDS;120} else {121ctl_reg = PP_CONTROL;122lvds_reg = LVDS;123}124125intel_panel_disable_backlight(dev);126127I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);128129if (intel_lvds->pfit_control) {130if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000))131DRM_ERROR("timed out waiting for panel to power off\n");132133I915_WRITE(PFIT_CONTROL, 0);134intel_lvds->pfit_dirty = true;135}136137I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);138POSTING_READ(lvds_reg);139}140141static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)142{143struct intel_lvds *intel_lvds = to_intel_lvds(encoder);144145if (mode == DRM_MODE_DPMS_ON)146intel_lvds_enable(intel_lvds);147else148intel_lvds_disable(intel_lvds);149150/* XXX: We never power down the LVDS pairs. */151}152153static int intel_lvds_mode_valid(struct drm_connector *connector,154struct drm_display_mode *mode)155{156struct intel_lvds *intel_lvds = intel_attached_lvds(connector);157struct drm_display_mode *fixed_mode = intel_lvds->fixed_mode;158159if (mode->hdisplay > fixed_mode->hdisplay)160return MODE_PANEL;161if (mode->vdisplay > fixed_mode->vdisplay)162return MODE_PANEL;163164return MODE_OK;165}166167static void168centre_horizontally(struct drm_display_mode *mode,169int width)170{171u32 border, sync_pos, blank_width, sync_width;172173/* keep the hsync and hblank widths constant */174sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;175blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;176sync_pos = (blank_width - sync_width + 1) / 2;177178border = (mode->hdisplay - width + 1) / 2;179border += border & 1; /* make the border even */180181mode->crtc_hdisplay = width;182mode->crtc_hblank_start = width + border;183mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;184185mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;186mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;187}188189static void190centre_vertically(struct drm_display_mode *mode,191int height)192{193u32 border, sync_pos, blank_width, sync_width;194195/* keep the vsync and vblank widths constant */196sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;197blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;198sync_pos = (blank_width - sync_width + 1) / 2;199200border = (mode->vdisplay - height + 1) / 2;201202mode->crtc_vdisplay = height;203mode->crtc_vblank_start = height + border;204mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;205206mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;207mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;208}209210static inline u32 panel_fitter_scaling(u32 source, u32 target)211{212/*213* Floating point operation is not supported. So the FACTOR214* is defined, which can avoid the floating point computation215* when calculating the panel ratio.216*/217#define ACCURACY 12218#define FACTOR (1 << ACCURACY)219u32 ratio = source * FACTOR / target;220return (FACTOR * ratio + FACTOR/2) / FACTOR;221}222223static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,224struct drm_display_mode *mode,225struct drm_display_mode *adjusted_mode)226{227struct drm_device *dev = encoder->dev;228struct drm_i915_private *dev_priv = dev->dev_private;229struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);230struct intel_lvds *intel_lvds = to_intel_lvds(encoder);231struct drm_encoder *tmp_encoder;232u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;233int pipe;234235/* Should never happen!! */236if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {237DRM_ERROR("Can't support LVDS on pipe A\n");238return false;239}240241/* Should never happen!! */242list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {243if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {244DRM_ERROR("Can't enable LVDS and another "245"encoder on the same pipe\n");246return false;247}248}249250/*251* We have timings from the BIOS for the panel, put them in252* to the adjusted mode. The CRTC will be set up for this mode,253* with the panel scaling set up to source from the H/VDisplay254* of the original mode.255*/256intel_fixed_panel_mode(intel_lvds->fixed_mode, adjusted_mode);257258if (HAS_PCH_SPLIT(dev)) {259intel_pch_panel_fitting(dev, intel_lvds->fitting_mode,260mode, adjusted_mode);261return true;262}263264/* Native modes don't need fitting */265if (adjusted_mode->hdisplay == mode->hdisplay &&266adjusted_mode->vdisplay == mode->vdisplay)267goto out;268269/* 965+ wants fuzzy fitting */270if (INTEL_INFO(dev)->gen >= 4)271pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |272PFIT_FILTER_FUZZY);273274/*275* Enable automatic panel scaling for non-native modes so that they fill276* the screen. Should be enabled before the pipe is enabled, according277* to register description and PRM.278* Change the value here to see the borders for debugging279*/280for_each_pipe(pipe)281I915_WRITE(BCLRPAT(pipe), 0);282283switch (intel_lvds->fitting_mode) {284case DRM_MODE_SCALE_CENTER:285/*286* For centered modes, we have to calculate border widths &287* heights and modify the values programmed into the CRTC.288*/289centre_horizontally(adjusted_mode, mode->hdisplay);290centre_vertically(adjusted_mode, mode->vdisplay);291border = LVDS_BORDER_ENABLE;292break;293294case DRM_MODE_SCALE_ASPECT:295/* Scale but preserve the aspect ratio */296if (INTEL_INFO(dev)->gen >= 4) {297u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;298u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;299300/* 965+ is easy, it does everything in hw */301if (scaled_width > scaled_height)302pfit_control |= PFIT_ENABLE | PFIT_SCALING_PILLAR;303else if (scaled_width < scaled_height)304pfit_control |= PFIT_ENABLE | PFIT_SCALING_LETTER;305else if (adjusted_mode->hdisplay != mode->hdisplay)306pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;307} else {308u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;309u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;310/*311* For earlier chips we have to calculate the scaling312* ratio by hand and program it into the313* PFIT_PGM_RATIO register314*/315if (scaled_width > scaled_height) { /* pillar */316centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);317318border = LVDS_BORDER_ENABLE;319if (mode->vdisplay != adjusted_mode->vdisplay) {320u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);321pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |322bits << PFIT_VERT_SCALE_SHIFT);323pfit_control |= (PFIT_ENABLE |324VERT_INTERP_BILINEAR |325HORIZ_INTERP_BILINEAR);326}327} else if (scaled_width < scaled_height) { /* letter */328centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);329330border = LVDS_BORDER_ENABLE;331if (mode->hdisplay != adjusted_mode->hdisplay) {332u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);333pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |334bits << PFIT_VERT_SCALE_SHIFT);335pfit_control |= (PFIT_ENABLE |336VERT_INTERP_BILINEAR |337HORIZ_INTERP_BILINEAR);338}339} else340/* Aspects match, Let hw scale both directions */341pfit_control |= (PFIT_ENABLE |342VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |343VERT_INTERP_BILINEAR |344HORIZ_INTERP_BILINEAR);345}346break;347348case DRM_MODE_SCALE_FULLSCREEN:349/*350* Full scaling, even if it changes the aspect ratio.351* Fortunately this is all done for us in hw.352*/353if (mode->vdisplay != adjusted_mode->vdisplay ||354mode->hdisplay != adjusted_mode->hdisplay) {355pfit_control |= PFIT_ENABLE;356if (INTEL_INFO(dev)->gen >= 4)357pfit_control |= PFIT_SCALING_AUTO;358else359pfit_control |= (VERT_AUTO_SCALE |360VERT_INTERP_BILINEAR |361HORIZ_AUTO_SCALE |362HORIZ_INTERP_BILINEAR);363}364break;365366default:367break;368}369370out:371/* If not enabling scaling, be consistent and always use 0. */372if ((pfit_control & PFIT_ENABLE) == 0) {373pfit_control = 0;374pfit_pgm_ratios = 0;375}376377/* Make sure pre-965 set dither correctly */378if (INTEL_INFO(dev)->gen < 4 && dev_priv->lvds_dither)379pfit_control |= PANEL_8TO6_DITHER_ENABLE;380381if (pfit_control != intel_lvds->pfit_control ||382pfit_pgm_ratios != intel_lvds->pfit_pgm_ratios) {383intel_lvds->pfit_control = pfit_control;384intel_lvds->pfit_pgm_ratios = pfit_pgm_ratios;385intel_lvds->pfit_dirty = true;386}387dev_priv->lvds_border_bits = border;388389/*390* XXX: It would be nice to support lower refresh rates on the391* panels to reduce power consumption, and perhaps match the392* user's requested refresh rate.393*/394395return true;396}397398static void intel_lvds_prepare(struct drm_encoder *encoder)399{400struct drm_device *dev = encoder->dev;401struct drm_i915_private *dev_priv = dev->dev_private;402struct intel_lvds *intel_lvds = to_intel_lvds(encoder);403404/* We try to do the minimum that is necessary in order to unlock405* the registers for mode setting.406*407* On Ironlake, this is quite simple as we just set the unlock key408* and ignore all subtleties. (This may cause some issues...)409*410* Prior to Ironlake, we must disable the pipe if we want to adjust411* the panel fitter. However at all other times we can just reset412* the registers regardless.413*/414415if (HAS_PCH_SPLIT(dev)) {416I915_WRITE(PCH_PP_CONTROL,417I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);418} else if (intel_lvds->pfit_dirty) {419I915_WRITE(PP_CONTROL,420(I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS)421& ~POWER_TARGET_ON);422} else {423I915_WRITE(PP_CONTROL,424I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);425}426}427428static void intel_lvds_commit(struct drm_encoder *encoder)429{430struct drm_device *dev = encoder->dev;431struct drm_i915_private *dev_priv = dev->dev_private;432struct intel_lvds *intel_lvds = to_intel_lvds(encoder);433434/* Undo any unlocking done in prepare to prevent accidental435* adjustment of the registers.436*/437if (HAS_PCH_SPLIT(dev)) {438u32 val = I915_READ(PCH_PP_CONTROL);439if ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)440I915_WRITE(PCH_PP_CONTROL, val & 0x3);441} else {442u32 val = I915_READ(PP_CONTROL);443if ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)444I915_WRITE(PP_CONTROL, val & 0x3);445}446447/* Always do a full power on as we do not know what state448* we were left in.449*/450intel_lvds_enable(intel_lvds);451}452453static void intel_lvds_mode_set(struct drm_encoder *encoder,454struct drm_display_mode *mode,455struct drm_display_mode *adjusted_mode)456{457/*458* The LVDS pin pair will already have been turned on in the459* intel_crtc_mode_set since it has a large impact on the DPLL460* settings.461*/462}463464/**465* Detect the LVDS connection.466*467* Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means468* connected and closed means disconnected. We also send hotplug events as469* needed, using lid status notification from the input layer.470*/471static enum drm_connector_status472intel_lvds_detect(struct drm_connector *connector, bool force)473{474struct drm_device *dev = connector->dev;475enum drm_connector_status status;476477status = intel_panel_detect(dev);478if (status != connector_status_unknown)479return status;480481return connector_status_connected;482}483484/**485* Return the list of DDC modes if available, or the BIOS fixed mode otherwise.486*/487static int intel_lvds_get_modes(struct drm_connector *connector)488{489struct intel_lvds *intel_lvds = intel_attached_lvds(connector);490struct drm_device *dev = connector->dev;491struct drm_display_mode *mode;492493if (intel_lvds->edid)494return drm_add_edid_modes(connector, intel_lvds->edid);495496mode = drm_mode_duplicate(dev, intel_lvds->fixed_mode);497if (mode == NULL)498return 0;499500drm_mode_probed_add(connector, mode);501return 1;502}503504static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)505{506DRM_DEBUG_KMS("Skipping forced modeset for %s\n", id->ident);507return 1;508}509510/* The GPU hangs up on these systems if modeset is performed on LID open */511static const struct dmi_system_id intel_no_modeset_on_lid[] = {512{513.callback = intel_no_modeset_on_lid_dmi_callback,514.ident = "Toshiba Tecra A11",515.matches = {516DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),517DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),518},519},520521{ } /* terminating entry */522};523524/*525* Lid events. Note the use of 'modeset_on_lid':526* - we set it on lid close, and reset it on open527* - we use it as a "only once" bit (ie we ignore528* duplicate events where it was already properly529* set/reset)530* - the suspend/resume paths will also set it to531* zero, since they restore the mode ("lid open").532*/533static int intel_lid_notify(struct notifier_block *nb, unsigned long val,534void *unused)535{536struct drm_i915_private *dev_priv =537container_of(nb, struct drm_i915_private, lid_notifier);538struct drm_device *dev = dev_priv->dev;539struct drm_connector *connector = dev_priv->int_lvds_connector;540541if (dev->switch_power_state != DRM_SWITCH_POWER_ON)542return NOTIFY_OK;543544/*545* check and update the status of LVDS connector after receiving546* the LID nofication event.547*/548if (connector)549connector->status = connector->funcs->detect(connector,550false);551552/* Don't force modeset on machines where it causes a GPU lockup */553if (dmi_check_system(intel_no_modeset_on_lid))554return NOTIFY_OK;555if (!acpi_lid_open()) {556dev_priv->modeset_on_lid = 1;557return NOTIFY_OK;558}559560if (!dev_priv->modeset_on_lid)561return NOTIFY_OK;562563dev_priv->modeset_on_lid = 0;564565mutex_lock(&dev->mode_config.mutex);566drm_helper_resume_force_mode(dev);567mutex_unlock(&dev->mode_config.mutex);568569return NOTIFY_OK;570}571572/**573* intel_lvds_destroy - unregister and free LVDS structures574* @connector: connector to free575*576* Unregister the DDC bus for this connector then free the driver private577* structure.578*/579static void intel_lvds_destroy(struct drm_connector *connector)580{581struct drm_device *dev = connector->dev;582struct drm_i915_private *dev_priv = dev->dev_private;583584if (dev_priv->lid_notifier.notifier_call)585acpi_lid_notifier_unregister(&dev_priv->lid_notifier);586drm_sysfs_connector_remove(connector);587drm_connector_cleanup(connector);588kfree(connector);589}590591static int intel_lvds_set_property(struct drm_connector *connector,592struct drm_property *property,593uint64_t value)594{595struct intel_lvds *intel_lvds = intel_attached_lvds(connector);596struct drm_device *dev = connector->dev;597598if (property == dev->mode_config.scaling_mode_property) {599struct drm_crtc *crtc = intel_lvds->base.base.crtc;600601if (value == DRM_MODE_SCALE_NONE) {602DRM_DEBUG_KMS("no scaling not supported\n");603return -EINVAL;604}605606if (intel_lvds->fitting_mode == value) {607/* the LVDS scaling property is not changed */608return 0;609}610intel_lvds->fitting_mode = value;611if (crtc && crtc->enabled) {612/*613* If the CRTC is enabled, the display will be changed614* according to the new panel fitting mode.615*/616drm_crtc_helper_set_mode(crtc, &crtc->mode,617crtc->x, crtc->y, crtc->fb);618}619}620621return 0;622}623624static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {625.dpms = intel_lvds_dpms,626.mode_fixup = intel_lvds_mode_fixup,627.prepare = intel_lvds_prepare,628.mode_set = intel_lvds_mode_set,629.commit = intel_lvds_commit,630};631632static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {633.get_modes = intel_lvds_get_modes,634.mode_valid = intel_lvds_mode_valid,635.best_encoder = intel_best_encoder,636};637638static const struct drm_connector_funcs intel_lvds_connector_funcs = {639.dpms = drm_helper_connector_dpms,640.detect = intel_lvds_detect,641.fill_modes = drm_helper_probe_single_connector_modes,642.set_property = intel_lvds_set_property,643.destroy = intel_lvds_destroy,644};645646static const struct drm_encoder_funcs intel_lvds_enc_funcs = {647.destroy = intel_encoder_destroy,648};649650static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)651{652DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident);653return 1;654}655656/* These systems claim to have LVDS, but really don't */657static const struct dmi_system_id intel_no_lvds[] = {658{659.callback = intel_no_lvds_dmi_callback,660.ident = "Apple Mac Mini (Core series)",661.matches = {662DMI_MATCH(DMI_SYS_VENDOR, "Apple"),663DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),664},665},666{667.callback = intel_no_lvds_dmi_callback,668.ident = "Apple Mac Mini (Core 2 series)",669.matches = {670DMI_MATCH(DMI_SYS_VENDOR, "Apple"),671DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),672},673},674{675.callback = intel_no_lvds_dmi_callback,676.ident = "MSI IM-945GSE-A",677.matches = {678DMI_MATCH(DMI_SYS_VENDOR, "MSI"),679DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),680},681},682{683.callback = intel_no_lvds_dmi_callback,684.ident = "Dell Studio Hybrid",685.matches = {686DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),687DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),688},689},690{691.callback = intel_no_lvds_dmi_callback,692.ident = "AOpen Mini PC",693.matches = {694DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),695DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),696},697},698{699.callback = intel_no_lvds_dmi_callback,700.ident = "AOpen Mini PC MP915",701.matches = {702DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),703DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),704},705},706{707.callback = intel_no_lvds_dmi_callback,708.ident = "AOpen i915GMm-HFS",709.matches = {710DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),711DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),712},713},714{715.callback = intel_no_lvds_dmi_callback,716.ident = "Aopen i945GTt-VFA",717.matches = {718DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),719},720},721{722.callback = intel_no_lvds_dmi_callback,723.ident = "Clientron U800",724.matches = {725DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),726DMI_MATCH(DMI_PRODUCT_NAME, "U800"),727},728},729{730.callback = intel_no_lvds_dmi_callback,731.ident = "Asus EeeBox PC EB1007",732.matches = {733DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),734DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),735},736},737738{ } /* terminating entry */739};740741/**742* intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID743* @dev: drm device744* @connector: LVDS connector745*746* Find the reduced downclock for LVDS in EDID.747*/748static void intel_find_lvds_downclock(struct drm_device *dev,749struct drm_display_mode *fixed_mode,750struct drm_connector *connector)751{752struct drm_i915_private *dev_priv = dev->dev_private;753struct drm_display_mode *scan;754int temp_downclock;755756temp_downclock = fixed_mode->clock;757list_for_each_entry(scan, &connector->probed_modes, head) {758/*759* If one mode has the same resolution with the fixed_panel760* mode while they have the different refresh rate, it means761* that the reduced downclock is found for the LVDS. In such762* case we can set the different FPx0/1 to dynamically select763* between low and high frequency.764*/765if (scan->hdisplay == fixed_mode->hdisplay &&766scan->hsync_start == fixed_mode->hsync_start &&767scan->hsync_end == fixed_mode->hsync_end &&768scan->htotal == fixed_mode->htotal &&769scan->vdisplay == fixed_mode->vdisplay &&770scan->vsync_start == fixed_mode->vsync_start &&771scan->vsync_end == fixed_mode->vsync_end &&772scan->vtotal == fixed_mode->vtotal) {773if (scan->clock < temp_downclock) {774/*775* The downclock is already found. But we776* expect to find the lower downclock.777*/778temp_downclock = scan->clock;779}780}781}782if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {783/* We found the downclock for LVDS. */784dev_priv->lvds_downclock_avail = 1;785dev_priv->lvds_downclock = temp_downclock;786DRM_DEBUG_KMS("LVDS downclock is found in EDID. "787"Normal clock %dKhz, downclock %dKhz\n",788fixed_mode->clock, temp_downclock);789}790}791792/*793* Enumerate the child dev array parsed from VBT to check whether794* the LVDS is present.795* If it is present, return 1.796* If it is not present, return false.797* If no child dev is parsed from VBT, it assumes that the LVDS is present.798*/799static bool lvds_is_present_in_vbt(struct drm_device *dev,800u8 *i2c_pin)801{802struct drm_i915_private *dev_priv = dev->dev_private;803int i;804805if (!dev_priv->child_dev_num)806return true;807808for (i = 0; i < dev_priv->child_dev_num; i++) {809struct child_device_config *child = dev_priv->child_dev + i;810811/* If the device type is not LFP, continue.812* We have to check both the new identifiers as well as the813* old for compatibility with some BIOSes.814*/815if (child->device_type != DEVICE_TYPE_INT_LFP &&816child->device_type != DEVICE_TYPE_LFP)817continue;818819if (child->i2c_pin)820*i2c_pin = child->i2c_pin;821822/* However, we cannot trust the BIOS writers to populate823* the VBT correctly. Since LVDS requires additional824* information from AIM blocks, a non-zero addin offset is825* a good indicator that the LVDS is actually present.826*/827if (child->addin_offset)828return true;829830/* But even then some BIOS writers perform some black magic831* and instantiate the device without reference to any832* additional data. Trust that if the VBT was written into833* the OpRegion then they have validated the LVDS's existence.834*/835if (dev_priv->opregion.vbt)836return true;837}838839return false;840}841842/**843* intel_lvds_init - setup LVDS connectors on this device844* @dev: drm device845*846* Create the connector, register the LVDS DDC bus, and try to figure out what847* modes we can display on the LVDS panel (if present).848*/849bool intel_lvds_init(struct drm_device *dev)850{851struct drm_i915_private *dev_priv = dev->dev_private;852struct intel_lvds *intel_lvds;853struct intel_encoder *intel_encoder;854struct intel_connector *intel_connector;855struct drm_connector *connector;856struct drm_encoder *encoder;857struct drm_display_mode *scan; /* *modes, *bios_mode; */858struct drm_crtc *crtc;859u32 lvds;860int pipe;861u8 pin;862863/* Skip init on machines we know falsely report LVDS */864if (dmi_check_system(intel_no_lvds))865return false;866867pin = GMBUS_PORT_PANEL;868if (!lvds_is_present_in_vbt(dev, &pin)) {869DRM_DEBUG_KMS("LVDS is not present in VBT\n");870return false;871}872873if (HAS_PCH_SPLIT(dev)) {874if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)875return false;876if (dev_priv->edp.support) {877DRM_DEBUG_KMS("disable LVDS for eDP support\n");878return false;879}880}881882intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL);883if (!intel_lvds) {884return false;885}886887intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);888if (!intel_connector) {889kfree(intel_lvds);890return false;891}892893if (!HAS_PCH_SPLIT(dev)) {894intel_lvds->pfit_control = I915_READ(PFIT_CONTROL);895}896897intel_encoder = &intel_lvds->base;898encoder = &intel_encoder->base;899connector = &intel_connector->base;900drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,901DRM_MODE_CONNECTOR_LVDS);902903drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,904DRM_MODE_ENCODER_LVDS);905906intel_connector_attach_encoder(intel_connector, intel_encoder);907intel_encoder->type = INTEL_OUTPUT_LVDS;908909intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT);910intel_encoder->crtc_mask = (1 << 1);911if (INTEL_INFO(dev)->gen >= 5)912intel_encoder->crtc_mask |= (1 << 0);913drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);914drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);915connector->display_info.subpixel_order = SubPixelHorizontalRGB;916connector->interlace_allowed = false;917connector->doublescan_allowed = false;918919/* create the scaling mode property */920drm_mode_create_scaling_mode_property(dev);921/*922* the initial panel fitting mode will be FULL_SCREEN.923*/924925drm_connector_attach_property(&intel_connector->base,926dev->mode_config.scaling_mode_property,927DRM_MODE_SCALE_ASPECT);928intel_lvds->fitting_mode = DRM_MODE_SCALE_ASPECT;929/*930* LVDS discovery:931* 1) check for EDID on DDC932* 2) check for VBT data933* 3) check to see if LVDS is already on934* if none of the above, no panel935* 4) make sure lid is open936* if closed, act like it's not there for now937*/938939/*940* Attempt to get the fixed panel mode from DDC. Assume that the941* preferred mode is the right one.942*/943intel_lvds->edid = drm_get_edid(connector,944&dev_priv->gmbus[pin].adapter);945if (intel_lvds->edid) {946if (drm_add_edid_modes(connector,947intel_lvds->edid)) {948drm_mode_connector_update_edid_property(connector,949intel_lvds->edid);950} else {951kfree(intel_lvds->edid);952intel_lvds->edid = NULL;953}954}955if (!intel_lvds->edid) {956/* Didn't get an EDID, so957* Set wide sync ranges so we get all modes958* handed to valid_mode for checking959*/960connector->display_info.min_vfreq = 0;961connector->display_info.max_vfreq = 200;962connector->display_info.min_hfreq = 0;963connector->display_info.max_hfreq = 200;964}965966list_for_each_entry(scan, &connector->probed_modes, head) {967if (scan->type & DRM_MODE_TYPE_PREFERRED) {968intel_lvds->fixed_mode =969drm_mode_duplicate(dev, scan);970intel_find_lvds_downclock(dev,971intel_lvds->fixed_mode,972connector);973goto out;974}975}976977/* Failed to get EDID, what about VBT? */978if (dev_priv->lfp_lvds_vbt_mode) {979intel_lvds->fixed_mode =980drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);981if (intel_lvds->fixed_mode) {982intel_lvds->fixed_mode->type |=983DRM_MODE_TYPE_PREFERRED;984goto out;985}986}987988/*989* If we didn't get EDID, try checking if the panel is already turned990* on. If so, assume that whatever is currently programmed is the991* correct mode.992*/993994/* Ironlake: FIXME if still fail, not try pipe mode now */995if (HAS_PCH_SPLIT(dev))996goto failed;997998lvds = I915_READ(LVDS);999pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;1000crtc = intel_get_crtc_for_pipe(dev, pipe);10011002if (crtc && (lvds & LVDS_PORT_EN)) {1003intel_lvds->fixed_mode = intel_crtc_mode_get(dev, crtc);1004if (intel_lvds->fixed_mode) {1005intel_lvds->fixed_mode->type |=1006DRM_MODE_TYPE_PREFERRED;1007goto out;1008}1009}10101011/* If we still don't have a mode after all that, give up. */1012if (!intel_lvds->fixed_mode)1013goto failed;10141015out:1016if (HAS_PCH_SPLIT(dev)) {1017u32 pwm;10181019pipe = (I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) ? 1 : 0;10201021/* make sure PWM is enabled and locked to the LVDS pipe */1022pwm = I915_READ(BLC_PWM_CPU_CTL2);1023if (pipe == 0 && (pwm & PWM_PIPE_B))1024I915_WRITE(BLC_PWM_CPU_CTL2, pwm & ~PWM_ENABLE);1025if (pipe)1026pwm |= PWM_PIPE_B;1027else1028pwm &= ~PWM_PIPE_B;1029I915_WRITE(BLC_PWM_CPU_CTL2, pwm | PWM_ENABLE);10301031pwm = I915_READ(BLC_PWM_PCH_CTL1);1032pwm |= PWM_PCH_ENABLE;1033I915_WRITE(BLC_PWM_PCH_CTL1, pwm);1034}1035dev_priv->lid_notifier.notifier_call = intel_lid_notify;1036if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) {1037DRM_DEBUG_KMS("lid notifier registration failed\n");1038dev_priv->lid_notifier.notifier_call = NULL;1039}1040/* keep the LVDS connector */1041dev_priv->int_lvds_connector = connector;1042drm_sysfs_connector_add(connector);1043return true;10441045failed:1046DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");1047drm_connector_cleanup(connector);1048drm_encoder_cleanup(encoder);1049kfree(intel_lvds);1050kfree(intel_connector);1051return false;1052}105310541055