From 71d13a919ff26a37256e82fa4d2fe80b8be78d65 Mon Sep 17 00:00:00 2001
From: Brieuc Dubois <git@bhasher.com>
Date: Mon, 10 Jun 2024 15:40:56 +0200
Subject: [PATCH] rpi4: bluetooth fix

---
 raspberry-pi/4/bluetooth.nix | 44 ++++++++++++++++++++++++++++++++++++
 raspberry-pi/4/default.nix   |  1 +
 2 files changed, 45 insertions(+)
 create mode 100644 raspberry-pi/4/bluetooth.nix

diff --git a/raspberry-pi/4/bluetooth.nix b/raspberry-pi/4/bluetooth.nix
new file mode 100644
index 000000000..78619bcd2
--- /dev/null
+++ b/raspberry-pi/4/bluetooth.nix
@@ -0,0 +1,44 @@
+{ config, lib, ... }:
+
+let
+  cfg = config.hardware.raspberry-pi."4".bluetooth;
+in
+{
+  options.hardware = {
+    raspberry-pi."4".bluetooth = {
+      enable = lib.mkEnableOption ''
+        configuration for bluetooth
+      '';
+    };
+  };
+
+  config = lib.mkIf cfg.enable {
+    hardware.raspberry-pi."4".apply-overlays-dtmerge.enable = lib.mkDefault true;
+    # doesn't work for the CM module, so we exclude e.g. bcm2711-rpi-cm4.dts
+    hardware.deviceTree.filter = "bcm2711-rpi-4*.dtb";
+
+    hardware.deviceTree = {
+      overlays = [
+        {
+          name = "bluetooth-overlay";
+          dtsText = ''
+            /dts-v1/;
+            /plugin/;
+
+            / {
+                compatible = "brcm,bcm2711";
+
+                fragment@0 {
+                    target = <&uart0_pins>;
+                    __overlay__ {
+                            brcm,pins = <30 31 32 33>;
+                            brcm,pull = <2 0 0 2>;
+                    };
+                };
+            };
+          '';
+        }
+      ];
+    };
+  };
+}
diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix
index 41d065afb..a2739d79b 100644
--- a/raspberry-pi/4/default.nix
+++ b/raspberry-pi/4/default.nix
@@ -4,6 +4,7 @@
   imports = [
     ./audio.nix
     ./backlight.nix
+    ./bluetooth.nix
     ./cpu-revision.nix
     ./digi-amp-plus.nix
     ./dwc2.nix