some progress indeed

This commit is contained in:
2025-06-04 12:43:11 +01:00
parent 95a3395313
commit 1af4490a39
3 changed files with 35 additions and 42 deletions

View File

@ -4,7 +4,7 @@ obj-m += $(NAME).o
all: $(NAME).ko $(NAME).dtbo all: $(NAME).ko $(NAME).dtbo
echo Builded Device Tree Overlay and kernel module echo Builded Device Tree Overlay and kernel module
$(NAME).ko: $(NAME).ko: $(NAME).c
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
$(NAME).dtbo: $(NAME).dts $(NAME).dtbo: $(NAME).dts

View File

@ -18,7 +18,7 @@ static void dt_remove(struct platform_device *pdev);
static struct of_device_id my_driver_ids[] = { static struct of_device_id my_driver_ids[] = {
{ {
.compatible = "brightlight,mydev", .compatible = "hottis,counter",
}, { /* sentinel */ } }, { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, my_driver_ids); MODULE_DEVICE_TABLE(of, my_driver_ids);
@ -33,7 +33,8 @@ static struct platform_driver my_driver = {
}; };
/* GPIO variable */ /* GPIO variable */
static struct gpio_desc *my_led = NULL; static struct gpio_desc *red_led = NULL;
static struct gpio_desc *blue_led = NULL;
/** /**
@ -41,44 +42,29 @@ static struct gpio_desc *my_led = NULL;
*/ */
static int dt_probe(struct platform_device *pdev) { static int dt_probe(struct platform_device *pdev) {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
const char *label;
int my_value, ret;
printk("dt_gpio - Now I am in the probe function!\n"); printk("counter - probing\n");
/* Check for device properties */ if(!device_property_present(dev, "red-led-gpio")) {
if(!device_property_present(dev, "label")) { printk("counter - Error! Device property 'red-led-gpio' not found!\n");
printk("dt_gpio - Error! Device property 'label' not found!\n");
return -1; return -1;
} }
if(!device_property_present(dev, "my_value")) { if(!device_property_present(dev, "blue-led-gpio")) {
printk("dt_gpio - Error! Device property 'my_value' not found!\n"); printk("counter - Error! Device property 'blue-led-gpio' not found!\n");
return -1;
}
if(!device_property_present(dev, "green-led-gpio")) {
printk("dt_gpio - Error! Device property 'green-led-gpio' not found!\n");
return -1; return -1;
} }
/* Read device properties */
ret = device_property_read_string(dev, "label", &label);
if(ret) {
printk("dt_gpio - Error! Could not read 'label'\n");
return -1;
}
printk("dt_gpio - label: %s\n", label);
ret = device_property_read_u32(dev, "my_value", &my_value);
if(ret) {
printk("dt_gpio - Error! Could not read 'my_value'\n");
return -1;
}
printk("dt_gpio - my_value: %d\n", my_value);
/* Init GPIO */ /* Init GPIO */
my_led = gpiod_get(dev, "green-led", GPIOD_OUT_LOW); red_led = gpiod_get(dev, "red-led", GPIOD_OUT_LOW);
if(IS_ERR(my_led)) { if(IS_ERR(red_led)) {
printk("dt_gpio - Error! Could not setup the GPIO\n"); printk("counter - Error! Could not setup the GPIO red-led\n");
return -1 * IS_ERR(my_led); return -1 * IS_ERR(red_led);
}
blue_led = gpiod_get(dev, "blue-led", GPIOD_OUT_LOW);
if(IS_ERR(blue_led)) {
printk("counter - Error! Could not setup the GPIO blue-led\n");
return -1 * IS_ERR(blue_led);
} }
return 0; return 0;
@ -88,19 +74,24 @@ static int dt_probe(struct platform_device *pdev) {
* @brief This function is called on unloading the driver * @brief This function is called on unloading the driver
*/ */
static void dt_remove(struct platform_device *pdev) { static void dt_remove(struct platform_device *pdev) {
printk("dt_gpio - Now I am in the remove function\n"); printk("counter - removing\n");
gpiod_put(my_led); gpiod_put(red_led);
gpiod_put(blue_led);
} }
/** /**
* @brief This function is called, when the module is loaded into the kernel * @brief This function is called, when the module is loaded into the kernel
*/ */
static int __init my_init(void) { static int __init my_init(void) {
printk("dt_gpio - Loading the driver...\n"); printk("counter - Loading the driver...\n");
if(platform_driver_register(&my_driver)) { if(platform_driver_register(&my_driver)) {
printk("dt_gpio - Error! Could not load driver\n"); printk("dt_gpio - Error! Could not load driver\n");
return -1; return -1;
} }
printk("counter - red led on\n");
gpiod_set_value(red_led, 1);
return 0; return 0;
} }
@ -108,7 +99,11 @@ static int __init my_init(void) {
* @brief This function is called, when the module is removed from the kernel * @brief This function is called, when the module is removed from the kernel
*/ */
static void __exit my_exit(void) { static void __exit my_exit(void) {
printk("dt_gpio - Unload driver"); printk("counter - Unload driver");
printk("counter - red led off\n");
gpiod_set_value(red_led, 0);
platform_driver_unregister(&my_driver); platform_driver_unregister(&my_driver);
} }

View File

@ -5,12 +5,10 @@
fragment@0 { fragment@0 {
target-path = "/"; target-path = "/";
__overlay__ { __overlay__ {
my_device { counter {
compatible = "brightlight,mydev"; compatible = "hottis,counter";
status = "okay"; red-led-gpio = <&gpio 26 0>;
label = "Test"; blue-led-gpio = <&gpio 21 0>;
my_value = <12>;
green-led-gpio = <&gpio 21 0>;
}; };
}; };
}; };