Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

framework: refactor kmod for improved AMD support #1029

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ For the Framework 13 laptops, there are common configuration modules available u
including some modules specific to AMD- or Intel-based laptops. By preference, there will already be a specialised
module for your model's configuration. Otherwise, it can be added alongside the existing modules.

## OS integration

`hardware.framework.enableKmod` enables the [community-created Framework kernel
module](https://github.com/DHowett/framework-laptop-kmod) which exposes EC functionality like battery charge limit,
privacy switches, and system LEDs as standard driver interfaces. This enables, for example, configuring the charge limit
using the KDE settings GUI. The option is enabled by default when NixOS `>= 24.05` and linux kernel version `>= 6.10`.

On AMD Framework 13 and 16, before kernel 6.10, additional kernel patches are required for the kernel module to function
properly. Manually setting `hardware.framework.enableKmod = true` will apply the patches, requiring a kernel
recompilation.

## Support Tools

### fw-ectool
Expand Down
43 changes: 34 additions & 9 deletions framework/kmod.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
{ config, lib, ... }:
{
options.hardware.framework.enableKmod = lib.mkEnableOption
{ config, lib, pkgs, ... }:
let
kernel_version_compatible = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.10";
Mic92 marked this conversation as resolved.
Show resolved Hide resolved
in {
options.hardware.framework.enableKmod = (lib.mkEnableOption
"Enable the community created Framework kernel module that allows interacting with the embedded controller from sysfs."
// {
# Enable by default if on new enough version of NixOS
default = (lib.versionAtLeast (lib.versions.majorMinor lib.version) "24.05");
) // {
# enable by default on NixOS >= 24.05 and kernel >= 6.10
default = lib.and
(lib.versionAtLeast (lib.versions.majorMinor lib.version) "24.05")
kernel_version_compatible;
};

config = lib.mkIf config.hardware.framework.enableKmod {
boot.extraModulePackages = with config.boot.kernelPackages; [

config.boot = lib.mkIf config.hardware.framework.enableKmod {
extraModulePackages = with config.boot.kernelPackages; [
framework-laptop-kmod
];

# https://github.com/DHowett/framework-laptop-kmod?tab=readme-ov-file#usage
boot.kernelModules = [ "cros_ec" "cros_ec_lpcs" ];
kernelModules = [ "cros_ec" "cros_ec_lpcs" ];

# add required patch if enabled on kernel <6.10
kernelPatches = lib.mkIf (!kernel_version_compatible) [
Mic92 marked this conversation as resolved.
Show resolved Hide resolved
rec {
name = "platform/chrome: cros_ec_lpc: add support for AMD Framework Laptops";
msgid = "[email protected]";
version = "3";
hash = "sha256-aQSyys8CMzlj9EdNhg8vtp76fg1qEwUVeJL0E+8w5HU=";
patch = pkgs.runCommandLocal "patch-${msgid}" {
nativeBuildInputs = with pkgs; [ b4 git cacert ];
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";

outputHash = hash;
} ''
export HOME="$TMP"
PYTHONHASHSEED=0 ${pkgs.b4}/bin/b4 -n am -C -T -v ${version} -o- "${msgid}" > "$out"
'';
}
];
};
}