[openchrome-devel] drm-openchrome: Branch 'drm-next-4.18' - 3 commits - drivers/gpu/drm
Kevin Brace
kevinbrace at kemper.freedesktop.org
Fri May 25 07:04:17 UTC 2018
drivers/gpu/drm/openchrome/Makefile | 3
drivers/gpu/drm/openchrome/openchrome_display.c | 2
drivers/gpu/drm/openchrome/openchrome_display.h | 4
drivers/gpu/drm/openchrome/openchrome_drv.h | 4
drivers/gpu/drm/openchrome/openchrome_tmds.c | 132 +++++
drivers/gpu/drm/openchrome/openchrome_vt1632.c | 574 ++++++++++++++++++++++++
6 files changed, 716 insertions(+), 3 deletions(-)
New commits:
commit c6be045d5b00f84b89d983372de6217a7d6a7c3f
Author: Kevin Brace <kevinbrace at gmx.com>
Date: Fri May 25 00:01:25 2018 -0700
drm/openchrome: Version bumped to 3.0.83
Added support for VIA Technologies VT1632(A) DVI transmitter.
Signed-off-by: Kevin Brace <kevinbrace at gmx.com>
diff --git a/drivers/gpu/drm/openchrome/openchrome_drv.h b/drivers/gpu/drm/openchrome/openchrome_drv.h
index 0c79a4fa9e81..54ccbee335dc 100644
--- a/drivers/gpu/drm/openchrome/openchrome_drv.h
+++ b/drivers/gpu/drm/openchrome/openchrome_drv.h
@@ -31,11 +31,11 @@
#define DRIVER_AUTHOR "OpenChrome Project"
#define DRIVER_NAME "openchrome"
#define DRIVER_DESC "OpenChrome DRM for VIA Technologies Chrome IGP"
-#define DRIVER_DATE "20180521"
+#define DRIVER_DATE "20180525"
#define DRIVER_MAJOR 3
#define DRIVER_MINOR 0
-#define DRIVER_PATCHLEVEL 82
+#define DRIVER_PATCHLEVEL 83
#include <linux/module.h>
#include "ttm/ttm_bo_api.h"
commit c864662314baa276f740bb382d515fac4ef625c8
Author: Kevin Brace <kevinbrace at gmx.com>
Date: Thu May 24 23:48:28 2018 -0700
drm/openchrome: Add VIA Technologies VT1632(A) DVI transmitter support
Signed-off-by: Kevin Brace <kevinbrace at gmx.com>
diff --git a/drivers/gpu/drm/openchrome/openchrome_display.c b/drivers/gpu/drm/openchrome/openchrome_display.c
index 60b1b7fcf7f9..5bf85a8971eb 100644
--- a/drivers/gpu/drm/openchrome/openchrome_display.c
+++ b/drivers/gpu/drm/openchrome/openchrome_display.c
@@ -499,6 +499,7 @@ via_modeset_init(struct drm_device *dev)
for (i = 0; i < 2; i++)
via_crtc_init(dev, i);
+ openchrome_ext_dvi_probe(dev);
via_tmds_probe(dev);
via_fp_probe(dev);
@@ -506,6 +507,7 @@ via_modeset_init(struct drm_device *dev)
via_analog_probe(dev);
+ openchrome_ext_dvi_init(dev);
via_tmds_init(dev);
via_analog_init(dev);
commit f6ea96438ae3882400c553d992804d4449f2e121
Author: Kevin Brace <kevinbrace at gmx.com>
Date: Thu May 24 23:43:51 2018 -0700
drm/openchrome: Add openchrome_vt1632.c
This file handles VIA Technologies VT1632(A) DVI transmitter control
in order to support DVI.
Signed-off-by: Kevin Brace <kevinbrace at gmx.com>
diff --git a/drivers/gpu/drm/openchrome/Makefile b/drivers/gpu/drm/openchrome/Makefile
index 18c64d4a8405..6a1e291f9e92 100644
--- a/drivers/gpu/drm/openchrome/Makefile
+++ b/drivers/gpu/drm/openchrome/Makefile
@@ -24,6 +24,7 @@ openchrome-y := openchrome_analog.o \
openchrome_sgdma.o \
openchrome_tmds.o \
openchrome_ttm.o \
- openchrome_verifier.o
+ openchrome_verifier.o \
+ openchrome_vt1632.o
obj-$(CONFIG_DRM_OPENCHROME) += openchrome.o
diff --git a/drivers/gpu/drm/openchrome/openchrome_display.h b/drivers/gpu/drm/openchrome/openchrome_display.h
index 46cc9aa67f67..8be09b18cd72 100644
--- a/drivers/gpu/drm/openchrome/openchrome_display.h
+++ b/drivers/gpu/drm/openchrome/openchrome_display.h
@@ -190,11 +190,15 @@ extern int via_connector_mode_valid(struct drm_connector *connector,
extern void via_connector_destroy(struct drm_connector *connector);
extern void via_analog_probe(struct drm_device *dev);
+extern bool openchrome_vt1632_probe(struct i2c_adapter *i2c_bus);
+extern void openchrome_ext_dvi_probe(struct drm_device *dev);
extern void via_tmds_probe(struct drm_device *dev);
extern void via_fp_probe(struct drm_device *dev);
extern void via_hdmi_init(struct drm_device *dev, u32 di_port);
extern void via_analog_init(struct drm_device *dev);
+extern void openchrome_vt1632_init(struct drm_device *dev);
+extern void openchrome_ext_dvi_init(struct drm_device *dev);
extern void via_tmds_init(struct drm_device *dev);
extern void via_fp_init(struct drm_device *dev);
diff --git a/drivers/gpu/drm/openchrome/openchrome_tmds.c b/drivers/gpu/drm/openchrome/openchrome_tmds.c
index 4eda7904a861..2b9589bc2879 100644
--- a/drivers/gpu/drm/openchrome/openchrome_tmds.c
+++ b/drivers/gpu/drm/openchrome/openchrome_tmds.c
@@ -512,3 +512,135 @@ void via_tmds_init(struct drm_device *dev)
exit:
DRM_DEBUG_KMS("Exiting %s.\n", __func__);
}
+
+/*
+ * Probe (pre-initialization detection) of external DVI transmitters.
+ */
+void openchrome_ext_dvi_probe(struct drm_device *dev)
+{
+ struct via_device *dev_priv = dev->dev_private;
+ struct i2c_adapter *i2c_bus;
+ u16 chipset = dev->pdev->device;
+ u8 sr12, sr13;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ dev_priv->ext_tmds_presence = false;
+ dev_priv->ext_tmds_i2c_bus = VIA_I2C_NONE;
+ dev_priv->ext_tmds_transmitter = VIA_TMDS_NONE;
+
+ if ((!dev_priv->ext_tmds_presence) &&
+ (!(dev_priv->mapped_i2c_bus & VIA_I2C_BUS2))) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ if (openchrome_vt1632_probe(i2c_bus)) {
+ dev_priv->ext_tmds_presence = true;
+ dev_priv->ext_tmds_i2c_bus = VIA_I2C_BUS2;
+ dev_priv->ext_tmds_transmitter = VIA_TMDS_VT1632;
+ dev_priv->mapped_i2c_bus |= VIA_I2C_BUS2;
+ }
+ }
+
+ if ((!(dev_priv->ext_tmds_presence)) &&
+ (!(dev_priv->mapped_i2c_bus & VIA_I2C_BUS4))) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ if (openchrome_vt1632_probe(i2c_bus)) {
+ dev_priv->ext_tmds_presence = true;
+ dev_priv->ext_tmds_i2c_bus = VIA_I2C_BUS4;
+ dev_priv->ext_tmds_transmitter = VIA_TMDS_VT1632;
+ dev_priv->mapped_i2c_bus |= VIA_I2C_BUS4;
+ }
+ }
+
+ sr12 = vga_rseq(VGABASE, 0x12);
+ sr13 = vga_rseq(VGABASE, 0x13);
+ DRM_DEBUG_KMS("SR12: 0x%02x\n", sr12);
+ DRM_DEBUG_KMS("SR13: 0x%02x\n", sr13);
+
+ if (dev_priv->ext_tmds_presence) {
+ switch (chipset) {
+ case PCI_DEVICE_ID_VIA_CLE266:
+
+ /* 3C5.12[4] - FPD17 pin strapping
+ * 0: TMDS transmitter (DVI) /
+ * capture device
+ * 1: Flat panel */
+ if (!(sr12 & BIT(4))) {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_DIP0;
+
+ /* 3C5.12[5] - FPD18 pin strapping
+ * 0: TMDS transmitter (DVI)
+ * 1: TV encoder */
+ } else if (!(sr12 & BIT(5))) {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_DIP1;
+ } else {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_NONE;
+ }
+
+ break;
+ case PCI_DEVICE_ID_VIA_KM400:
+ case PCI_DEVICE_ID_VIA_K8M800:
+ case PCI_DEVICE_ID_VIA_CN700:
+ case PCI_DEVICE_ID_VIA_PM800:
+ /* 3C5.12[6] - DVP0D6 pin strapping
+ * 0: Disable DVP0 (Digital Video Port 0) for
+ * DVI or TV out use
+ * 1: Enable DVP0 (Digital Video Port 0) for
+ * DVI or TV out use
+ * 3C5.12[5] - DVP0D5 pin strapping
+ * 0: TMDS transmitter (DVI)
+ * 1: TV encoder */
+ if ((sr12 & BIT(6)) && (!(sr12 & BIT(5)))) {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_DVP0;
+ } else {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_DVP1;
+ }
+
+ break;
+ case PCI_DEVICE_ID_VIA_VT3343:
+ case PCI_DEVICE_ID_VIA_K8M890:
+ case PCI_DEVICE_ID_VIA_P4M900:
+ /* Assume DVP2 as DVP0. Hence, VIA_DI_PORT_DVP0
+ * is used. */
+ /* 3C5.12[6] - DVP2D6 pin strapping
+ * 0: Disable DVP2 (Digital Video Port 2)
+ * 1: Enable DVP2 (Digital Video Port 2)
+ * 3C5.12[5] - DVP2D5 pin strapping
+ * 0: TMDS transmitter (DVI)
+ * 1: TV encoder */
+ if ((sr12 & BIT(6)) && (!(sr12 & BIT(5)))) {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_DVP0;
+ } else {
+ dev_priv->ext_tmds_di_port =
+ VIA_DI_PORT_NONE;
+ }
+
+ break;
+ case PCI_DEVICE_ID_VIA_VT3157:
+ case PCI_DEVICE_ID_VIA_VT1122:
+ case PCI_DEVICE_ID_VIA_VX875:
+ case PCI_DEVICE_ID_VIA_VX900_VGA:
+ dev_priv->ext_tmds_di_port = VIA_DI_PORT_DVP1;
+ break;
+ default:
+ dev_priv->ext_tmds_di_port = VIA_DI_PORT_NONE;
+ break;
+ }
+ }
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+void openchrome_ext_dvi_init(struct drm_device *dev)
+{
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ openchrome_vt1632_init(dev);
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
diff --git a/drivers/gpu/drm/openchrome/openchrome_vt1632.c b/drivers/gpu/drm/openchrome/openchrome_vt1632.c
new file mode 100644
index 000000000000..8f1482387207
--- /dev/null
+++ b/drivers/gpu/drm/openchrome/openchrome_vt1632.c
@@ -0,0 +1,574 @@
+/*
+ * Copyright (C) 2016-2018 Kevin Brace. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/*
+ * Author(s):
+ *
+ * Kevin Brace <kevinbrace at gmx.com>
+ *
+ */
+
+#include "openchrome_drv.h"
+#include "openchrome_crtc_hw.h"
+
+
+#define VIA_VT1632_VEN BIT(5)
+#define VIA_VT1632_HEN BIT(4)
+#define VIA_VT1632_DSEL BIT(3)
+#define VIA_VT1632_BSEL BIT(2)
+#define VIA_VT1632_EDGE BIT(1)
+#define VIA_VT1632_PDB BIT(0)
+
+
+static void openchrome_vt1632_power(struct i2c_adapter *i2c_bus, bool power_state)
+{
+ u8 buf;
+ u8 power_bit;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ via_i2c_readbytes(i2c_bus, 0x08, 0x08, &buf, 1);
+ power_bit = power_state ? VIA_VT1632_PDB : 0x00;
+ buf &= ~power_bit;
+ buf |= power_bit;
+ via_i2c_writebytes(i2c_bus, 0x08, 0x08, &buf, 1);
+ DRM_DEBUG_KMS("VT1632 (DVI) Power: %s\n",
+ power_state ? "On" : "Off");
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+
+static bool openchrome_vt1632_sense(struct i2c_adapter *i2c_bus)
+{
+ u8 buf;
+ bool rx_detected = false;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ via_i2c_readbytes(i2c_bus, 0x08, 0x09, &buf, 1);
+ if (buf & BIT(2)) {
+ rx_detected = true;
+ }
+
+ DRM_DEBUG_KMS("VT1632 (DVI) Connector Sense: %s\n",
+ rx_detected ? "Connected" : "Not Connected");
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return rx_detected;
+}
+
+static void openchrome_vt1632_display_registers(
+ struct i2c_adapter *i2c_bus)
+{
+ uint8_t i;
+ u8 buf;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ DRM_DEBUG_KMS("VT1632(A) Registers:\n");
+ for (i = 0; i < 0x10; i++) {
+ via_i2c_readbytes(i2c_bus, 0x08, i, &buf, 1);
+ DRM_DEBUG_KMS("0x%02x: 0x%02x\n", i, buf);
+ }
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+static void openchrome_vt1632_init_registers(
+ struct i2c_adapter *i2c_bus)
+{
+ u8 buf;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ /*
+ * For Wyse Cx0 thin client VX855 chipset DVP1 (Digital Video
+ * Port 1), use 12-bit mode with dual edge transfer, along
+ * with rising edge data capture first mode. This is likely
+ * true for CX700, VX700, VX800, and VX900 chipsets as well.
+ */
+ buf = VIA_VT1632_VEN | VIA_VT1632_HEN |
+ VIA_VT1632_DSEL |
+ VIA_VT1632_EDGE | VIA_VT1632_PDB;
+ via_i2c_writebytes(i2c_bus, 0x08, 0x08, &buf, 1);
+
+ /*
+ * Route receiver detect bit (Offset 0x09[2]) as the output
+ * of MSEN pin.
+ */
+ buf = BIT(5);
+ via_i2c_writebytes(i2c_bus, 0x08, 0x09, &buf, 1);
+
+ /*
+ * Turning on deskew feature caused screen display issues.
+ * This was observed with Wyse Cx0.
+ */
+ buf = 0x00;
+ via_i2c_writebytes(i2c_bus, 0x08, 0x0a, &buf, 1);
+
+ /*
+ * While VIA Technologies VT1632A datasheet insists on setting
+ * this register to 0x89 as the recommended setting, in
+ * practice, this leads to a blank screen on the display with
+ * Wyse Cx0. According to Silicon Image SiI 164 datasheet
+ * (VT1632(A) is a pin and mostly register compatible chip),
+ * offset 0x0C is for PLL filter enable, PLL filter setting,
+ * and continuous SYNC enable bits. All of these are turned
+ * off for proper operation.
+ */
+ buf = 0x00;
+ via_i2c_writebytes(i2c_bus, 0x08, 0x0c, &buf, 1);
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+
+static const struct drm_encoder_funcs openchrome_vt1632_drm_encoder_funcs = {
+ .destroy = via_encoder_cleanup,
+};
+
+static void openchrome_vt1632_dpms(struct drm_encoder *encoder, int mode)
+{
+ struct via_encoder *enc = container_of(encoder,
+ struct via_encoder, base);
+ struct via_device *dev_priv = encoder->dev->dev_private;
+ struct i2c_adapter *i2c_bus;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (enc->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (enc->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (enc->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (enc->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (enc->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ openchrome_vt1632_display_registers(i2c_bus);
+ switch (mode) {
+ case DRM_MODE_DPMS_ON:
+ openchrome_vt1632_power(i2c_bus, true);
+ openchrome_transmitter_io_pad_state(dev_priv, enc->di_port, true);
+ break;
+ case DRM_MODE_DPMS_STANDBY:
+ case DRM_MODE_DPMS_SUSPEND:
+ case DRM_MODE_DPMS_OFF:
+ openchrome_vt1632_power(i2c_bus, false);
+ openchrome_transmitter_io_pad_state(dev_priv, enc->di_port, false);
+ break;
+ default:
+ DRM_ERROR("Bad DPMS mode.");
+ break;
+ }
+
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+static bool openchrome_vt1632_mode_fixup(struct drm_encoder *encoder,
+ const struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode)
+{
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ drm_mode_set_crtcinfo(adjusted_mode, 0);
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return true;
+}
+
+static void openchrome_vt1632_mode_set(struct drm_encoder *encoder,
+ struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode)
+{
+ struct via_crtc *iga = container_of(encoder->crtc, struct via_crtc, base);
+ struct via_encoder *enc = container_of(encoder,
+ struct via_encoder, base);
+ struct via_device *dev_priv = encoder->dev->dev_private;
+ struct i2c_adapter *i2c_bus;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (enc->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (enc->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (enc->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (enc->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (enc->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ openchrome_transmitter_clock_drive_strength(dev_priv, enc->di_port, 0x03);
+ openchrome_transmitter_data_drive_strength(dev_priv, enc->di_port, 0x03);
+ openchrome_transmitter_io_pad_state(dev_priv, enc->di_port, true);
+
+ openchrome_vt1632_display_registers(i2c_bus);
+ openchrome_vt1632_init_registers(i2c_bus);
+ openchrome_vt1632_display_registers(i2c_bus);
+
+ openchrome_transmitter_display_source(dev_priv, enc->di_port, iga->index);
+exit:
+
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+static void openchrome_vt1632_prepare(struct drm_encoder *encoder)
+{
+ struct via_encoder *enc = container_of(encoder,
+ struct via_encoder, base);
+ struct via_device *dev_priv = encoder->dev->dev_private;
+ struct i2c_adapter *i2c_bus;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (enc->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (enc->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (enc->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (enc->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (enc->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ openchrome_vt1632_power(i2c_bus, false);
+ openchrome_transmitter_io_pad_state(dev_priv, enc->di_port, false);
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+static void openchrome_vt1632_commit(struct drm_encoder *encoder)
+{
+ struct via_encoder *enc = container_of(encoder,
+ struct via_encoder, base);
+ struct via_device *dev_priv = encoder->dev->dev_private;
+ struct i2c_adapter *i2c_bus;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (enc->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (enc->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (enc->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (enc->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (enc->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ openchrome_vt1632_power(i2c_bus, true);
+ openchrome_transmitter_io_pad_state(dev_priv, enc->di_port, true);
+
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+static void openchrome_vt1632_disable(struct drm_encoder *encoder)
+{
+ struct via_encoder *enc = container_of(encoder,
+ struct via_encoder, base);
+ struct via_device *dev_priv = encoder->dev->dev_private;
+ struct i2c_adapter *i2c_bus;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (enc->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (enc->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (enc->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (enc->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (enc->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ openchrome_vt1632_power(i2c_bus, false);
+ openchrome_transmitter_io_pad_state(dev_priv, enc->di_port, false);
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+
+static const struct drm_encoder_helper_funcs openchrome_vt1632_drm_encoder_helper_funcs = {
+ .dpms = openchrome_vt1632_dpms,
+ .mode_fixup = openchrome_vt1632_mode_fixup,
+ .mode_set = openchrome_vt1632_mode_set,
+ .prepare = openchrome_vt1632_prepare,
+ .commit = openchrome_vt1632_commit,
+ .disable = openchrome_vt1632_disable,
+};
+
+
+static enum drm_connector_status openchrome_vt1632_detect(
+ struct drm_connector *connector,
+ bool force)
+{
+ struct via_connector *con = container_of(connector,
+ struct via_connector, base);
+ struct i2c_adapter *i2c_bus;
+ enum drm_connector_status ret = connector_status_disconnected;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (con->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (con->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (con->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (con->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (con->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ if (openchrome_vt1632_sense(i2c_bus)) {
+ ret = connector_status_connected;
+ DRM_DEBUG_KMS("DVI detected.\n");
+ }
+
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return ret;
+}
+
+static const struct drm_connector_funcs openchrome_vt1632_drm_connector_funcs = {
+ .dpms = drm_helper_connector_dpms,
+ .detect = openchrome_vt1632_detect,
+ .fill_modes = drm_helper_probe_single_connector_modes,
+ .set_property = via_connector_set_property,
+ .destroy = via_connector_destroy,
+};
+
+
+int openchrome_vt1632_mode_valid(struct drm_connector *connector,
+ struct drm_display_mode *mode)
+{
+ struct via_connector *con = container_of(connector,
+ struct via_connector, base);
+ struct i2c_adapter *i2c_bus;
+ u8 buf;
+ uint32_t low_freq_limit, high_freq_limit;
+ int ret;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (con->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (con->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (con->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (con->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (con->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ ret = MODE_ERROR;
+ goto exit;
+ }
+
+ via_i2c_readbytes(i2c_bus, 0x08, 0x06, &buf, 1);
+ low_freq_limit = buf * 1000;
+ via_i2c_readbytes(i2c_bus, 0x08, 0x07, &buf, 1);
+ high_freq_limit = (buf + 65) * 1000;
+ DRM_DEBUG_KMS("Low Frequency Limit: %u KHz\n", low_freq_limit);
+ DRM_DEBUG_KMS("High Frequency Limit: %u KHz\n", high_freq_limit);
+
+ if (mode->clock < low_freq_limit) {
+ ret = MODE_CLOCK_LOW;
+ goto exit;
+ }
+
+ if (mode->clock > high_freq_limit) {
+ ret = MODE_CLOCK_HIGH;
+ goto exit;
+ }
+
+ ret = MODE_OK;
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return ret;
+}
+
+static int openchrome_vt1632_get_modes(struct drm_connector *connector)
+{
+ struct via_connector *con = container_of(connector,
+ struct via_connector, base);
+ int count = 0;
+ struct i2c_adapter *i2c_bus;
+ struct edid *edid = NULL;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (con->i2c_bus & VIA_I2C_BUS1) {
+ i2c_bus = via_find_ddc_bus(0x26);
+ } else if (con->i2c_bus & VIA_I2C_BUS2) {
+ i2c_bus = via_find_ddc_bus(0x31);
+ } else if (con->i2c_bus & VIA_I2C_BUS3) {
+ i2c_bus = via_find_ddc_bus(0x25);
+ } else if (con->i2c_bus & VIA_I2C_BUS4) {
+ i2c_bus = via_find_ddc_bus(0x2c);
+ } else if (con->i2c_bus & VIA_I2C_BUS5) {
+ i2c_bus = via_find_ddc_bus(0x3d);
+ } else {
+ i2c_bus = NULL;
+ goto exit;
+ }
+
+ edid = drm_get_edid(&con->base, i2c_bus);
+ if (edid) {
+ if (edid->input & DRM_EDID_INPUT_DIGITAL) {
+ drm_mode_connector_update_edid_property(connector, edid);
+ count = drm_add_edid_modes(connector, edid);
+ DRM_DEBUG_KMS("DVI EDID information was obtained.\n");
+ }
+
+ kfree(edid);
+ }
+
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return count;
+}
+
+static const struct drm_connector_helper_funcs openchrome_vt1632_drm_connector_helper_funcs = {
+ .mode_valid = openchrome_vt1632_mode_valid,
+ .get_modes = openchrome_vt1632_get_modes,
+ .best_encoder = via_best_encoder,
+};
+
+bool openchrome_vt1632_probe(struct i2c_adapter *i2c_bus)
+{
+ u8 buf;
+ u16 vendor_id, device_id, revision;
+ bool device_detected = false;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ via_i2c_readbytes(i2c_bus, 0x08, 0x00, &buf, 1);
+ vendor_id = buf;
+ via_i2c_readbytes(i2c_bus, 0x08, 0x01, &buf, 1);
+ vendor_id |= (buf << 8);
+ DRM_DEBUG_KMS("Vendor ID: %x\n", vendor_id);
+ via_i2c_readbytes(i2c_bus, 0x08, 0x02, &buf, 1);
+ device_id = buf;
+ via_i2c_readbytes(i2c_bus, 0x08, 0x03, &buf, 1);
+ device_id |= (buf << 8);
+ DRM_DEBUG_KMS("Device ID: %x\n", device_id);
+ via_i2c_readbytes(i2c_bus, 0x08, 0x04, &buf, 1);
+ revision = buf;
+ DRM_DEBUG_KMS("Revision: %x\n", revision);
+
+ if ((vendor_id != 0x1106) || (device_id != 0x3192)) {
+ goto exit;
+ }
+
+ device_detected = true;
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return device_detected;
+}
+
+void openchrome_vt1632_init(struct drm_device *dev)
+{
+ struct via_connector *con;
+ struct via_encoder *enc;
+ struct via_device *dev_priv = dev->dev_private;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (!dev_priv->ext_tmds_presence) {
+ goto exit;
+ }
+
+ enc = kzalloc(sizeof(*enc) + sizeof(*con), GFP_KERNEL);
+ if (!enc) {
+ DRM_ERROR("Failed to allocate connector "
+ "and encoder.\n");
+ goto exit;
+ }
+
+ drm_encoder_init(dev, &enc->base, &openchrome_vt1632_drm_encoder_funcs,
+ DRM_MODE_ENCODER_TMDS, NULL);
+ drm_encoder_helper_add(&enc->base, &openchrome_vt1632_drm_encoder_helper_funcs);
+
+ enc->base.possible_crtcs = BIT(1) | BIT(0);
+ enc->base.possible_clones = 0;
+
+ enc->i2c_bus = dev_priv->ext_tmds_i2c_bus;
+ enc->di_port = dev_priv->ext_tmds_di_port;
+
+ /* Increment the number of DVI connectors. */
+ dev_priv->number_dvi++;
+
+
+ con = &enc->cons[0];
+
+ drm_connector_init(dev, &con->base, &openchrome_vt1632_drm_connector_funcs,
+ DRM_MODE_CONNECTOR_DVID);
+ drm_connector_helper_add(&con->base, &openchrome_vt1632_drm_connector_helper_funcs);
+ drm_connector_register(&con->base);
+
+ con->base.doublescan_allowed = false;
+ con->base.interlace_allowed = false;
+
+ con->i2c_bus = dev_priv->ext_tmds_i2c_bus;
+
+ INIT_LIST_HEAD(&con->props);
+ drm_mode_connector_attach_encoder(&con->base, &enc->base);
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
More information about the openchrome-devel
mailing list