summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linux-core/Makefile.kernel4
-rw-r--r--linux-core/drmP.h11
-rw-r--r--linux-core/drm_drv.c6
-rw-r--r--linux-core/drm_pm.c126
-rw-r--r--linux-core/drm_stub.c2
-rw-r--r--linux-core/i915_drv.c3
-rw-r--r--shared-core/i915_drv.h5
-rw-r--r--shared-core/i915_pm.c140
8 files changed, 295 insertions, 2 deletions
diff --git a/linux-core/Makefile.kernel b/linux-core/Makefile.kernel
index 93082355..40a5f5a0 100644
--- a/linux-core/Makefile.kernel
+++ b/linux-core/Makefile.kernel
@@ -10,14 +10,14 @@
drm-objs := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
- drm_sysfs.o drm_pci.o drm_agpsupport.o drm_scatter.o \
+ drm_sysfs.o drm_pci.o drm_pm.o drm_agpsupport.o drm_scatter.o \
drm_memory_debug.o ati_pcigart.o
tdfx-objs := tdfx_drv.o
r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o
mga-objs := mga_drv.o mga_dma.o mga_state.o mga_warp.o mga_irq.o
i810-objs := i810_drv.o i810_dma.o
i830-objs := i830_drv.o i830_dma.o i830_irq.o
-i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o
+i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o i915_pm.o
radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o radeon_i2c.o
sis-objs := sis_drv.o sis_ds.o sis_mm.o
ffb-objs := ffb_drv.o ffb_context.o
diff --git a/linux-core/drmP.h b/linux-core/drmP.h
index 24d8a23b..d7a19a2a 100644
--- a/linux-core/drmP.h
+++ b/linux-core/drmP.h
@@ -80,6 +80,7 @@
#endif
#include <linux/poll.h>
#include <asm/pgalloc.h>
+#include <linux/sysdev.h>
#include "drm.h"
#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
@@ -541,6 +542,7 @@ struct drm_driver {
int new);
int (*kernel_context_switch_unlock) (struct drm_device * dev);
int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
+ int (*power) (struct drm_device * dev, unsigned int state);
/**
* Called by \c drm_device_is_agp. Typically used to determine if a
@@ -720,6 +722,9 @@ typedef struct drm_device {
struct drm_driver *driver;
drm_local_map_t *agp_buffer_map;
drm_head_t primary; /**< primary screen head */
+
+ struct sys_device sysdev; /**< Power Management device structure */
+ int sysdev_registered; /**< Whether the device has been registered */
} drm_device_t;
static __inline__ int drm_core_check_feature(struct drm_device *dev,
@@ -896,6 +901,12 @@ extern unsigned long drm_get_resource_start(drm_device_t *dev,
extern unsigned long drm_get_resource_len(drm_device_t *dev,
unsigned int resource);
+ /* Power Management (drm_pm.h) */
+extern int drm_pm_setup(drm_device_t *dev);
+extern void drm_pm_takedown(drm_device_t *dev);
+extern int drm_pm_init(void);
+extern void drm_pm_cleanup(void);
+
/* DMA support (drm_dma.h) */
extern int drm_dma_setup(drm_device_t * dev);
extern void drm_dma_takedown(drm_device_t * dev);
diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c
index 069ecd3e..192b05cd 100644
--- a/linux-core/drm_drv.c
+++ b/linux-core/drm_drv.c
@@ -265,6 +265,8 @@ int drm_takedown(drm_device_t * dev)
if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
drm_dma_takedown(dev);
+ drm_pm_takedown(dev);
+
if (dev->lock.hw_lock) {
dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */
dev->lock.filp = NULL;
@@ -310,6 +312,8 @@ int drm_init(struct drm_driver *driver,
drm_mem_init();
+ drm_pm_init();
+
for (i = 0; (pciidlist[i].vendor != 0) && !drm_fb_loaded; i++) {
pid = &pciidlist[i];
@@ -439,6 +443,8 @@ static void __exit drm_cleanup(drm_device_t * dev)
if (dev->driver->postcleanup)
dev->driver->postcleanup(dev);
+ drm_pm_cleanup();
+
drm_put_head(&dev->primary);
if (drm_put_dev(dev))
DRM_ERROR("Cannot unload module\n");
diff --git a/linux-core/drm_pm.c b/linux-core/drm_pm.c
new file mode 100644
index 00000000..ea801bda
--- /dev/null
+++ b/linux-core/drm_pm.c
@@ -0,0 +1,126 @@
+/**
+ * \file drm_pm.h
+ * Power management support
+ *
+ * \author José Fonseca <jrfonseca@tungstengraphics.com>
+ */
+
+/*
+ * Copyright 2004 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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
+ * TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ */
+
+#define __NO_VERSION__
+#include "drmP.h"
+
+
+#include <linux/device.h>
+#include <linux/sysdev.h>
+
+static int drm_suspend(struct sys_device *sysdev, u32 state)
+{
+ drm_device_t *dev = (drm_device_t *)sysdev;
+
+ DRM_DEBUG("%s state=%d\n", __FUNCTION__, state);
+
+ if (dev->driver->power)
+ return dev->driver->power(dev, state);
+ else
+ return 0;
+}
+
+static int drm_resume(struct sys_device *sysdev)
+{
+ drm_device_t *dev = (drm_device_t *)sysdev;
+
+ DRM_DEBUG("%s\n", __FUNCTION__);
+
+ if (dev->driver->power)
+ return dev->driver->power(dev, 0);
+ else
+ return 0;
+}
+
+static struct sysdev_class drm_sysdev_class = {
+ set_kset_name("drm"),
+ .resume = drm_resume,
+ .suspend = drm_suspend,
+};
+
+
+/**
+ * Initialize the Power Management data.
+ *
+ * \param dev DRM device.
+ * \return zero on success or a negative value on failure.
+ */
+int drm_pm_setup(drm_device_t *dev)
+{
+ int error;
+
+ DRM_DEBUG("%s\n", __FUNCTION__);
+
+ dev->sysdev.id = dev->primary.minor;
+ dev->sysdev.cls = &drm_sysdev_class;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
+ error = sys_device_register(&dev->sysdev);
+#else
+ error = sysdev_register(&dev->sysdev);
+#endif
+ if(!error)
+ dev->sysdev_registered = 1;
+ return error;
+}
+
+/**
+ * Cleanup the Power Management resources.
+ *
+ * \param dev DRM device.
+ */
+void drm_pm_takedown(drm_device_t *dev)
+{
+ DRM_DEBUG("%s\n", __FUNCTION__);
+
+ if(dev->sysdev_registered) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
+ sys_device_unregister(&dev->sysdev);
+#else
+ sysdev_unregister(&dev->sysdev);
+#endif
+ dev->sysdev_registered = 0;
+ }
+}
+
+int drm_pm_init(void)
+{
+ DRM_DEBUG("%s\n", __FUNCTION__);
+
+ return sysdev_class_register(&drm_sysdev_class);
+}
+
+void drm_pm_cleanup(void)
+{
+ DRM_DEBUG("%s\n", __FUNCTION__);
+
+ sysdev_class_unregister(&drm_sysdev_class);
+}
diff --git a/linux-core/drm_stub.c b/linux-core/drm_stub.c
index 338996d6..af080c2d 100644
--- a/linux-core/drm_stub.c
+++ b/linux-core/drm_stub.c
@@ -67,6 +67,8 @@ static int fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,
dev->pdev = pdev;
+ drm_pm_setup( dev );
+
#ifdef __alpha__
dev->hose = pdev->sysdata;
dev->pci_domain = dev->hose->bus->number;
diff --git a/linux-core/i915_drv.c b/linux-core/i915_drv.c
index d09b9d43..51bea892 100644
--- a/linux-core/i915_drv.c
+++ b/linux-core/i915_drv.c
@@ -71,6 +71,7 @@ static struct drm_driver driver = {
.postinit = postinit,
.version = version,
.ioctls = i915_ioctls,
+ .power = i915_power,
.fops = {
.owner = THIS_MODULE,
.open = drm_open,
@@ -84,6 +85,8 @@ static struct drm_driver driver = {
.name = DRIVER_NAME,
.id_table = pciidlist,
.probe = probe,
+ .resume = i915_resume,
+ .suspend = i915_suspend,
.remove = __devexit_p(drm_cleanup_pci),
}
};
diff --git a/shared-core/i915_drv.h b/shared-core/i915_drv.h
index 75480c16..8024d829 100644
--- a/shared-core/i915_drv.h
+++ b/shared-core/i915_drv.h
@@ -91,6 +91,11 @@ extern void i915_driver_irq_preinstall(drm_device_t * dev);
extern void i915_driver_irq_postinstall(drm_device_t * dev);
extern void i915_driver_irq_uninstall(drm_device_t * dev);
+/* i915_pm.c */
+extern int i915_suspend(struct pci_dev *pdev, u32 state);
+extern int i915_resume(struct pci_dev *pdev);
+extern int i915_power(drm_device_t *dev, unsigned int state);
+
/* i915_mem.c */
extern int i915_mem_alloc(DRM_IOCTL_ARGS);
extern int i915_mem_free(DRM_IOCTL_ARGS);
diff --git a/shared-core/i915_pm.c b/shared-core/i915_pm.c
new file mode 100644
index 00000000..17451319
--- /dev/null
+++ b/shared-core/i915_pm.c
@@ -0,0 +1,140 @@
+/* i915_pm.c -- Power management support for the i915 -*- linux-c -*-
+ */
+/**************************************************************************
+ *
+ * Copyright 2004 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+#define __NO_VERSION__
+#include "drmP.h"
+#include "drm.h"
+#include "i915_drm.h"
+#include "i915_drv.h"
+
+
+/**
+ * Set DPMS mode.
+ */
+static int i915_set_dpms(drm_device_t *dev, int mode)
+{
+ drm_i915_private_t *dev_priv =
+ (drm_i915_private_t *)dev->dev_private;
+ unsigned sr01, adpa, ppcr, dvob, dvoc, lvds;
+
+ DRM_DEBUG("%s mode=%d\n", __FUNCTION__, mode);
+
+ I915_WRITE( SRX_INDEX, SR01 );
+ sr01 = I915_READ( SRX_DATA );
+
+ adpa = I915_READ( ADPA );
+ ppcr = I915_READ( PPCR );
+ dvoc = I915_READ( DVOC );
+ dvob = I915_READ( DVOB );
+ lvds = I915_READ( LVDS );
+
+ switch(mode) {
+ case 0:
+ /* On */
+ sr01 &= ~SR01_SCREEN_OFF;
+ adpa = (adpa & ADPA_DPMS_MASK) | ADPA_DPMS_ON;
+#if 0
+ I915_WRITE( LVDS, lvds | LVDS_ON ); /* Power on LVDS */
+#endif
+ I915_WRITE( PPCR, dev_priv->ppcr ); /* Power up panel */
+ I915_WRITE( DVOC, dev_priv->dvoc );
+ I915_WRITE( DVOB, dev_priv->dvob );
+ break;
+
+ case 1:
+ /* Standby */
+ sr01 |= SR01_SCREEN_OFF;
+ adpa = (adpa & ADPA_DPMS_MASK) | ADPA_DPMS_STANDBY;
+ I915_WRITE( PPCR, ppcr & ~PPCR_ON ); /* Power off panel*/
+#if 0
+ I915_WRITE( LVDS, lvds & ~LVDS_ON ); /* Power off LVDS */
+#endif
+ I915_WRITE( DVOC, dvoc & ~DVOC_ON );
+ I915_WRITE( DVOB, dvob & ~DVOB_ON );
+ break;
+
+ case 2:
+ /* Suspend */
+ sr01 |= SR01_SCREEN_OFF;
+ adpa = (adpa & ADPA_DPMS_MASK) | ADPA_DPMS_SUSPEND;
+ I915_WRITE( PPCR, ppcr & ~PPCR_ON ); /* Power off panel*/
+#if 0
+ I915_WRITE( LVDS, lvds & ~LVDS_ON ); /* Power off LVDS */
+#endif
+ I915_WRITE( DVOC, dvoc & ~DVOC_ON );
+ I915_WRITE( DVOB, dvob & ~DVOB_ON );
+ break;
+
+ case 3:
+ /* Off */
+ sr01 |= SR01_SCREEN_OFF;
+ adpa = (adpa & ADPA_DPMS_MASK) | ADPA_DPMS_OFF;
+ I915_WRITE( PPCR, ppcr & ~PPCR_ON ); /* Power off panel*/
+#if 0
+ I915_WRITE( LVDS, lvds & ~LVDS_ON ); /* Power off LVDS */
+#endif
+ I915_WRITE( DVOC, dvoc & ~DVOC_ON );
+ I915_WRITE( DVOB, dvob & ~DVOB_ON );
+ break;
+ }
+
+ I915_WRITE( SRX_DATA, sr01 );
+
+ I915_WRITE( ADPA, adpa );
+
+ return 0;
+}
+
+int i915_suspend( struct pci_dev *pdev, unsigned state )
+{
+ drm_device_t *dev = (drm_device_t *)pci_get_drvdata(pdev);
+
+ DRM_DEBUG("%s state=%d\n", __FUNCTION__, state);
+
+ switch(state) {
+ case 0:
+ /* D0: set DPMS mode on */
+ i915_set_dpms(dev, 0);
+ break;
+ case 1:
+ /* D1: set DPMS mode standby */
+ i915_set_dpms(dev, 1);
+ break;
+ case 2:
+ /* D2: set DPMS mode suspend */
+ i915_set_dpms(dev, 2);
+ break;
+ case 3:
+ /* D3: set DPMS mode off */
+ i915_set_dpms(dev, 3);
+ break;
+ }
+
+ return 0;
+}
+
+int i915_resume( struct pci_dev *pdev )
+{
+ drm_device_t *dev = (drm_device_t *)pci_get_drvdata(pdev);
+
+ /* D0: set DPMS mode on */
+ i915_set_dpms(dev, 0);
+
+ return 0;
+}
+
+int i915_power( drm_device_t *dev, unsigned int state )
+{
+ DRM_DEBUG("%s state=%d\n", __FUNCTION__, state);
+
+ /* D0: set DPMS mode on */
+ i915_set_dpms(dev, state);
+
+ return 0;
+}