raspberry-pi/4/i2c1: factor out easy dts into helper, add i2c0

This commit is contained in:
M. Ian Graham 2021-12-11 08:34:25 +09:00
parent e81c9aed16
commit 41c4e294f4
4 changed files with 47 additions and 22 deletions

View File

@ -4,6 +4,7 @@
imports = [
./audio.nix
./dwc2.nix
./i2c0.nix
./i2c1.nix
./modesetting.nix
./poe-hat.nix

25
raspberry-pi/4/i2c0.nix Normal file
View File

@ -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"; }) ];
};
};
};
}

View File

@ -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"; }) ];
};
};
};

View File

@ -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}";
};
};
};
'';
};
}