1
0
Fork 0
mirror of https://github.com/NixOS/nixos-hardware synced 2024-11-30 06:49:43 +01:00

Merge pull request #440 from carlossless/raspberry-pi-4-i2c-frequency

raspberry-pi-4: add i2c clock-frequency option
This commit is contained in:
Jörg Thalheim 2022-08-13 17:11:59 +01:00 committed by GitHub
commit 12620020f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,8 @@
let let
cfg = config.hardware.raspberry-pi."4"; cfg = config.hardware.raspberry-pi."4";
simple-overlay = { target, status }: { optionalProperty = name: value: lib.optionalString (value != null) "${name} = <${builtins.toString value}>;";
simple-overlay = { target, status, frequency }: {
name = "${target}-${status}-overlay"; name = "${target}-${status}-overlay";
dtsText = '' dtsText = ''
/dts-v1/; /dts-v1/;
@ -13,6 +14,7 @@ let
target = <&${target}>; target = <&${target}>;
__overlay__ { __overlay__ {
status = "${status}"; status = "${status}";
${optionalProperty "clock-frequency" frequency}
}; };
}; };
}; };
@ -21,26 +23,52 @@ let
in in
{ {
options.hardware.raspberry-pi."4" = { options.hardware.raspberry-pi."4" = {
i2c0.enable = lib.mkEnableOption '' i2c0 = {
Turn on the VideoCore I2C bus (maps to /dev/i2c-22) and enable access from the i2c group. enable = lib.mkEnableOption ''
After a reboot, i2c-tools (e.g. i2cdetect -F 22) should work for root or any user in i2c. Turn on the VideoCore I2C bus (maps to /dev/i2c-22) and enable access from the i2c group.
''; After a reboot, i2c-tools (e.g. i2cdetect -F 22) should work for root or any user in i2c.
i2c1.enable = lib.mkEnableOption '' '';
Turn on the ARM I2C bus (/dev/i2c-1 on GPIO pins 3 and 5) and enable access from the i2c group. frequency = lib.mkOption {
After a reboot, i2c-tools (e.g. i2cdetect -F 1) should work for root or any user in i2c. type = lib.types.nullOr lib.types.int;
''; default = null;
description = ''
interface clock-frequency
'';
};
};
i2c1 = {
enable = lib.mkEnableOption ''
Turn on the ARM I2C bus (/dev/i2c-1 on GPIO pins 3 and 5) and enable access from the i2c group.
After a reboot, i2c-tools (e.g. i2cdetect -F 1) should work for root or any user in i2c.
'';
frequency = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
description = ''
interface clock-frequency
'';
};
};
}; };
config.hardware = lib.mkMerge [ config.hardware = lib.mkMerge [
(lib.mkIf cfg.i2c0.enable { (lib.mkIf cfg.i2c0.enable {
i2c.enable = lib.mkDefault true; i2c.enable = lib.mkDefault true;
deviceTree = { deviceTree = {
overlays = [ (simple-overlay { target = "i2c0if"; status = "okay"; }) ]; overlays = [ (simple-overlay {
target = "i2c0if";
status = "okay";
frequency = cfg.i2c0.frequency;
}) ];
}; };
}) })
(lib.mkIf cfg.i2c1.enable { (lib.mkIf cfg.i2c1.enable {
i2c.enable = lib.mkDefault true; i2c.enable = lib.mkDefault true;
deviceTree = { deviceTree = {
overlays = [ (simple-overlay { target = "i2c1"; status = "okay"; }) ]; overlays = [ (simple-overlay {
target = "i2c1";
status = "okay";
frequency = cfg.i2c1.frequency;
}) ];
}; };
}) })
]; ];