]> git.zerfleddert.de Git - ms2-fixes/commitdiff
add support for switching between edge and level triggered IRQs
authorMichael Gernoth <michael@gernoth.net>
Tue, 6 Sep 2011 18:36:31 +0000 (20:36 +0200)
committerMichael Gernoth <michael@gernoth.net>
Tue, 6 Sep 2011 18:36:31 +0000 (20:36 +0200)
debounce.c

index e6040167c3de8f2ccbbd9c1cb57405ca49aba6da..9110598d507ca7ccf88cdb6c8c6a0846a9958b3a 100644 (file)
@@ -2,6 +2,8 @@
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/gpio_event.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
 #include <mach/gpio.h>
 
 #define PREFIX "debounce: "
@@ -45,6 +47,42 @@ static void hw_debounce_set(int enable, int time) {
        }
 }
 
+static void set_irq_types(void) {
+       int err;
+       unsigned int irq;
+       unsigned long type;
+       int i;
+
+       if (gpio_evmi == NULL)
+               return;
+
+       switch (gpio_evmi->flags & (GPIOKPF_ACTIVE_HIGH|GPIOKPF_LEVEL_TRIGGERED_IRQ)) {
+       default:
+               type = IRQ_TYPE_EDGE_FALLING;
+               break;
+       case GPIOKPF_ACTIVE_HIGH:
+               type = IRQ_TYPE_EDGE_RISING;
+               break;
+       case GPIOKPF_LEVEL_TRIGGERED_IRQ:
+               type = IRQ_TYPE_LEVEL_LOW;
+               break;
+       case GPIOKPF_LEVEL_TRIGGERED_IRQ | GPIOKPF_ACTIVE_HIGH:
+               type = IRQ_TYPE_LEVEL_HIGH;
+               break;
+       }
+
+       printk(KERN_INFO PREFIX "Settinhg IRQ type to 0x%lx\n", type);
+
+       for (i = 0; i < gpio_evmi->ninputs; i++) {
+
+               err = irq = gpio_to_irq(gpio_evmi->input_gpios[i]);
+
+               if (err < 0)
+                       return;
+
+               err = set_irq_type(irq, type);
+       }
+}
 
 static ssize_t show_debounce_delay(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -309,6 +347,36 @@ static ssize_t store_active_high_flag(struct device *dev, struct device_attribut
                gpio_evmi->flags &= ~GPIOKPF_ACTIVE_HIGH;
        }
 
+       set_irq_types();
+
+       return count;
+}
+
+static ssize_t show_level_triggered_irq_flag(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       if (!gpio_evmi) 
+               return -ENODEV;
+
+       return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_LEVEL_TRIGGERED_IRQ) ? 1 : 0);
+}
+
+static ssize_t store_level_triggered_irq_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+       unsigned flag;
+
+       if (!gpio_evmi) 
+               return -ENODEV;
+
+       sscanf(buf, "%u", &flag);
+
+       if (flag) {
+               gpio_evmi->flags |= GPIOKPF_LEVEL_TRIGGERED_IRQ;
+       } else {
+               gpio_evmi->flags &= ~GPIOKPF_LEVEL_TRIGGERED_IRQ;
+       }
+
+       set_irq_types();
+
        return count;
 }
 
@@ -396,6 +464,7 @@ static DEVICE_ATTR(print_unmapped_keys_flag, (S_IRUGO | S_IWUGO), show_print_unm
 static DEVICE_ATTR(print_mapped_keys_flag, (S_IRUGO | S_IWUGO), show_print_mapped_keys_flag, store_print_mapped_keys_flag);
 static DEVICE_ATTR(print_phantom_keys_flag, (S_IRUGO | S_IWUGO), show_print_phantom_keys_flag, store_print_phantom_keys_flag);
 static DEVICE_ATTR(active_high_flag, (S_IRUGO), show_active_high_flag, store_active_high_flag);
+static DEVICE_ATTR(level_triggered_irq_flag, (S_IRUGO | S_IWUGO), show_level_triggered_irq_flag, store_level_triggered_irq_flag);
 static DEVICE_ATTR(drive_inactive_flag, (S_IRUGO | S_IWUGO), show_drive_inactive_flag, store_drive_inactive_flag);
 static DEVICE_ATTR(hw_debounce, (S_IRUGO | S_IWUGO), show_hw_debounce, store_hw_debounce);
 static DEVICE_ATTR(hw_debounce_time, (S_IRUGO | S_IWUGO), show_hw_debounce_time, store_hw_debounce_time);
@@ -445,6 +514,7 @@ static int __init debounce_init(void)
        err = device_create_file(&debounce_device, &dev_attr_print_mapped_keys_flag);
        err = device_create_file(&debounce_device, &dev_attr_print_phantom_keys_flag);
        err = device_create_file(&debounce_device, &dev_attr_active_high_flag);
+       err = device_create_file(&debounce_device, &dev_attr_level_triggered_irq_flag);
        err = device_create_file(&debounce_device, &dev_attr_drive_inactive_flag);
        err = device_create_file(&debounce_device, &dev_attr_hw_debounce);
        err = device_create_file(&debounce_device, &dev_attr_hw_debounce_time);
@@ -476,6 +546,7 @@ static void __exit debounce_exit(void)
                        printk(KERN_INFO PREFIX "Restoring flags\n");
                        gpio_evmi->flags = old_flags;
                        printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
+                       set_irq_types();
                }
                gpio_evmi->settle_time = old_settle_time;
                gpio_evmi->poll_time = old_poll_time;
@@ -491,6 +562,7 @@ static void __exit debounce_exit(void)
        device_remove_file(&debounce_device, &dev_attr_print_mapped_keys_flag);
        device_remove_file(&debounce_device, &dev_attr_print_phantom_keys_flag);
        device_remove_file(&debounce_device, &dev_attr_active_high_flag);
+       device_remove_file(&debounce_device, &dev_attr_level_triggered_irq_flag);
        device_remove_file(&debounce_device, &dev_attr_drive_inactive_flag);
        device_remove_file(&debounce_device, &dev_attr_hw_debounce);
        device_remove_file(&debounce_device, &dev_attr_hw_debounce_time);
Impressum, Datenschutz