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
1450N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1450N/A * DEALINGS IN THE SOFTWARE.
1450N/A *
1450N/A * Authors:
1450N/A * Eric Anholt <eric@anholt.net>
1450N/A *
1450N/A */
1450N/A
1450N/A#include "dvo.h"
1450N/A
1450N/A/*
1450N/A * register definitions for the i82807aa.
1450N/A *
1450N/A * Documentation on this chipset can be found in datasheet #29069001 at
1450N/A * intel.com.
1450N/A */
1450N/A
1450N/A/*
1450N/A * VCH Revision & GMBus Base Addr
1450N/A */
1450N/A#define VR00 0x00
1450N/A# define VR00_BASE_ADDRESS_MASK 0x007f
1450N/A
1450N/A/*
1450N/A * Functionality Enable
1450N/A */
1450N/A#define VR01 0x01
1450N/A
1450N/A/*
1450N/A * Enable the panel fitter
1450N/A */
1450N/A# define VR01_PANEL_FIT_ENABLE (1 << 3)
1450N/A/*
1450N/A * Enables the LCD display.
1450N/A *
1450N/A * This must not be set while VR01_DVO_BYPASS_ENABLE is set.
1450N/A */
1450N/A# define VR01_LCD_ENABLE (1 << 2)
1450N/A/** Enables the DVO repeater. */
1450N/A# define VR01_DVO_BYPASS_ENABLE (1 << 1)
1450N/A/** Enables the DVO clock */
1450N/A# define VR01_DVO_ENABLE (1 << 0)
1450N/A
1450N/A/*
1450N/A * LCD Interface Format
1450N/A */
1450N/A#define VR10 0x10
1450N/A/** Enables LVDS output instead of CMOS */
1450N/A# define VR10_LVDS_ENABLE (1 << 4)
1450N/A/** Enables 18-bit LVDS output. */
1450N/A# define VR10_INTERFACE_1X18 (0 << 2)
1450N/A/** Enables 24-bit LVDS or CMOS output */
1450N/A# define VR10_INTERFACE_1X24 (1 << 2)
1450N/A/** Enables 2x18-bit LVDS or CMOS output. */
1450N/A# define VR10_INTERFACE_2X18 (2 << 2)
1450N/A/** Enables 2x24-bit LVDS output */
1450N/A# define VR10_INTERFACE_2X24 (3 << 2)
1450N/A
1450N/A/*
1450N/A * VR20 LCD Horizontal Display Size
1450N/A */
1450N/A#define VR20 0x20
1450N/A
1450N/A/*
1450N/A * LCD Vertical Display Size
1450N/A */
1450N/A#define VR21 0x20
1450N/A
1450N/A/*
1450N/A * Panel power down status
1450N/A */
1450N/A#define VR30 0x30
1450N/A/** Read only bit indicating that the panel is not in a safe poweroff state. */
1450N/A# define VR30_PANEL_ON (1 << 15)
1450N/A
1450N/A#define VR40 0x40
1450N/A# define VR40_STALL_ENABLE (1 << 13)
1450N/A# define VR40_VERTICAL_INTERP_ENABLE (1 << 12)
1450N/A# define VR40_ENHANCED_PANEL_FITTING (1 << 11)
1450N/A# define VR40_HORIZONTAL_INTERP_ENABLE (1 << 10)
1450N/A# define VR40_AUTO_RATIO_ENABLE (1 << 9)
1450N/A# define VR40_CLOCK_GATING_ENABLE (1 << 8)
1450N/A
1450N/A/*
1450N/A * Panel Fitting Vertical Ratio
1450N/A * (((image_height - 1) << 16) / ((panel_height - 1))) >> 2
1450N/A */
1450N/A#define VR41 0x41
1450N/A
1450N/A/*
1450N/A * Panel Fitting Horizontal Ratio
1450N/A * (((image_width - 1) << 16) / ((panel_width - 1))) >> 2
1450N/A */
1450N/A#define VR42 0x42
1450N/A
1450N/A/*
1450N/A * Horizontal Image Size
1450N/A */
1450N/A#define VR43 0x43
1450N/A
1450N/A/* VR80 GPIO 0
1450N/A */
1450N/A#define VR80 0x80
1450N/A#define VR81 0x81
1450N/A#define VR82 0x82
1450N/A#define VR83 0x83
1450N/A#define VR84 0x84
1450N/A#define VR85 0x85
1450N/A#define VR86 0x86
1450N/A#define VR87 0x87
1450N/A
1450N/A/* VR88 GPIO 8
1450N/A */
1450N/A#define VR88 0x88
1450N/A
1450N/A/* Graphics BIOS scratch 0
1450N/A */
1450N/A#define VR8E 0x8E
1450N/A# define VR8E_PANEL_TYPE_MASK (0xf << 0)
1450N/A# define VR8E_PANEL_INTERFACE_CMOS (0 << 4)
1450N/A# define VR8E_PANEL_INTERFACE_LVDS (1 << 4)
1450N/A# define VR8E_FORCE_DEFAULT_PANEL (1 << 5)
1450N/A
1450N/A/* Graphics BIOS scratch 1
1450N/A */
1450N/A#define VR8F 0x8F
1450N/A# define VR8F_VCH_PRESENT (1 << 0)
1450N/A# define VR8F_DISPLAY_CONN (1 << 1)
1450N/A# define VR8F_POWER_MASK (0x3c)
1450N/A# define VR8F_POWER_POS (2)
1450N/A
1450N/A
1450N/Astruct ivch_priv {
1450N/A bool quiet;
1450N/A
1450N/A uint16_t width, height;
1450N/A};
1450N/A
1450N/A
1450N/Astatic void ivch_dump_regs(struct intel_dvo_device *dvo);
1450N/A
1450N/A/**
1450N/A * Reads a register on the ivch.
1450N/A *
1450N/A * Each of the 256 registers are 16 bits long.
1450N/A */
1450N/Astatic bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
1450N/A{
1450N/A struct ivch_priv *priv = dvo->dev_priv;
1450N/A struct i2c_adapter *adapter = dvo->i2c_bus;
1450N/A u8 out_buf[1];
1450N/A u8 in_buf[2];
1450N/A
1450N/A struct i2c_msg msgs[] = {
1450N/A {
1450N/A .addr = dvo->slave_addr,
1450N/A .flags = I2C_M_RD,
1450N/A .len = 0,
1450N/A },
1450N/A {
1450N/A .addr = 0,
1450N/A .flags = I2C_M_NOSTART,
1450N/A .len = 1,
1450N/A .buf = out_buf,
1450N/A },
1450N/A {
1450N/A .addr = dvo->slave_addr,
1450N/A .flags = I2C_M_RD | I2C_M_NOSTART,
1450N/A .len = 2,
1450N/A .buf = in_buf,
1450N/A }
1450N/A };
1450N/A
1450N/A out_buf[0] = (u8) addr;
1450N/A
1450N/A if (i2c_transfer(adapter, msgs, 3) == 3) {
1450N/A *data = (in_buf[1] << 8) | in_buf[0];
1450N/A return true;
1450N/A };
1450N/A
1450N/A if (!priv->quiet) {
1450N/A DRM_DEBUG_KMS("Unable to read register 0x%02x from "
1450N/A "%s:%02x.\n",
1450N/A addr, adapter->name, dvo->slave_addr);
1450N/A }
1450N/A return false;
1450N/A}
1450N/A
1450N/A/** Writes a 16-bit register on the ivch */
1450N/Astatic bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
1450N/A{
1450N/A struct ivch_priv *priv = dvo->dev_priv;
1450N/A struct i2c_adapter *adapter = dvo->i2c_bus;
1450N/A u8 out_buf[3];
1450N/A struct i2c_msg msg = {
1450N/A .addr = dvo->slave_addr,
1450N/A .flags = 0,
1450N/A .len = 3,
1450N/A .buf = out_buf,
1450N/A };
1450N/A
1450N/A out_buf[0] = (u8) addr;
1450N/A out_buf[1] = data & 0xff;
1450N/A out_buf[2] = data >> 8;
1450N/A
1450N/A if (i2c_transfer(adapter, &msg, 1) == 1)
1450N/A return true;
1450N/A
1450N/A if (!priv->quiet) {
1450N/A DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
1450N/A addr, adapter->name, dvo->slave_addr);
1450N/A }
1450N/A
1450N/A return false;
1450N/A}
1450N/A
1450N/A/** Probes the given bus and slave address for an ivch */
1450N/Astatic bool ivch_init(struct intel_dvo_device *dvo,
1450N/A struct i2c_adapter *adapter)
1450N/A{
1450N/A struct ivch_priv *priv;
1450N/A uint16_t temp;
1450N/A
1450N/A priv = kzalloc(sizeof(struct ivch_priv), GFP_KERNEL);
1450N/A if (priv == NULL)
1450N/A return false;
1450N/A
1450N/A dvo->i2c_bus = adapter;
1450N/A dvo->dev_priv = priv;
1450N/A priv->quiet = true;
1450N/A
1450N/A if (!ivch_read(dvo, VR00, &temp))
1450N/A goto out;
1450N/A priv->quiet = false;
1450N/A
1450N/A /* Since the identification bits are probably zeroes, which doesn't seem
1450N/A * very unique, check that the value in the base address field matches
1450N/A * the address it's responding on.
1450N/A */
1450N/A if ((temp & VR00_BASE_ADDRESS_MASK) != dvo->slave_addr) {
1450N/A DRM_DEBUG_KMS("ivch detect failed due to address mismatch "
1450N/A "(%d vs %d)\n",
1450N/A (temp & VR00_BASE_ADDRESS_MASK), dvo->slave_addr);
1450N/A goto out;
1450N/A }
1450N/A
1450N/A (void) ivch_read(dvo, VR20, &priv->width);
1450N/A (void) ivch_read(dvo, VR21, &priv->height);
1450N/A
1450N/A return true;
1450N/A
1450N/Aout:
1450N/A kfree(priv, sizeof (struct ivch_priv));
1450N/A return false;
1450N/A}
1450N/A
1450N/A/* LINTED */
1450N/Astatic enum drm_connector_status ivch_detect(struct intel_dvo_device *dvo)
1450N/A{
1450N/A return connector_status_connected;
1450N/A}
1450N/A
1450N/A/* LINTED */
1450N/Astatic int ivch_mode_valid(struct intel_dvo_device *dvo,
1450N/A struct drm_display_mode *mode)
1450N/A{
1450N/A if (mode->clock > 112000)
1450N/A return MODE_CLOCK_HIGH;
1450N/A
1450N/A return MODE_OK;
1450N/A}
1450N/A
1450N/A/** Sets the power state of the panel connected to the ivch */
1450N/Astatic void ivch_dpms(struct intel_dvo_device *dvo, bool enable)
1450N/A{
1450N/A int i;
1450N/A uint16_t vr01, vr30, backlight;
1450N/A
1450N/A /* Set the new power state of the panel. */
1450N/A if (!ivch_read(dvo, VR01, &vr01))
1450N/A return;
1450N/A
1450N/A if (enable)
1450N/A backlight = 1;
1450N/A else
1450N/A backlight = 0;
1450N/A (void) ivch_write(dvo, VR80, backlight);
1450N/A
1450N/A if (enable)
1450N/A vr01 |= VR01_LCD_ENABLE | VR01_DVO_ENABLE;
1450N/A else
1450N/A vr01 &= ~(VR01_LCD_ENABLE | VR01_DVO_ENABLE);
1450N/A
1450N/A (void) ivch_write(dvo, VR01, vr01);
1450N/A
1450N/A /* Wait for the panel to make its state transition */
1450N/A for (i = 0; i < 100; i++) {
1450N/A if (!ivch_read(dvo, VR30, &vr30))
1450N/A break;
1450N/A
1450N/A if (((vr30 & VR30_PANEL_ON) != 0) == enable)
1450N/A break;
1450N/A udelay(1000);
1450N/A }
1450N/A /* wait some more; vch may fail to resync sometimes without this */
1450N/A udelay(16 * 1000);
1450N/A}
1450N/A
1450N/Astatic bool ivch_get_hw_state(struct intel_dvo_device *dvo)
1450N/A{
1450N/A uint16_t vr01;
1450N/A
1450N/A /* Set the new power state of the panel. */
1450N/A if (!ivch_read(dvo, VR01, &vr01))
1450N/A return false;
1450N/A
1450N/A if (vr01 & VR01_LCD_ENABLE)
1450N/A return true;
1450N/A else
1450N/A return false;
1450N/A}
1450N/A
1450N/Astatic void ivch_mode_set(struct intel_dvo_device *dvo,
1450N/A struct drm_display_mode *mode,
1450N/A struct drm_display_mode *adjusted_mode)
1450N/A{
1450N/A uint16_t vr40 = 0;
1450N/A uint16_t vr01;
1450N/A
1450N/A vr01 = 0;
1450N/A vr40 = (VR40_STALL_ENABLE | VR40_VERTICAL_INTERP_ENABLE |
1450N/A VR40_HORIZONTAL_INTERP_ENABLE);
1450N/A
1450N/A if (mode->hdisplay != adjusted_mode->hdisplay ||
1450N/A mode->vdisplay != adjusted_mode->vdisplay) {
1450N/A uint16_t x_ratio, y_ratio;
1450N/A
1450N/A vr01 |= VR01_PANEL_FIT_ENABLE;
1450N/A vr40 |= VR40_CLOCK_GATING_ENABLE;
1450N/A x_ratio = (((mode->hdisplay - 1) << 16) /
1450N/A (adjusted_mode->hdisplay - 1)) >> 2;
1450N/A y_ratio = (((mode->vdisplay - 1) << 16) /
1450N/A (adjusted_mode->vdisplay - 1)) >> 2;
1450N/A (void) ivch_write (dvo, VR42, x_ratio);
1450N/A (void) ivch_write (dvo, VR41, y_ratio);
1450N/A } else {
1450N/A vr01 &= ~VR01_PANEL_FIT_ENABLE;
1450N/A vr40 &= ~VR40_CLOCK_GATING_ENABLE;
1450N/A }
1450N/A vr40 &= ~VR40_AUTO_RATIO_ENABLE;
1450N/A
1450N/A (void) ivch_write(dvo, VR01, vr01);
1450N/A (void) ivch_write(dvo, VR40, vr40);
1450N/A
1450N/A ivch_dump_regs(dvo);
1450N/A}
1450N/A
1450N/Astatic void ivch_dump_regs(struct intel_dvo_device *dvo)
1450N/A{
1450N/A uint16_t val;
1450N/A
1450N/A (void) ivch_read(dvo, VR00, &val);
1450N/A DRM_LOG_KMS("VR00: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR01, &val);
1450N/A DRM_LOG_KMS("VR01: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR30, &val);
1450N/A DRM_LOG_KMS("VR30: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR40, &val);
1450N/A DRM_LOG_KMS("VR40: 0x%04x\n", val);
1450N/A
1450N/A /* GPIO registers */
1450N/A (void) ivch_read(dvo, VR80, &val);
1450N/A DRM_LOG_KMS("VR80: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR81, &val);
1450N/A DRM_LOG_KMS("VR81: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR82, &val);
1450N/A DRM_LOG_KMS("VR82: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR83, &val);
1450N/A DRM_LOG_KMS("VR83: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR84, &val);
1450N/A DRM_LOG_KMS("VR84: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR85, &val);
1450N/A DRM_LOG_KMS("VR85: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR86, &val);
1450N/A DRM_LOG_KMS("VR86: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR87, &val);
1450N/A DRM_LOG_KMS("VR87: 0x%04x\n", val);
1450N/A (void) ivch_read(dvo, VR88, &val);
1450N/A DRM_LOG_KMS("VR88: 0x%04x\n", val);
1450N/A
1450N/A /* Scratch register 0 - AIM Panel type */
1450N/A (void) ivch_read(dvo, VR8E, &val);
1450N/A DRM_LOG_KMS("VR8E: 0x%04x\n", val);
1450N/A
1450N/A /* Scratch register 1 - Status register */
1450N/A (void) ivch_read(dvo, VR8F, &val);
1450N/A DRM_LOG_KMS("VR8F: 0x%04x\n", val);
1450N/A}
1450N/A
1450N/Astatic void ivch_destroy(struct intel_dvo_device *dvo)
1450N/A{
1450N/A struct ivch_priv *priv = dvo->dev_priv;
1450N/A
1450N/A if (priv) {
1450N/A kfree(priv, sizeof(struct ivch_priv));
1450N/A dvo->dev_priv = NULL;
1450N/A }
1450N/A}
1450N/A
1450N/Astruct intel_dvo_dev_ops ivch_ops= {
1450N/A .init = ivch_init,
1450N/A .dpms = ivch_dpms,
1450N/A .get_hw_state = ivch_get_hw_state,
1450N/A .mode_valid = ivch_mode_valid,
1450N/A .mode_set = ivch_mode_set,
1450N/A .detect = ivch_detect,
1450N/A .dump_regs = ivch_dump_regs,
1450N/A .destroy = ivch_destroy,
1450N/A};