@@ -604,6 +604,8 @@ driver = {
.dumb_map_offset = nouveau_display_dumb_map_offset,
.dumb_destroy = nouveau_display_dumb_destroy,
+ .dynamic_off_check = nouveau_dynamic_power_check,
+ .dynamic_set_state = nouveau_dynamic_power_set_state,
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
#ifdef GIT_REVISION
@@ -148,4 +148,7 @@ int nouveau_drm_resume(struct pci_dev *);
NV_PRINTK(KERN_DEBUG, "D", drm, fmt, ##args); \
} while (0)
+bool nouveau_dynamic_power_check(struct drm_device *dev);
+int nouveau_dynamic_power_set_state(struct drm_device *dev, int state);
+
#endif
@@ -28,12 +28,12 @@
#include <linux/power_supply.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
-
+#include <linux/vga_switcheroo.h>
#include "drmP.h"
-
+#include "drm_crtc_helper.h"
#include "nouveau_drm.h"
#include "nouveau_pm.h"
-
+#include "nouveau_acpi.h"
#include <subdev/bios/gpio.h>
#include <subdev/gpio.h>
#include <subdev/timer.h>
@@ -962,6 +962,7 @@ nouveau_pm_init(struct drm_device *dev)
register_acpi_notifier(&pm->acpi_nb);
#endif
+ drm_dynamic_power_init(dev);
return 0;
}
@@ -1007,3 +1008,53 @@ nouveau_pm_resume(struct drm_device *dev)
nouveau_pm_perflvl_set(dev, perflvl);
nouveau_pwmfan_set(dev, pm->fan.percent);
}
+
+/* rules for what we want
+ if we are an optimus laptop,
+ with no active crtc/encoders/connectors
+ with no channel activity for 4-5s
+*/
+
+bool nouveau_dynamic_power_check(struct drm_device *dev)
+{
+ struct nouveau_drm *drm = nouveau_drm(dev);
+ struct drm_crtc *crtc;
+
+ /* are we optimus enabled? */
+ if (!nouveau_is_optimus()) {
+ DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
+ return false;
+ }
+
+ list_for_each_entry(crtc, &drm->dev->mode_config.crtc_list, head) {
+ if (crtc->enabled) {
+ DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+ return false;
+ }
+ }
+ return true;
+}
+
+int nouveau_dynamic_power_set_state(struct drm_device *dev, int state)
+{
+ struct nouveau_drm *drm = nouveau_drm(dev);
+ pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
+
+ if (state == DRM_SWITCH_POWER_DYNAMIC_OFF) {
+ dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
+ drm_kms_helper_poll_disable(drm->dev);
+ vga_switcheroo_set_dynamic_switch(dev->pdev, VGA_SWITCHEROO_OFF, false);
+ nouveau_switcheroo_optimus_dsm();
+ nouveau_drm_suspend(drm->dev->pdev, pmm);
+ vga_switcheroo_set_dynamic_switch(dev->pdev, VGA_SWITCHEROO_OFF, true);
+ } else if (state == DRM_SWITCH_POWER_ON) {
+ vga_switcheroo_set_dynamic_switch(dev->pdev, VGA_SWITCHEROO_ON, true);
+ nouveau_drm_resume(dev->pdev);
+ vga_switcheroo_set_dynamic_switch(dev->pdev, VGA_SWITCHEROO_ON, false);
+ drm_kms_helper_poll_enable(dev);
+ dev->switch_power_state = DRM_SWITCH_POWER_ON;
+ }
+
+ return 0;
+}
+
@@ -33,6 +33,8 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
struct drm_device *dev = pci_get_drvdata(pdev);
pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
+ if (nouveau_is_optimus() && state == VGA_SWITCHEROO_OFF)
+ return;
if (state == VGA_SWITCHEROO_ON) {
printk(KERN_ERR "VGA switcheroo: switched nouveau on\n");
dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
@@ -80,7 +82,7 @@ nouveau_vga_init(struct nouveau_drm *drm)
{
struct drm_device *dev = drm->dev;
vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
- vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, false);
+ vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, nouveau_is_optimus());
}
void