From 1bc731fde4af337134331572889de8dd8dbff897 Mon Sep 17 00:00:00 2001 From: "M. Ian Graham" Date: Sat, 11 Dec 2021 00:51:56 +0900 Subject: [PATCH 1/4] rpi4: Add option to turn on the ARM I2C bus (i2c1). --- raspberry-pi/4/default.nix | 1 + raspberry-pi/4/i2c1.nix | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 raspberry-pi/4/i2c1.nix diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix index 2fe97e1..d94a9f9 100644 --- a/raspberry-pi/4/default.nix +++ b/raspberry-pi/4/default.nix @@ -4,6 +4,7 @@ imports = [ ./audio.nix ./dwc2.nix + ./i2c1.nix ./modesetting.nix ./poe-hat.nix ./tc358743.nix diff --git a/raspberry-pi/4/i2c1.nix b/raspberry-pi/4/i2c1.nix new file mode 100644 index 0000000..a93acb3 --- /dev/null +++ b/raspberry-pi/4/i2c1.nix @@ -0,0 +1,44 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.hardware.raspberry-pi."4".i2c1; +in +{ + options.hardware = { + raspberry-pi."4".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. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + hardware = { + i2c.enable = true; + deviceTree = { + overlays = [ + # Equivalent to dtparam=i2c1=on + { + name = "i2c1-on-overlay"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2711"; + fragment@0 { + target = <&i2c1>; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + }; + }; + }; + ''; + } + ]; + }; + }; + }; +} From e81c9aed162c49b6652c18b85b2fed131a1968c2 Mon Sep 17 00:00:00 2001 From: "M. Ian Graham" Date: Sat, 11 Dec 2021 05:08:24 +0900 Subject: [PATCH 2/4] raspberry-pi/4/i2c1: indentation fix --- raspberry-pi/4/i2c1.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/raspberry-pi/4/i2c1.nix b/raspberry-pi/4/i2c1.nix index a93acb3..27db73e 100644 --- a/raspberry-pi/4/i2c1.nix +++ b/raspberry-pi/4/i2c1.nix @@ -22,20 +22,20 @@ in { name = "i2c1-on-overlay"; dtsText = '' - /dts-v1/; - /plugin/; - / { - compatible = "brcm,bcm2711"; - fragment@0 { - target = <&i2c1>; - __overlay__ { - #address-cells = <1>; - #size-cells = <0>; - status = "okay"; + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2711"; + fragment@0 { + target = <&i2c1>; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + }; }; }; - }; - ''; + ''; } ]; }; From 41c4e294f441f2aa655f7d8985623ec07a4314af Mon Sep 17 00:00:00 2001 From: "M. Ian Graham" Date: Sat, 11 Dec 2021 08:34:25 +0900 Subject: [PATCH 3/4] raspberry-pi/4/i2c1: factor out easy dts into helper, add i2c0 --- raspberry-pi/4/default.nix | 1 + raspberry-pi/4/i2c0.nix | 25 +++++++++++++++++++++++++ raspberry-pi/4/i2c1.nix | 25 +++---------------------- raspberry-pi/4/overlay.nix | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 raspberry-pi/4/i2c0.nix create mode 100644 raspberry-pi/4/overlay.nix diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix index d94a9f9..7d1bce4 100644 --- a/raspberry-pi/4/default.nix +++ b/raspberry-pi/4/default.nix @@ -4,6 +4,7 @@ imports = [ ./audio.nix ./dwc2.nix + ./i2c0.nix ./i2c1.nix ./modesetting.nix ./poe-hat.nix diff --git a/raspberry-pi/4/i2c0.nix b/raspberry-pi/4/i2c0.nix new file mode 100644 index 0000000..e4fa779 --- /dev/null +++ b/raspberry-pi/4/i2c0.nix @@ -0,0 +1,25 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.hardware.raspberry-pi."4".i2c0; + inherit (import ./overlay.nix) simple-pi4-overlay; +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. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + hardware = { + i2c.enable = lib.mkDefault true; + deviceTree = { + overlays = [ (simple-pi4-overlay { target = "i2c0if"; status = "okay"; }) ]; + }; + }; + }; +} diff --git a/raspberry-pi/4/i2c1.nix b/raspberry-pi/4/i2c1.nix index 27db73e..02d2623 100644 --- a/raspberry-pi/4/i2c1.nix +++ b/raspberry-pi/4/i2c1.nix @@ -2,6 +2,7 @@ let cfg = config.hardware.raspberry-pi."4".i2c1; + inherit (import ./overlay.nix) simple-pi4-overlay; in { options.hardware = { @@ -15,29 +16,9 @@ in config = lib.mkIf cfg.enable { hardware = { - i2c.enable = true; + i2c.enable = lib.mkDefault true; deviceTree = { - overlays = [ - # Equivalent to dtparam=i2c1=on - { - name = "i2c1-on-overlay"; - dtsText = '' - /dts-v1/; - /plugin/; - / { - compatible = "brcm,bcm2711"; - fragment@0 { - target = <&i2c1>; - __overlay__ { - #address-cells = <1>; - #size-cells = <0>; - status = "okay"; - }; - }; - }; - ''; - } - ]; + overlays = [ (simple-pi4-overlay { target = "i2c1"; status = "okay"; }) ]; }; }; }; diff --git a/raspberry-pi/4/overlay.nix b/raspberry-pi/4/overlay.nix new file mode 100644 index 0000000..d32e75f --- /dev/null +++ b/raspberry-pi/4/overlay.nix @@ -0,0 +1,18 @@ +{ + simple-pi4-overlay = { target, status }: { + name = "${target}-${status}-overlay"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2711"; + fragment@0 { + target = <&${target}>; + __overlay__ { + status = "${status}"; + }; + }; + }; + ''; + }; +} From 8f1bf828d8606fe38a02df312cf14546ae200a72 Mon Sep 17 00:00:00 2001 From: "M. Ian Graham" Date: Sat, 11 Dec 2021 10:26:21 +0900 Subject: [PATCH 4/4] raspberry-pi/4/i2c: refactor i2c stuff into single file --- raspberry-pi/4/default.nix | 3 +-- raspberry-pi/4/i2c.nix | 47 ++++++++++++++++++++++++++++++++++++++ raspberry-pi/4/i2c0.nix | 25 -------------------- raspberry-pi/4/i2c1.nix | 25 -------------------- raspberry-pi/4/overlay.nix | 18 --------------- 5 files changed, 48 insertions(+), 70 deletions(-) create mode 100644 raspberry-pi/4/i2c.nix delete mode 100644 raspberry-pi/4/i2c0.nix delete mode 100644 raspberry-pi/4/i2c1.nix delete mode 100644 raspberry-pi/4/overlay.nix diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix index 7d1bce4..fac4cc1 100644 --- a/raspberry-pi/4/default.nix +++ b/raspberry-pi/4/default.nix @@ -4,8 +4,7 @@ imports = [ ./audio.nix ./dwc2.nix - ./i2c0.nix - ./i2c1.nix + ./i2c.nix ./modesetting.nix ./poe-hat.nix ./tc358743.nix diff --git a/raspberry-pi/4/i2c.nix b/raspberry-pi/4/i2c.nix new file mode 100644 index 0000000..93c1c6d --- /dev/null +++ b/raspberry-pi/4/i2c.nix @@ -0,0 +1,47 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.hardware.raspberry-pi."4"; + simple-overlay = { target, status }: { + name = "${target}-${status}-overlay"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2711"; + fragment@0 { + target = <&${target}>; + __overlay__ { + status = "${status}"; + }; + }; + }; + ''; + }; +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. + ''; + }; + config.hardware = lib.mkMerge [ + (lib.mkIf cfg.i2c0.enable { + i2c.enable = lib.mkDefault true; + deviceTree = { + overlays = [ (simple-overlay { target = "i2c0if"; status = "okay"; }) ]; + }; + }) + (lib.mkIf cfg.i2c1.enable { + i2c.enable = lib.mkDefault true; + deviceTree = { + overlays = [ (simple-overlay { target = "i2c1"; status = "okay"; }) ]; + }; + }) + ]; +} diff --git a/raspberry-pi/4/i2c0.nix b/raspberry-pi/4/i2c0.nix deleted file mode 100644 index e4fa779..0000000 --- a/raspberry-pi/4/i2c0.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.hardware.raspberry-pi."4".i2c0; - inherit (import ./overlay.nix) simple-pi4-overlay; -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. - ''; - }; - }; - - config = lib.mkIf cfg.enable { - hardware = { - i2c.enable = lib.mkDefault true; - deviceTree = { - overlays = [ (simple-pi4-overlay { target = "i2c0if"; status = "okay"; }) ]; - }; - }; - }; -} diff --git a/raspberry-pi/4/i2c1.nix b/raspberry-pi/4/i2c1.nix deleted file mode 100644 index 02d2623..0000000 --- a/raspberry-pi/4/i2c1.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.hardware.raspberry-pi."4".i2c1; - inherit (import ./overlay.nix) simple-pi4-overlay; -in -{ - options.hardware = { - raspberry-pi."4".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. - ''; - }; - }; - - config = lib.mkIf cfg.enable { - hardware = { - i2c.enable = lib.mkDefault true; - deviceTree = { - overlays = [ (simple-pi4-overlay { target = "i2c1"; status = "okay"; }) ]; - }; - }; - }; -} diff --git a/raspberry-pi/4/overlay.nix b/raspberry-pi/4/overlay.nix deleted file mode 100644 index d32e75f..0000000 --- a/raspberry-pi/4/overlay.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ - simple-pi4-overlay = { target, status }: { - name = "${target}-${status}-overlay"; - dtsText = '' - /dts-v1/; - /plugin/; - / { - compatible = "brcm,bcm2711"; - fragment@0 { - target = <&${target}>; - __overlay__ { - status = "${status}"; - }; - }; - }; - ''; - }; -}