Created
November 4, 2015 18:42
-
-
Save firetech/831ca1ea11c6fba4864f to your computer and use it in GitHub Desktop.
bbswitch hack to turn off dGPU before suspend instead (for Clevo laptops where the dGPU remains on and overheating during suspend)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- bbswitch-0.8.orig/bbswitch.c | |
+++ bbswitch-0.8/bbswitch.c | |
@@ -238,10 +238,15 @@ static int is_card_disabled(void) { | |
return !~cfg_word; | |
} | |
+static void bbswitch_off_force(void); | |
static void bbswitch_off(void) { | |
if (is_card_disabled()) | |
return; | |
+ bbswitch_off_force(); | |
+} | |
+ | |
+static void bbswitch_off_force(void) { | |
// to prevent the system from possibly locking up, don't disable the device | |
// if it's still in use by a driver (i.e. nouveau or nvidia) | |
if (dis_dev->driver) { | |
@@ -280,10 +285,15 @@ static void bbswitch_off(void) { | |
pr_warn("The discrete card could not be disabled by a _DSM call\n"); | |
} | |
+static void bbswitch_on_force(void); | |
static void bbswitch_on(void) { | |
if (!is_card_disabled()) | |
return; | |
+ bbswitch_on_force(); | |
+} | |
+ | |
+static void bbswitch_on_force(void) { | |
pr_info("enabling discrete graphics\n"); | |
if (bbswitch_acpi_on()) | |
@@ -351,8 +361,8 @@ static int bbswitch_pm_handler(struct no | |
dis_before_suspend_disabled = is_card_disabled(); | |
// enable the device before suspend to avoid the PCI config space from | |
// being saved incorrectly | |
- if (dis_before_suspend_disabled) | |
- bbswitch_on(); | |
+ if (!dis_before_suspend_disabled) | |
+ bbswitch_off(); | |
dis_dev_put(); | |
break; | |
case PM_POST_HIBERNATION: | |
@@ -360,11 +370,12 @@ static int bbswitch_pm_handler(struct no | |
case PM_POST_RESTORE: | |
// after suspend, the card is on, but if it was off before suspend, | |
// disable it again | |
- if (dis_before_suspend_disabled) { | |
- dis_dev_get(); | |
- bbswitch_off(); | |
- dis_dev_put(); | |
- } | |
+ dis_dev_get(); | |
+ pr_info("resumed\n"); | |
+ bbswitch_off_force(); | |
+ if (!dis_before_suspend_disabled) | |
+ bbswitch_on(); | |
+ dis_dev_put(); | |
break; | |
case PM_RESTORE_PREPARE: | |
// deliberately don't do anything as it does not occur before suspend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment