mfd: Fix twl-core oops while calling twl_i2c_* for unbound driver
[linux-2.6.git] / drivers / mfd / ezx-pcap.c
index 016be49..43a76c4 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/mfd/ezx-pcap.h>
 #include <linux/spi/spi.h>
 #include <linux/gpio.h>
+#include <linux/slab.h>
 
 #define PCAP_ADC_MAXQ          8
 struct pcap_adc_request {
@@ -143,26 +144,27 @@ int pcap_to_irq(struct pcap_chip *pcap, int irq)
 }
 EXPORT_SYMBOL_GPL(pcap_to_irq);
 
-static void pcap_mask_irq(unsigned int irq)
+static void pcap_mask_irq(struct irq_data *d)
 {
-       struct pcap_chip *pcap = get_irq_chip_data(irq);
+       struct pcap_chip *pcap = irq_data_get_irq_chip_data(d);
 
-       pcap->msr |= 1 << irq_to_pcap(pcap, irq);
+       pcap->msr |= 1 << irq_to_pcap(pcap, d->irq);
        queue_work(pcap->workqueue, &pcap->msr_work);
 }
 
-static void pcap_unmask_irq(unsigned int irq)
+static void pcap_unmask_irq(struct irq_data *d)
 {
-       struct pcap_chip *pcap = get_irq_chip_data(irq);
+       struct pcap_chip *pcap = irq_data_get_irq_chip_data(d);
 
-       pcap->msr &= ~(1 << irq_to_pcap(pcap, irq));
+       pcap->msr &= ~(1 << irq_to_pcap(pcap, d->irq));
        queue_work(pcap->workqueue, &pcap->msr_work);
 }
 
 static struct irq_chip pcap_irq_chip = {
-       .name   = "pcap",
-       .mask   = pcap_mask_irq,
-       .unmask = pcap_unmask_irq,
+       .name           = "pcap",
+       .irq_disable    = pcap_mask_irq,
+       .irq_mask       = pcap_mask_irq,
+       .irq_unmask     = pcap_unmask_irq,
 };
 
 static void pcap_msr_work(struct work_struct *work)
@@ -183,7 +185,7 @@ static void pcap_isr_work(struct work_struct *work)
                ezx_pcap_read(pcap, PCAP_REG_MSR, &msr);
                ezx_pcap_read(pcap, PCAP_REG_ISR, &isr);
 
-               /* We cant service/ack irqs that are assigned to port 2 */
+               /* We can't service/ack irqs that are assigned to port 2 */
                if (!(pdata->config & PCAP_SECOND_PORT)) {
                        ezx_pcap_read(pcap, PCAP_REG_INT_SEL, &int_sel);
                        isr &= ~int_sel;
@@ -195,18 +197,8 @@ static void pcap_isr_work(struct work_struct *work)
                local_irq_disable();
                service = isr & ~msr;
                for (irq = pcap->irq_base; service; service >>= 1, irq++) {
-                       if (service & 1) {
-                               struct irq_desc *desc = irq_to_desc(irq);
-
-                               if (WARN(!desc, KERN_WARNING
-                                               "Invalid PCAP IRQ %d\n", irq))
-                                       break;
-
-                               if (desc->status & IRQ_DISABLED)
-                                       note_interrupt(irq, desc, IRQ_NONE);
-                               else
-                                       desc->handle_irq(irq, desc);
-                       }
+                       if (service & 1)
+                               generic_handle_irq(irq);
                }
                local_irq_enable();
                ezx_pcap_write(pcap, PCAP_REG_MSR, pcap->msr);
@@ -215,9 +207,9 @@ static void pcap_isr_work(struct work_struct *work)
 
 static void pcap_irq_handler(unsigned int irq, struct irq_desc *desc)
 {
-       struct pcap_chip *pcap = get_irq_data(irq);
+       struct pcap_chip *pcap = irq_get_handler_data(irq);
 
-       desc->chip->ack(irq);
+       desc->irq_data.chip->irq_ack(&desc->irq_data);
        queue_work(pcap->workqueue, &pcap->isr_work);
        return;
 }
@@ -281,7 +273,7 @@ static irqreturn_t pcap_adc_irq(int irq, void *_pcap)
        mutex_lock(&pcap->adc_mutex);
        req = pcap->adc_queue[pcap->adc_head];
 
-       if (WARN(!req, KERN_WARNING "adc irq without pending request\n")) {
+       if (WARN(!req, "adc irq without pending request\n")) {
                mutex_unlock(&pcap->adc_mutex);
                return IRQ_HANDLED;
        }
@@ -383,13 +375,20 @@ static int __devinit pcap_add_subdev(struct pcap_chip *pcap,
                                                struct pcap_subdev *subdev)
 {
        struct platform_device *pdev;
+       int ret;
 
        pdev = platform_device_alloc(subdev->name, subdev->id);
+       if (!pdev)
+               return -ENOMEM;
+
        pdev->dev.parent = &pcap->spi->dev;
        pdev->dev.platform_data = subdev->platform_data;
-       platform_set_drvdata(pdev, pcap);
 
-       return platform_device_add(pdev);
+       ret = platform_device_add(pdev);
+       if (ret)
+               platform_device_put(pdev);
+
+       return ret;
 }
 
 static int __devexit ezx_pcap_remove(struct spi_device *spi)
@@ -412,7 +411,7 @@ static int __devexit ezx_pcap_remove(struct spi_device *spi)
 
        /* cleanup irqchip */
        for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++)
-               set_irq_chip_and_handler(i, NULL, NULL);
+               irq_set_chip_and_handler(i, NULL, NULL);
 
        destroy_workqueue(pcap->workqueue);
 
@@ -457,7 +456,8 @@ static int __devinit ezx_pcap_probe(struct spi_device *spi)
        pcap->irq_base = pdata->irq_base;
        pcap->workqueue = create_singlethread_workqueue("pcapd");
        if (!pcap->workqueue) {
-               dev_err(&spi->dev, "cant create pcap thread\n");
+               ret = -ENOMEM;
+               dev_err(&spi->dev, "can't create pcap thread\n");
                goto free_pcap;
        }
 
@@ -468,12 +468,12 @@ static int __devinit ezx_pcap_probe(struct spi_device *spi)
 
        /* setup irq chip */
        for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++) {
-               set_irq_chip_and_handler(i, &pcap_irq_chip, handle_simple_irq);
-               set_irq_chip_data(i, pcap);
+               irq_set_chip_and_handler(i, &pcap_irq_chip, handle_simple_irq);
+               irq_set_chip_data(i, pcap);
 #ifdef CONFIG_ARM
                set_irq_flags(i, IRQF_VALID);
 #else
-               set_irq_noprobe(i);
+               irq_set_noprobe(i);
 #endif
        }
 
@@ -482,10 +482,10 @@ static int __devinit ezx_pcap_probe(struct spi_device *spi)
        ezx_pcap_write(pcap, PCAP_REG_ISR, PCAP_CLEAR_INTERRUPT_REGISTER);
        pcap->msr = PCAP_MASK_ALL_INTERRUPT;
 
-       set_irq_type(spi->irq, IRQ_TYPE_EDGE_RISING);
-       set_irq_data(spi->irq, pcap);
-       set_irq_chained_handler(spi->irq, pcap_irq_handler);
-       set_irq_wake(spi->irq, 1);
+       irq_set_irq_type(spi->irq, IRQ_TYPE_EDGE_RISING);
+       irq_set_handler_data(spi->irq, pcap);
+       irq_set_chained_handler(spi->irq, pcap_irq_handler);
+       irq_set_irq_wake(spi->irq, 1);
 
        /* ADC */
        adc_irq = pcap_to_irq(pcap, (pdata->config & PCAP_SECOND_PORT) ?
@@ -514,7 +514,7 @@ remove_subdevs:
        free_irq(adc_irq, pcap);
 free_irqchip:
        for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++)
-               set_irq_chip_and_handler(i, NULL, NULL);
+               irq_set_chip_and_handler(i, NULL, NULL);
 /* destroy_workqueue: */
        destroy_workqueue(pcap->workqueue);
 free_pcap:
@@ -548,3 +548,4 @@ module_exit(ezx_pcap_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Daniel Ribeiro / Harald Welte");
 MODULE_DESCRIPTION("Motorola PCAP2 ASIC Driver");
+MODULE_ALIAS("spi:ezx-pcap");