From 53ec24fe8cf12d33bb825052984febe50fc93320 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 4 Jun 2025 09:51:01 +0100 Subject: [PATCH] save --- driver/counter.c | 64 ++++++++++++++++++++++++++++++++++--------- dtoverlay/counter.dts | 22 +++++++++++++++ 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/driver/counter.c b/driver/counter.c index fd8c378..4c78fef 100644 --- a/driver/counter.c +++ b/driver/counter.c @@ -1,21 +1,59 @@ -#include -#include #include +#include +#include +#include +#include + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Du"); +MODULE_DESCRIPTION("GPIO consumer API example for two LEDs"); + +static struct gpio_desc *led_blue; +static struct gpio_desc *led_red; + +static int __init led_consumer_init(void) +{ + struct device *dev = NULL; + + pr_info("GPIO consumer LED module loading\n"); + + // GPIOs per Name aus dem Device Tree holen (via label oder node property) + led_blue = gpiod_get(dev, "led-blue", GPIOD_OUT_LOW); + if (IS_ERR(led_blue)) { + pr_err("Failed to get GPIO for blue LED\n"); + return PTR_ERR(led_blue); + } + + led_red = gpiod_get(dev, "led-red", GPIOD_OUT_LOW); + if (IS_ERR(led_red)) { + pr_err("Failed to get GPIO for red LED\n"); + gpiod_put(led_blue); + return PTR_ERR(led_red); + } + + // Test: LEDs einschalten + gpiod_set_value(led_blue, 1); + gpiod_set_value(led_red, 1); + msleep(500); + gpiod_set_value(led_blue, 0); + gpiod_set_value(led_red, 0); + + pr_info("LEDs blinked using gpio/consumer\n"); -static int __init counter_init(void) { - pr_info("counter: LKM loaded.\n"); return 0; } -static void __exit counter_exit(void) { - pr_info("counter: LKM unloaded.\n"); +static void __exit led_consumer_exit(void) +{ + gpiod_set_value(led_blue, 0); + gpiod_set_value(led_red, 0); + + gpiod_put(led_blue); + gpiod_put(led_red); + + pr_info("GPIO consumer LED module unloaded\n"); } -module_init(counter_init); -module_exit(counter_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Wolfgang Hottgenroth "); -MODULE_DESCRIPTION("LKM for MainsCnt counter module"); -MODULE_VERSION("0.1"); +module_init(led_consumer_init); +module_exit(led_consumer_exit); diff --git a/dtoverlay/counter.dts b/dtoverlay/counter.dts index d9b7eec..1d4c0c7 100644 --- a/dtoverlay/counter.dts +++ b/dtoverlay/counter.dts @@ -19,6 +19,28 @@ }; }; }; + + fragment@1 { + target-path = "/"; + __overlay__ { + mygpioleds { + compatible = "my,gpio-led-controller"; + pinctrl-names = "default"; + pinctrl-0 = <&gpio_led_blue &gpio_led_red>; + + led-blue { + gpios = <&gpio 26 0>; + label = "led-blue"; + }; + + led-red { + gpios = <&gpio 21 0>; + label = "led-red"; + }; + }; + }; + }; + };