[Openchrome-devel] drm-openchrome: drivers/gpu/drm
James Simmons
jsimmons at kemper.freedesktop.org
Fri Mar 29 08:09:38 PDT 2013
drivers/gpu/drm/via/Makefile | 2
drivers/gpu/drm/via/via_display.c | 21 +++-
drivers/gpu/drm/via/via_display.h | 1
drivers/gpu/drm/via/via_drv.c | 17 ++-
drivers/gpu/drm/via/via_drv.h | 17 +++
drivers/gpu/drm/via/via_tmds.c | 187 ++++++++++++++++++++++++++++++++++++++
6 files changed, 236 insertions(+), 9 deletions(-)
New commits:
commit 74bdda2f1dc9ed70713ded0f563852a34cc05bed
Author: James Simmons <jsimmons at infradead.org>
Date: Fri Mar 29 10:59:46 2013 -0400
Add support for DVI for platforms without a HDMI encoder
diff --git a/drivers/gpu/drm/via/Makefile b/drivers/gpu/drm/via/Makefile
index 62f4fc7..3d6e2e7 100644
--- a/drivers/gpu/drm/via/Makefile
+++ b/drivers/gpu/drm/via/Makefile
@@ -7,6 +7,6 @@ via-y := via_drv.o via_pm.o via_i2c.o via_irq.o via_verifier.o via_ioc32.o \
init_ttm.o ttm_gem.o via_ttm.o via_fence.o via_sgdma.o \
via_h1_dma.o via_h1_cmdbuf.o via_video.o \
via_display.o via_crtc.o via_fb.o crtc_hw.o via_clocks.o \
- via_analog.o via_lvds.o via_hdmi.o
+ via_analog.o via_lvds.o via_tmds.o via_hdmi.o
obj-$(CONFIG_DRM_VIA) += via.o
diff --git a/drivers/gpu/drm/via/via_display.c b/drivers/gpu/drm/via/via_display.c
index 2533698..8be5eb2 100644
--- a/drivers/gpu/drm/via/via_display.c
+++ b/drivers/gpu/drm/via/via_display.c
@@ -536,12 +536,23 @@ via_modeset_init(struct drm_device *dev)
via_lvds_init(dev);
- if ((dev->pdev->device != PCI_DEVICE_ID_VIA_CLE266) ||
- (dev->pdev->device != PCI_DEVICE_ID_VIA_KM400) ||
- (dev->pdev->device != PCI_DEVICE_ID_VIA_K8M800) ||
- (dev->pdev->device != PCI_DEVICE_ID_VIA_PM800) ||
- (dev->pdev->device != PCI_DEVICE_ID_VIA_CN700))
+ switch (dev->pdev->device) {
+ /* CX700 can support HDMI and non HDMI based DVI ports */
+ case PCI_DEVICE_ID_VIA_VT3157:
+ if (!via_tmds_init(dev))
+ break;
+
+ /* Newer platforms use HDMI encoder */
+ case PCI_DEVICE_ID_VIA_VT1122:
+ case PCI_DEVICE_ID_VIA_VX875:
+ case PCI_DEVICE_ID_VIA_VX900:
via_hdmi_init(dev, DISP_DI_NONE);
+ break;
+
+ default:
+ via_tmds_init(dev);
+ break;
+ }
/*
* Set up the framebuffer device
diff --git a/drivers/gpu/drm/via/via_display.h b/drivers/gpu/drm/via/via_display.h
index a54a3fb..a4da6c8 100644
--- a/drivers/gpu/drm/via/via_display.h
+++ b/drivers/gpu/drm/via/via_display.h
@@ -166,5 +166,6 @@ extern int via_get_edid_modes(struct drm_connector *connector);
extern void via_hdmi_init(struct drm_device *dev, int diPort);
extern void via_analog_init(struct drm_device *dev);
extern void via_lvds_init(struct drm_device *dev);
+extern int via_tmds_init(struct drm_device *dev);
#endif
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index 68b38b4..36fb3eb 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -173,8 +173,9 @@ chip_revision_info(struct drm_device *dev)
struct drm_via_private *dev_priv = dev->dev_private;
u8 tmp;
+ switch (dev->pci_device) {
/* Check revision of CLE266 Chip */
- if (dev->pdev->device == PCI_DEVICE_ID_VIA_CLE266) {
+ case PCI_DEVICE_ID_VIA_CLE266:
/* CR4F only define in CLE266.CX chip */
tmp = vga_rcrt(VGABASE, 0x4F);
vga_wcrt(VGABASE, 0x4F, 0x55);
@@ -184,9 +185,9 @@ chip_revision_info(struct drm_device *dev)
dev_priv->revision = CLE266_REVISION_CX;
/* restore orignal CR4F value */
vga_wcrt(VGABASE, 0x4F, tmp);
- }
+ break;
- if (dev->pdev->device == PCI_DEVICE_ID_VIA_VT3157) {
+ case PCI_DEVICE_ID_VIA_VT3157:
tmp = vga_rseq(VGABASE, 0x43);
if (tmp & 0x02) {
dev_priv->revision = CX700_REVISION_700M2;
@@ -195,6 +196,16 @@ chip_revision_info(struct drm_device *dev)
} else {
dev_priv->revision = CX700_REVISION_700;
}
+ break;
+
+ case PCI_DEVICE_ID_VIA_VT1122:
+ case PCI_DEVICE_ID_VIA_VX875:
+ case PCI_DEVICE_ID_VIA_VX900:
+ dev_priv->revision = vga_rseq(VGABASE, 0x3B);
+ break;
+
+ default:
+ break;
}
}
diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
index 1d3b86de..c39352d 100644
--- a/drivers/gpu/drm/via/via_drv.h
+++ b/drivers/gpu/drm/via/via_drv.h
@@ -65,6 +65,23 @@
#define CX700_REVISION_700M 0x1
#define CX700_REVISION_700M2 0x2
+/* For VT3353 */
+#define VX800_REVISION_A 0x0f
+#define VX800_REVISION_B0 0x10
+#define VX800_REVISION_B1 0x11
+#define VX800_REVISION_B2 0x12
+
+/* For VT3409 */
+#define VX855_REVISION_A0 0x00
+#define VX855_REVISION_A1 0x01
+#define VX855_REVISION_A2 0x02
+
+/* For VT3410 */
+#define VX900_REVISION_A0 0x00
+#define VX900_REVISION_A1 0x01
+#define VX900_REVISION_A2 0x02
+#define VX900_REVISION_A3 0x03
+
typedef uint32_t maskarray_t[5];
typedef struct drm_via_irq {
diff --git a/drivers/gpu/drm/via/via_tmds.c b/drivers/gpu/drm/via/via_tmds.c
new file mode 100644
index 0000000..a906661
--- /dev/null
+++ b/drivers/gpu/drm/via/via_tmds.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright © 2013 James Simmons
+ *
+ * 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.
+ *
+ * Authors:
+ * James Simmons <jsimmons at infradead.org>
+ */
+#include "via_drv.h"
+
+/*
+ * Routines for controlling stuff on the TMDS port
+ */
+static const struct drm_encoder_funcs via_tmds_enc_funcs = {
+ .destroy = via_encoder_cleanup,
+};
+
+/* Manage the power state of the DAC */
+static void
+via_tmds_dpms(struct drm_encoder *encoder, int mode)
+{
+ struct drm_via_private *dev_priv = encoder->dev->dev_private;
+
+ switch (mode) {
+ case DRM_MODE_DPMS_SUSPEND:
+ case DRM_MODE_DPMS_STANDBY:
+ case DRM_MODE_DPMS_OFF:
+ svga_wcrt_mask(VGABASE, 0xD2, BIT(4), BIT(4));
+ svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(0));
+
+ /* Internal TMDS only use DFP_L */
+ /* Turn on DVI panel path(Only for internal),
+ * otherwise, the screen of DVI will be black. */
+ svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(7));
+ /* Power on TMDS */
+ svga_wcrt_mask(VGABASE, 0xD2, 0x00, BIT(3));
+ break;
+
+ case DRM_MODE_DPMS_ON:
+ default:
+ svga_wcrt_mask(VGABASE, 0x91, BIT(7), BIT(7));
+ /* Power off TMDS */
+ svga_wcrt_mask(VGABASE, 0xD2, BIT(3), BIT(3));
+ break;
+ }
+}
+
+/* Pass our mode to the connectors and the CRTC to give them a chance to
+ * adjust it according to limitations or connector properties, and also
+ * a chance to reject the mode entirely. Usefule for things like scaling.
+ */
+static bool
+via_tmds_mode_fixup(struct drm_encoder *encoder,
+ const struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode)
+{
+ drm_mode_set_crtcinfo(adjusted_mode, 0);
+ return true;
+}
+
+static const struct drm_encoder_helper_funcs via_tmds_enc_helper_funcs = {
+ .dpms = via_tmds_dpms,
+ .mode_fixup = via_tmds_mode_fixup,
+ .mode_set = via_set_sync_polarity,
+ .prepare = via_encoder_prepare,
+ .commit = via_encoder_commit,
+ .disable = via_encoder_disable,
+};
+
+static enum drm_connector_status
+via_dvi_detect(struct drm_connector *connector, bool force)
+{
+ struct via_connector *con = container_of(connector, struct via_connector, base);
+ enum drm_connector_status ret = connector_status_disconnected;
+ struct edid *edid = NULL;
+
+ drm_mode_connector_update_edid_property(connector, edid);
+ if (con->ddc_bus) {
+ edid = drm_get_edid(connector, con->ddc_bus);
+ if (edid) {
+ if ((connector->connector_type == DRM_MODE_CONNECTOR_DVIA) ^
+ (edid->input & DRM_EDID_INPUT_DIGITAL)) {
+ drm_mode_connector_update_edid_property(connector, edid);
+ ret = connector_status_connected;
+ }
+ kfree(edid);
+ }
+ }
+ return ret;
+}
+
+static const struct drm_connector_funcs via_dvi_connector_funcs = {
+ .dpms = drm_helper_connector_dpms,
+ .detect = via_dvi_detect,
+ .fill_modes = drm_helper_probe_single_connector_modes,
+ .set_property = via_connector_set_property,
+ .destroy = via_connector_destroy,
+};
+
+static const struct drm_connector_helper_funcs via_dvi_connector_helper_funcs = {
+ .mode_valid = via_connector_mode_valid,
+ .get_modes = via_get_edid_modes,
+ .best_encoder = via_best_encoder,
+};
+
+int
+via_tmds_init(struct drm_device *dev)
+{
+ struct drm_via_private *dev_priv = dev->dev_private;
+ struct via_connector *con;
+ struct via_encoder *enc;
+ int i2c_port = 0x3D;
+
+ if (!(vga_rseq(VGABASE, 0x3E) & BIT(5))) {
+ DRM_INFO("Internal DVI not detected\n");
+ return 1;
+ }
+
+ enc = kzalloc(sizeof(*enc) + 2 * sizeof(*con), GFP_KERNEL);
+ if (!enc) {
+ DRM_ERROR("Failed to allocate connector and encoder\n");
+ return -ENOMEM;
+ }
+
+ /* Setup the encoders and attach them */
+ drm_encoder_init(dev, &enc->base, &via_tmds_enc_funcs, DRM_MODE_ENCODER_DAC);
+ drm_encoder_helper_add(&enc->base, &via_tmds_enc_helper_funcs);
+
+ enc->base.possible_crtcs = BIT(1) | BIT(0);
+ enc->base.possible_clones = 0;
+ enc->diPort = DISP_DI_DFPL;
+
+ /* Piece together our DVI-D connector */
+ con = &enc->cons[0];
+ drm_connector_init(dev, &con->base, &via_dvi_connector_funcs,
+ DRM_MODE_CONNECTOR_DVID);
+ drm_connector_helper_add(&con->base, &via_dvi_connector_helper_funcs);
+ drm_sysfs_connector_add(&con->base);
+
+ switch (dev->pci_device) {
+ case PCI_DEVICE_ID_VIA_VT1122:
+ if (dev_priv->revision < VX800_REVISION_B1)
+ break;
+
+ case PCI_DEVICE_ID_VIA_VX875:
+ case PCI_DEVICE_ID_VIA_VX900:
+ i2c_port = 0x31;
+ break;
+ default:
+ break;
+ }
+ con->ddc_bus = via_find_ddc_bus(i2c_port);
+ con->base.doublescan_allowed = false;
+ con->base.interlace_allowed = true;
+
+ drm_mode_connector_attach_encoder(&con->base, &enc->base);
+
+ /* Now handle the DVI-A case */
+ con = &enc->cons[1];
+ drm_connector_init(dev, &con->base, &via_dvi_connector_funcs,
+ DRM_MODE_CONNECTOR_DVIA);
+ drm_connector_helper_add(&con->base, &via_dvi_connector_helper_funcs);
+ drm_sysfs_connector_add(&con->base);
+ con->ddc_bus = via_find_ddc_bus(i2c_port);
+ con->base.doublescan_allowed = false;
+ con->base.interlace_allowed = true;
+
+ drm_mode_connector_attach_encoder(&con->base, &enc->base);
+ return 0;
+}
More information about the Openchrome-devel
mailing list