diff --git a/raspberry-pi/4/pwm0.nix b/raspberry-pi/4/pwm0.nix index da93a767..13b11c56 100644 --- a/raspberry-pi/4/pwm0.nix +++ b/raspberry-pi/4/pwm0.nix @@ -1,50 +1,39 @@ -{ config, lib, ... }: +{ lib, ... }: -let - cfg = config.hardware.raspberry-pi."4".pwm0; -in { - options.hardware = { - raspberry-pi."4".pwm0 = { - enable = lib.mkEnableOption "support for the hardware pwm0 channel on GPIO_18"; - }; - }; + imports = [ + (lib.mkRemovedOptionModule + [ + "hardware" + "raspberry-pi" + "4" + "pwm0" + ] + '' + If hardware.raspberry-pi."4".pwm0.enable was false, remove it without adding firmware configuration. + If it was true, use the pwm firmware overlay for PWM0 on GPIO18: - 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 */ - }; + { + boot.loader.generic-extlinux-compatible.useGenerationDeviceTree = false; + hardware.raspberry-pi.configtxt.deviceTreeOverlays.pi4 = [ + { + pwm = { + pin = 18; + func = 2; + clock = 100000000; }; - }; + } + ]; + } - fragment@1 { - target = <&pwm>; - __overlay__ { - pinctrl-names = "default"; - assigned-clock-rates = <100000000>; - status = "okay"; - pinctrl-0 = <&pwm_pins>; - }; - }; + The removed pwm0 module explicitly assigned a 100 MHz clock. + Keep clock = 100000000 to preserve that assignment. + Without clock, the pwm overlay leaves the base clock configuration unchanged: + https://github.com/raspberrypi/linux/blob/e165a3e0c5c6729d077c30c6d720c029d688d99d/arch/arm/boot/dts/overlays/pwm-overlay.dts - }; - ''; - } - ]; - }; - }; + Before switching, migrate any remaining hardware.deviceTree.overlays used only in generation DTBs. + For firmware installation, read "Device tree overlays" in raspberry-pi/README.md. + '' + ) + ]; }