gryphon-led-module: turn LED off on system shutdown and module unload

This commit is contained in:
Erik Karlsson 2025-02-12 13:55:21 +01:00
parent d6ef40fd0f
commit 3dbc47b54f

View file

@ -28,6 +28,7 @@
#include <linux/gpio/consumer.h>
#include <linux/of.h>
#include <linux/version.h>
#include <linux/string.h>
#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,