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