raspberry-pi/4/i2c: refactor i2c stuff into single file

This commit is contained in:
M. Ian Graham 2021-12-11 10:26:21 +09:00
parent 41c4e294f4
commit 8f1bf828d8
5 changed files with 48 additions and 70 deletions

View File

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

47
raspberry-pi/4/i2c.nix Normal file
View File

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

View File

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

View File

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

View File

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