From 97900e1e7eb3257a037ce5cfc3544787295685d9 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 13:26:28 +1300 Subject: [PATCH] Support reloading i2c-designware module(s) after resuming --- dell/xps/13-9300/default.nix | 4 ++ .../sleep-resume/i2c-designware/default.nix | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 dell/xps/sleep-resume/i2c-designware/default.nix diff --git a/dell/xps/13-9300/default.nix b/dell/xps/13-9300/default.nix index 6ec94ea..9c379ae 100644 --- a/dell/xps/13-9300/default.nix +++ b/dell/xps/13-9300/default.nix @@ -10,6 +10,7 @@ in { ../../../common/pc/laptop ../../../common/pc/laptop/acpi_call.nix ../../../common/pc/ssd + ../sleep-resume/i2c-designware ]; # Force S3 sleep mode. See README.wiki for details. @@ -26,4 +27,7 @@ in { # This will save you money and possibly your life! services.thermald.enable = mkDefault true; + + # Reloads i2c-designware module after suspend + services.sleep-resume.i2c-designware.enable = mkDefault true; } diff --git a/dell/xps/sleep-resume/i2c-designware/default.nix b/dell/xps/sleep-resume/i2c-designware/default.nix new file mode 100644 index 0000000..55be549 --- /dev/null +++ b/dell/xps/sleep-resume/i2c-designware/default.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkIf mkOption types; + + reloadDesignware = pkgs.writeShellApplication { + name = "reload-i2c-designware.sh"; + runtimeInputs = [ pkgs.kmod ]; + text = '' + # Reload the i2c Designware driver after resuming from sleep. + + # Wait up-to 0.5 second for each module to be unloaded: + # (It should never take this long) + modprobe -r --wait 500 i2c_designware_platform + modprobe -r --wait 500 i2c_designware_core + modprobe -r --wait 500 i2c_hid_acpi + modprobe -r --wait 500 i2c_hid + + # Should reload the module dependencies automatically: + modprobe i2c_designware_platform + ''; + }; + + cfg = config.services.sleep-resume.i2c-designware; +in { + options = { + services.sleep-resume.i2c-designware = { + enable = mkOption { + default = false; + type = types.bool; + description = "Reload the i2c_designware driver after resuming from sleep."; + }; + }; + }; + + config = mkIf cfg.enable { + powerManagement.resumeCommands = "${reloadDesignware}/bin/reload-i2c-designware.sh"; + }; +} + + +