mirror of
				https://github.com/NixOS/nixos-hardware.git
				synced 2025-11-04 09:17:14 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
{ 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";
 | 
						|
  };
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 |