From 51e4bdf379659e4f80afaa81deea821c48977058 Mon Sep 17 00:00:00 2001 From: Karolis Stasaitis Date: Tue, 2 Aug 2022 20:32:29 +0200 Subject: [PATCH] raspberry-pi-4: add i2c clock-frequency option --- raspberry-pi/4/i2c.nix | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/raspberry-pi/4/i2c.nix b/raspberry-pi/4/i2c.nix index 93c1c6d..786581e 100644 --- a/raspberry-pi/4/i2c.nix +++ b/raspberry-pi/4/i2c.nix @@ -2,7 +2,8 @@ let 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"; dtsText = '' /dts-v1/; @@ -13,6 +14,7 @@ let target = <&${target}>; __overlay__ { status = "${status}"; + ${optionalProperty "clock-frequency" frequency} }; }; }; @@ -21,26 +23,52 @@ let in { options.hardware.raspberry-pi."4" = { - i2c0.enable = lib.mkEnableOption '' - 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. - After a reboot, i2c-tools (e.g. i2cdetect -F 1) should work for root or any user in i2c. - ''; + i2c0 = { + enable = lib.mkEnableOption '' + 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. + ''; + frequency = lib.mkOption { + 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 [ (lib.mkIf cfg.i2c0.enable { i2c.enable = lib.mkDefault true; deviceTree = { - overlays = [ (simple-overlay { target = "i2c0if"; status = "okay"; }) ]; + overlays = [ (simple-overlay { + target = "i2c0if"; + status = "okay"; + frequency = cfg.i2c0.frequency; + }) ]; }; }) (lib.mkIf cfg.i2c1.enable { i2c.enable = lib.mkDefault true; deviceTree = { - overlays = [ (simple-overlay { target = "i2c1"; status = "okay"; }) ]; + overlays = [ (simple-overlay { + target = "i2c1"; + status = "okay"; + frequency = cfg.i2c1.frequency; + }) ]; }; }) ];