From 4a8f2b39157825fefc505fe4b94f3a9ce101e170 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Thu, 12 Dec 2024 23:23:39 +0000
Subject: [PATCH 1478/1482] overlays: Add ws2812-pio overlay

Add an overlay to enable a WS2812 LED driver on a given GPIO.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 arch/arm/boot/dts/overlays/Makefile           |  3 +-
 arch/arm/boot/dts/overlays/README             | 22 +++++++++
 .../boot/dts/overlays/ws2812-pio-overlay.dts  | 46 +++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/dts/overlays/ws2812-pio-overlay.dts

--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -337,7 +337,8 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
 	waveshare-can-fd-hat-mode-a.dtbo \
 	waveshare-can-fd-hat-mode-b.dtbo \
 	wittypi.dtbo \
-	wm8960-soundcard.dtbo
+	wm8960-soundcard.dtbo \
+	ws2812-pio.dtbo
 
 targets += dtbs dtbs_install
 targets += $(dtbo-y)
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -5487,6 +5487,28 @@ Params: alsaname                Changes
         compatible              Changes the codec compatibility
 
 
+Name:   ws2812-pio
+Info:   Configures a GPIO pin to drive a string of WS2812 LEDS using pio. It
+        can be enabled on any RP1 GPIO in bank 0 (0-27). Up to 4 are supported,
+        assuming nothing else is using PIO. Pi 5 only.
+Load:   dtoverlay=ws2812-pio,<param>=<val>
+Params: brightness              Set the initial brightness for the LEDs. The
+                                brightness can be changed at runtime by writing
+                                a single byte to offset 0 of the device. Note
+                                that brightness is a multiplier for the pixel
+                                values, and only white pixels can reach the
+                                maximum visible brightness. (range 0-255,
+                                default 255)
+        dev_name                The name for the /dev/ device entry. Note that
+                                if the name includes '%d' it will be replaced
+                                by the instance number. (default 'leds%d')
+        gpio                    Output GPIO (0-27, default 4)
+        num_leds                Number of LEDs (default 60)
+        rgbw                    'rgbw=on' (or 'rgbw') indicates that each pixel
+                                includes a white LED as well as the usual red,
+                                green and blue. (default 'off')
+
+
 Troubleshooting
 ===============
 
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/ws2812-pio-overlay.dts
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+// Device tree overlay for RP1 PIO WS2812 driver.
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "brcm,bcm2712";
+
+	fragment@0 {
+		target = <&gpio>;
+		__overlay__ {
+			ws2812_pio_pins: ws2812_pio_pins@4 {
+				brcm,pins = <4>; /* gpio 4 */
+				function = "pio";
+				bias-disable;
+			};
+		};
+	};
+
+	fragment@1 {
+		target-path = "/";
+		__overlay__ {
+			ws2812_pio: ws2812_pio@4 {
+				compatible = "raspberrypi,ws2812-pio-rp1";
+				pinctrl-names = "default";
+				pinctrl-0 = <&ws2812_pio_pins>;
+				dev-name = "leds%d";
+				leds-gpios = <&gpio 4 0>;
+				rpi,num-leds = <60>;
+				rpi,brightness = <255>;
+			};
+		};
+	};
+
+	__overrides__ {
+		brightness = <&ws2812_pio>, "rpi,brightness:0";
+		dev_name = <&ws2812_pio>, "dev-name";
+		gpio = <&ws2812_pio>,"leds-gpios:4",
+		       <&ws2812_pio_pins>,"brcm,pins:0",
+		       /* modify reg values to allow multiple instantiation */
+		       <&ws2812_pio>,"reg:0",
+		       <&ws2812_pio_pins>,"reg:0";
+		num_leds = <&ws2812_pio>, "rpi,num-leds:0";
+		rgbw = <&ws2812_pio>, "rpi,rgbw?";
+	};
+};
