]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
genirq: Provide irq_request/release_resources chip callbacks
authorThomas Gleixner <tglx@linutronix.de>
Sat, 8 Mar 2014 07:59:58 +0000 (08:59 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 12 Mar 2014 15:00:24 +0000 (16:00 +0100)
For certain irq types, e.g. gpios, it's necessary to request resources
before starting up the irq.

This might fail so we cannot use the irq_startup() callback because we
might call the irq_set_type() callback before that which does not make
sense when the resource is not available. Calling irq_startup() before
irq_set_type() can lead to spurious interrupts which is not desired
either.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: http://lkml.kernel.org/r/alpine.DEB.2.02.1403080857160.18573@ionos.tec.linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
include/linux/irq.h
kernel/irq/manage.c

index 7dc10036eff552229cdd964e88669a7759a8152f..e675971bdc3fc16dad87fa20101979b685994dd3 100644 (file)
@@ -303,6 +303,10 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
  * @irq_pm_shutdown:   function called from core code on shutdown once per chip
  * @irq_calc_mask:     Optional function to set irq_data.mask for special cases
  * @irq_print_chip:    optional to print special chip info in show_interrupts
+ * @irq_request_resources:     optional to request resources before calling
+ *                             any other callback related to this irq
+ * @irq_release_resources:     optional to release resources acquired with
+ *                             irq_request_resources
  * @flags:             chip specific flags
  */
 struct irq_chip {
@@ -336,6 +340,8 @@ struct irq_chip {
        void            (*irq_calc_mask)(struct irq_data *data);
 
        void            (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
+       int             (*irq_request_resources)(struct irq_data *data);
+       void            (*irq_release_resources)(struct irq_data *data);
 
        unsigned long   flags;
 };
index d3bf660cb57fb8a26e55c3605dffc78ce82035f4..5d35cbe22896c43a15e84121f5fc5b1c86113095 100644 (file)
@@ -896,6 +896,23 @@ static void irq_setup_forced_threading(struct irqaction *new)
        }
 }
 
+static int irq_request_resources(struct irq_desc *desc)
+{
+       struct irq_data *d = &desc->irq_data;
+       struct irq_chip *c = d->chip;
+
+       return c->irq_request_resources ? c->irq_request_resources(d) : 0;
+}
+
+static void irq_release_resources(struct irq_desc *desc)
+{
+       struct irq_data *d = &desc->irq_data;
+       struct irq_chip *c = d->chip;
+
+       if (c->irq_release_resources)
+               c->irq_release_resources(d);
+}
+
 /*
  * Internal function to register an irqaction - typically used to
  * allocate special interrupts that are part of the architecture.
@@ -1091,6 +1108,13 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
        }
 
        if (!shared) {
+               ret = irq_request_resources(desc);
+               if (ret) {
+                       pr_err("Failed to request resources for %s (irq %d) on irqchip %s\n",
+                              new->name, irq, desc->irq_data.chip->name);
+                       goto out_mask;
+               }
+
                init_waitqueue_head(&desc->wait_for_threads);
 
                /* Setup the type (level, edge polarity) if configured: */
@@ -1261,8 +1285,10 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
        *action_ptr = action->next;
 
        /* If this was the last handler, shut down the IRQ line: */
-       if (!desc->action)
+       if (!desc->action) {
                irq_shutdown(desc);
+               irq_release_resources(desc);
+       }
 
 #ifdef CONFIG_SMP
        /* make sure affinity_hint is cleaned up */