From 3dbc47b54f550f43c159af955c757724d7e0783d Mon Sep 17 00:00:00 2001 From: Erik Karlsson Date: Wed, 12 Feb 2025 13:55:21 +0100 Subject: [PATCH] gryphon-led-module: turn LED off on system shutdown and module unload --- gryphon-led-module/src/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gryphon-led-module/src/main.c b/gryphon-led-module/src/main.c index af622416e..c1c5e6775 100644 --- a/gryphon-led-module/src/main.c +++ b/gryphon-led-module/src/main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "sk9822.h" @@ -278,6 +279,13 @@ static int canyon_led_probe(struct platform_device *pdev) return 0; } +static void canyon_led_off(struct sk9822_leds *leds) +{ + leds->led_brightness = 0; + memset(leds->led_colors, 0, sizeof(cRGB) * leds->led_count); + sk9822_update(leds); +} + static int canyon_led_remove(struct platform_device *pdev) { struct sk9822_leds *leds; @@ -290,6 +298,8 @@ static int canyon_led_remove(struct platform_device *pdev) return -1; } + canyon_led_off(leds); + if (leds->clock_gpio) { gpiod_put(leds->clock_gpio); } @@ -303,6 +313,18 @@ static int canyon_led_remove(struct platform_device *pdev) return 0; } +static void canyon_led_shutdown(struct platform_device *pdev) +{ + struct sk9822_leds *leds = platform_get_drvdata(pdev); + + if (IS_ERR(leds)) { + printk(KERN_ERR "Platform get drvdata returned NULL\n"); + return; + } + + canyon_led_off(leds); +} + /** * platform driver metadata */ @@ -315,6 +337,7 @@ static const struct of_device_id canyon_led_of_ids[] = { static struct platform_driver canyon_led = { .probe = &canyon_led_probe, .remove = &canyon_led_remove, + .shutdown = &canyon_led_shutdown, .driver = { .name = DRIVER_NAME, .owner = THIS_MODULE,