interrupt added and working

This commit is contained in:
2025-06-13 10:50:29 +01:00
parent 8dd3c67c05
commit 9b87645a3d
2 changed files with 88 additions and 1 deletions

View File

@ -6,6 +6,8 @@
#include <linux/of_device.h>
#include <linux/gpio/consumer.h>
#include <linux/spi/spi.h>
#include <linux/interrupt.h>
#include <linux/of_irq.h>
#include "ls7366r.h"
@ -207,11 +209,82 @@ static void dt_ls7366r_remove(struct spi_device *client) {
}
/* interrupt stuff */
static int dt_interrupt_probe(struct platform_device *pdev);
static void dt_interrupt_remove(struct platform_device *pdev);
static struct of_device_id interrupt_driver_ids[] = {
{
.compatible = "hottis,intr",
},
{},
};
MODULE_DEVICE_TABLE(of, interrupt_driver_ids);
static struct platform_driver interrupt_driver = {
.probe = dt_interrupt_probe,
.remove = dt_interrupt_remove,
.driver = {
.name = "interrupt_device_driver",
.of_match_table = interrupt_driver_ids,
},
};
static struct gpio_desc *counter_interrupt;
static int irq_number;
// ISR
static irqreturn_t counter_isr(int irq, void *dev_id) {
printk("counter - interrupt received\n");
return IRQ_HANDLED;
}
static int dt_interrupt_probe(struct platform_device *pdev) {
struct device *dev = &pdev->dev;
printk("counter - interrupt probing\n");
counter_interrupt = gpiod_get(dev, "intr", GPIOD_IN);
if (IS_ERR(counter_interrupt)) {
printk("counter - Error! Could not setup the GPIO intr\n");
return -1 * IS_ERR(counter_interrupt);
}
irq_number = gpiod_to_irq(counter_interrupt);
if (irq_number < 0) {
printk("counter - Error! Could not map GPIO to IRQ\n");
gpiod_put(counter_interrupt);
return irq_number;
}
printk("counter - Info! IRQ %d assigned\n", irq_number);
int ret = request_irq(irq_number, counter_isr,
IRQF_TRIGGER_RISING, "gpio19_irq", dev);
if (ret) {
printk("counter - Error! Could not request IRQ\n");
gpiod_put(counter_interrupt);
return ret;
}
printk("counter - Info! Interrupt assigned\n");
return 0;
}
static void dt_interrupt_remove(struct platform_device *pdev) {
printk("counter - interrupt removing\n");
struct device *dev = &pdev->dev;
free_irq(irq_number, dev);
gpiod_put(counter_interrupt);
}
/* module loading and unloading */
static int __init my_init(void) {
printk("counter - Loading the leds driver...\n");
if(platform_driver_register(&leds_driver)) {
printk("dt_gpio - Error! Could not load driver\n");
printk("dt_gpio - Error! Could not load leds driver\n");
return -1;
}
@ -221,6 +294,13 @@ static int __init my_init(void) {
return -1;
}
printk("counter - Loading the interrupt driver...\n");
if(platform_driver_register(&interrupt_driver)) {
printk("dt_gpio - Error! Could not load interrupt driver\n");
return -1;
}
printk("counter - red led on\n");
gpiod_set_value(red_led, 1);
@ -236,6 +316,9 @@ static void __exit my_exit(void) {
printk("counter - Unloading the ls7366r driver...\n");
spi_unregister_driver(&ls7366r_driver);
printk("counter - Unloading the interrupt driver...\n");
platform_driver_unregister(&interrupt_driver);
}
module_init(my_init);

View File

@ -11,6 +11,10 @@
red-led-gpio = <&gpio 26 0>;
blue-led-gpio = <&gpio 21 0>;
};
intr {
compatible = "hottis,intr";
intr-gpio = <&gpio 19 0>;
};
};
};