From 1c076b237f3b7b3c178e8672c7c700f295fbdb7e Mon Sep 17 00:00:00 2001 From: ettom <36895504+ettom@users.noreply.github.com> Date: Mon, 21 Feb 2022 22:06:43 +0200 Subject: [PATCH] Add rpi4 pwm0 support --- raspberry-pi/4/default.nix | 1 + raspberry-pi/4/pwm0.nix | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 raspberry-pi/4/pwm0.nix diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix index fac4cc1..fcaf5ad 100644 --- a/raspberry-pi/4/default.nix +++ b/raspberry-pi/4/default.nix @@ -8,6 +8,7 @@ ./modesetting.nix ./poe-hat.nix ./tc358743.nix + ./pwm0.nix ]; boot = { diff --git a/raspberry-pi/4/pwm0.nix b/raspberry-pi/4/pwm0.nix new file mode 100644 index 0000000..37ae3a1 --- /dev/null +++ b/raspberry-pi/4/pwm0.nix @@ -0,0 +1,50 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.hardware.raspberry-pi."4".pwm0; +in +{ + options.hardware = { + raspberry-pi."4".pwm0 = { + enable = lib.mkEnableOption '' + Enable support for the hardware pwm0 channel on GPIO_18 + ''; + }; + }; + + config = lib.mkIf cfg.enable { + hardware.deviceTree = { + overlays = [{ + name = "pwm-overlay"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2711"; + + fragment@0 { + target = <&gpio>; + __overlay__ { + pwm_pins: pwm_pins { + brcm,pins = <18>; + brcm,function = <2>; /* Alt5 */ + }; + }; + }; + + fragment@1 { + target = <&pwm>; + __overlay__ { + pinctrl-names = "default"; + assigned-clock-rates = <100000000>; + status = "okay"; + pinctrl-0 = <&pwm_pins>; + }; + }; + + }; + ''; + }]; + }; + }; +}