legacy PC parports support parport->dev
[safe/jmp/linux-2.6] / drivers / parport / parport_pc.c
index 18e85cc..02c0d52 100644 (file)
@@ -3,7 +3,7 @@
  * Authors: Phil Blundell <philb@gnu.org>
  *          Tim Waugh <tim@cyberelk.demon.co.uk>
  *         Jose Renau <renau@acm.org>
- *          David Campbell <campbell@torque.net>
+ *          David Campbell
  *          Andrea Arcangeli
  *
  * based on work by Grant Guenther <grant@torque.net> and Phil Blundell.
@@ -42,7 +42,6 @@
  * but rather will start at port->base_hi.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/sched.h>
@@ -54,6 +53,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/pnp.h>
+#include <linux/platform_device.h>
 #include <linux/sysctl.h>
 
 #include <asm/io.h>
@@ -97,7 +97,7 @@ static struct superio_struct {        /* For Super-IO chips autodetection */
        int io;
        int irq;
        int dma;
-} superios[NR_SUPERIOS] __devinitdata = { {0,},};
+} superios[NR_SUPERIOS] = { {0,},};
 
 static int user_specified;
 #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
@@ -271,9 +271,9 @@ static int clear_epp_timeout(struct parport *pb)
  * of these are in parport_pc.h.
  */
 
-static irqreturn_t parport_pc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t parport_pc_interrupt(int irq, void *dev_id)
 {
-       parport_generic_irq(irq, (struct parport *) dev_id, regs);
+       parport_generic_irq(irq, (struct parport *) dev_id);
        /* FIXME! Was it really ours? */
        return IRQ_HANDLED;
 }
@@ -621,6 +621,7 @@ static size_t parport_pc_fifo_write_block_dma (struct parport *port,
        unsigned long dmaflag;
        size_t left = length;
        const struct parport_pc_private *priv = port->physport->private_data;
+       struct device *dev = port->physport->dev;
        dma_addr_t dma_addr, dma_handle;
        size_t maxlen = 0x10000; /* max 64k per DMA transfer */
        unsigned long start = (unsigned long) buf;
@@ -632,8 +633,8 @@ dump_parport_state ("enter fifo_write_block_dma", port);
                if ((start ^ end) & ~0xffffUL)
                        maxlen = 0x10000 - (start & 0xffff);
 
-               dma_addr = dma_handle = pci_map_single(priv->dev, (void *)buf, length,
-                                                      PCI_DMA_TODEVICE);
+               dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
+                                                      DMA_TO_DEVICE);
         } else {
                /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
                maxlen   = PAGE_SIZE;          /* sizeof(priv->dma_buf) */
@@ -729,9 +730,9 @@ dump_parport_state ("enter fifo_write_block_dma", port);
 
        /* Turn off DMA mode */
        frob_econtrol (port, 1<<3, 0);
-       
+
        if (dma_handle)
-               pci_unmap_single(priv->dev, dma_handle, length, PCI_DMA_TODEVICE);
+               dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
 
 dump_parport_state ("leave fifo_write_block_dma", port);
        return length - left;
@@ -1547,7 +1548,7 @@ static void __devinit detect_and_report_smsc (void)
 }
 #endif /* CONFIG_PARPORT_PC_SUPERIO */
 
-static int __devinit get_superio_dma (struct parport *p)
+static int get_superio_dma (struct parport *p)
 {
        int i=0;
        while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
@@ -1557,7 +1558,7 @@ static int __devinit get_superio_dma (struct parport *p)
        return PARPORT_DMA_NONE;
 }
 
-static int __devinit get_superio_irq (struct parport *p)
+static int get_superio_irq (struct parport *p)
 {
        int i=0;
         while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
@@ -1579,7 +1580,7 @@ static int __devinit get_superio_irq (struct parport *p)
  *                         this shall always be the case!)
  *
  */
-static int __devinit parport_SPP_supported(struct parport *pb)
+static int parport_SPP_supported(struct parport *pb)
 {
        unsigned char r, w;
 
@@ -1660,7 +1661,7 @@ static int __devinit parport_SPP_supported(struct parport *pb)
  * two bits of ECR aren't writable, so we check by writing ECR and
  * reading it back to see if it's what we expect.
  */
-static int __devinit parport_ECR_present(struct parport *pb)
+static int parport_ECR_present(struct parport *pb)
 {
        struct parport_pc_private *priv = pb->private_data;
        unsigned char r = 0xc;
@@ -1712,7 +1713,7 @@ static int __devinit parport_ECR_present(struct parport *pb)
  * be misdetected here is rather academic. 
  */
 
-static int __devinit parport_PS2_supported(struct parport *pb)
+static int parport_PS2_supported(struct parport *pb)
 {
        int ok = 0;
   
@@ -1868,7 +1869,7 @@ static int __devinit parport_ECP_supported(struct parport *pb)
 }
 #endif
 
-static int __devinit parport_ECPPS2_supported(struct parport *pb)
+static int parport_ECPPS2_supported(struct parport *pb)
 {
        const struct parport_pc_private *priv = pb->private_data;
        int result;
@@ -1886,7 +1887,7 @@ static int __devinit parport_ECPPS2_supported(struct parport *pb)
 
 /* EPP mode detection  */
 
-static int __devinit parport_EPP_supported(struct parport *pb)
+static int parport_EPP_supported(struct parport *pb)
 {
        const struct parport_pc_private *priv = pb->private_data;
 
@@ -1931,7 +1932,7 @@ static int __devinit parport_EPP_supported(struct parport *pb)
        return 1;
 }
 
-static int __devinit parport_ECPEPP_supported(struct parport *pb)
+static int parport_ECPEPP_supported(struct parport *pb)
 {
        struct parport_pc_private *priv = pb->private_data;
        int result;
@@ -1976,7 +1977,7 @@ static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
 /* --- IRQ detection -------------------------------------- */
 
 /* Only if supports ECP mode */
-static int __devinit programmable_irq_support(struct parport *pb)
+static int programmable_irq_support(struct parport *pb)
 {
        int irq, intrLine;
        unsigned char oecr = inb (ECONTROL (pb));
@@ -1993,7 +1994,7 @@ static int __devinit programmable_irq_support(struct parport *pb)
        return irq;
 }
 
-static int __devinit irq_probe_ECP(struct parport *pb)
+static int irq_probe_ECP(struct parport *pb)
 {
        int i;
        unsigned long irqs;
@@ -2021,7 +2022,7 @@ static int __devinit irq_probe_ECP(struct parport *pb)
  * This detection seems that only works in National Semiconductors
  * This doesn't work in SMC, LGS, and Winbond 
  */
-static int __devinit irq_probe_EPP(struct parport *pb)
+static int irq_probe_EPP(struct parport *pb)
 {
 #ifndef ADVANCED_DETECT
        return PARPORT_IRQ_NONE;
@@ -2060,7 +2061,7 @@ static int __devinit irq_probe_EPP(struct parport *pb)
 #endif /* Advanced detection */
 }
 
-static int __devinit irq_probe_SPP(struct parport *pb)
+static int irq_probe_SPP(struct parport *pb)
 {
        /* Don't even try to do this. */
        return PARPORT_IRQ_NONE;
@@ -2073,7 +2074,7 @@ static int __devinit irq_probe_SPP(struct parport *pb)
  * When ECP is available we can autoprobe for IRQs.
  * NOTE: If we can autoprobe it, we can register the IRQ.
  */
-static int __devinit parport_irq_probe(struct parport *pb)
+static int parport_irq_probe(struct parport *pb)
 {
        struct parport_pc_private *priv = pb->private_data;
 
@@ -2107,7 +2108,7 @@ static int __devinit parport_irq_probe(struct parport *pb)
 /* --- DMA detection -------------------------------------- */
 
 /* Only if chipset conforms to ECP ISA Interface Standard */
-static int __devinit programmable_dma_support (struct parport *p)
+static int programmable_dma_support (struct parport *p)
 {
        unsigned char oecr = inb (ECONTROL (p));
        int dma;
@@ -2124,7 +2125,7 @@ static int __devinit programmable_dma_support (struct parport *p)
        return dma;
 }
 
-static int __devinit parport_dma_probe (struct parport *p)
+static int parport_dma_probe (struct parport *p)
 {
        const struct parport_pc_private *priv = p->private_data;
        if (priv->ecr)
@@ -2147,7 +2148,7 @@ static DEFINE_SPINLOCK(ports_lock);
 struct parport *parport_pc_probe_port (unsigned long int base,
                                       unsigned long int base_hi,
                                       int irq, int dma,
-                                      struct pci_dev *dev)
+                                      struct device *dev)
 {
        struct parport_pc_private *priv;
        struct parport_operations *ops;
@@ -2156,6 +2157,17 @@ struct parport *parport_pc_probe_port (unsigned long int base,
        struct resource *base_res;
        struct resource *ECR_res = NULL;
        struct resource *EPP_res = NULL;
+       struct platform_device *pdev = NULL;
+
+       if (!dev) {
+               /* We need a physical device to attach to, but none was
+                * provided. Create our own. */
+               pdev = platform_device_register_simple("parport_pc",
+                                                      base, NULL, 0);
+               if (IS_ERR(pdev))
+                       return NULL;
+               dev = &pdev->dev;
+       }
 
        ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
        if (!ops)
@@ -2181,9 +2193,10 @@ struct parport *parport_pc_probe_port (unsigned long int base,
        priv->fifo_depth = 0;
        priv->dma_buf = NULL;
        priv->dma_handle = 0;
-       priv->dev = dev;
        INIT_LIST_HEAD(&priv->list);
        priv->port = p;
+
+       p->dev = dev;
        p->base_hi = base_hi;
        p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
        p->private_data = priv;
@@ -2306,9 +2319,10 @@ struct parport *parport_pc_probe_port (unsigned long int base,
                                p->dma = PARPORT_DMA_NONE;
                        } else {
                                priv->dma_buf =
-                                 pci_alloc_consistent(priv->dev,
+                                 dma_alloc_coherent(dev,
                                                       PAGE_SIZE,
-                                                      &priv->dma_handle);
+                                                      &priv->dma_handle,
+                                                      GFP_KERNEL);
                                if (! priv->dma_buf) {
                                        printk (KERN_WARNING "%s: "
                                                "cannot get buffer for DMA, "
@@ -2357,6 +2371,8 @@ out3:
 out2:
        kfree (ops);
 out1:
+       if (pdev)
+               platform_device_unregister(pdev);
        return NULL;
 }
 
@@ -2371,8 +2387,10 @@ void parport_pc_unregister_port (struct parport *p)
        spin_lock(&ports_lock);
        list_del_init(&priv->list);
        spin_unlock(&ports_lock);
+#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
        if (p->dma != PARPORT_DMA_NONE)
                free_dma(p->dma);
+#endif
        if (p->irq != PARPORT_IRQ_NONE)
                free_irq(p->irq, p);
        release_region(p->base, 3);
@@ -2380,14 +2398,12 @@ void parport_pc_unregister_port (struct parport *p)
                release_region(p->base + 3, p->size - 3);
        if (p->modes & PARPORT_MODE_ECP)
                release_region(p->base_hi, 3);
-#ifdef CONFIG_PARPORT_PC_FIFO
-#ifdef HAS_DMA
+#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
        if (priv->dma_buf)
-               pci_free_consistent(priv->dev, PAGE_SIZE,
+               dma_free_coherent(p->physport->dev, PAGE_SIZE,
                                    priv->dma_buf,
                                    priv->dma_handle);
 #endif
-#endif
        kfree (p->private_data);
        parport_put_port(p);
        kfree (ops); /* hope no-one cached it */
@@ -2490,7 +2506,7 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
         */
        release_resource(base_res);
        if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi,
-                                  irq, PARPORT_DMA_NONE, NULL)) {
+                                  irq, PARPORT_DMA_NONE, &pdev->dev)) {
                printk (KERN_INFO
                        "parport_pc: ITE 8872 parallel port: io=0x%X",
                        ite8872_lpt);
@@ -2673,7 +2689,7 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
        }
 
        /* finally, do the probe with values obtained */
-       if (parport_pc_probe_port (port1, port2, irq, dma, NULL)) {
+       if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev)) {
                printk (KERN_INFO
                        "parport_pc: VIA parallel port: io=0x%X", port1);
                if (irq != PARPORT_IRQ_NONE)
@@ -2748,6 +2764,7 @@ enum parport_pc_pci_cards {
        titan_1284p2,
        avlab_1p,
        avlab_2p,
+       oxsemi_952,
        oxsemi_954,
        oxsemi_840,
        aks_0100,
@@ -2779,7 +2796,7 @@ static struct parport_pc_pci {
        /* If set, this is called after probing for ports.  If 'failed'
         * is non-zero we couldn't use any of the ports. */
        void (*postinit_hook) (struct pci_dev *pdev, int failed);
-} cards[] __devinitdata = {
+} cards[] = {
        /* siig_1p_10x */               { 1, { { 2, 3 }, } },
        /* siig_2p_10x */               { 2, { { 2, 3 }, { 4, 5 }, } },
        /* siig_1p_20x */               { 1, { { 0, 1 }, } },
@@ -2823,6 +2840,7 @@ static struct parport_pc_pci {
        /* avlab_2p             */      { 2, { { 0, 1}, { 2, 3 },} },
        /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
         * and 840 locks up if you write 1 to bit 2! */
+       /* oxsemi_952 */                { 1, { { 0, 1 }, } },
        /* oxsemi_954 */                { 1, { { 0, -1 }, } },
        /* oxsemi_840 */                { 1, { { 0, -1 }, } },
        /* aks_0100 */                  { 1, { { 0, -1 }, } },
@@ -2896,6 +2914,8 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
        /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
        { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */
        { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
+       { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
        { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
        { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
@@ -2967,7 +2987,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev,
                        parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi);
                data->ports[count] =
                        parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
-                                              PARPORT_DMA_NONE, dev);
+                                              PARPORT_DMA_NONE, &dev->dev);
                if (data->ports[count])
                        count++;
        }
@@ -3074,8 +3094,8 @@ static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id
        } else
                dma = PARPORT_DMA_NONE;
 
-       printk(KERN_INFO "parport: PnPBIOS parport detected.\n");
-       if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, NULL)))
+       dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
+       if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, &dev->dev)))
                return -ENODEV;
 
        pnp_set_drvdata(dev,pdata);
@@ -3100,6 +3120,21 @@ static struct pnp_driver parport_pc_pnp_driver = {
 };
 
 
+static int __devinit parport_pc_platform_probe(struct platform_device *pdev)
+{
+       /* Always succeed, the actual probing is done in
+        * parport_pc_probe_port(). */
+       return 0;
+}
+
+static struct platform_driver parport_pc_platform_driver = {
+       .driver = {
+               .owner  = THIS_MODULE,
+               .name   = "parport_pc",
+       },
+       .probe          = parport_pc_platform_probe,
+};
+
 /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
 static int __devinit __attribute__((unused))
 parport_pc_find_isa_ports (int autoirq, int autodma)
@@ -3126,9 +3161,9 @@ parport_pc_find_isa_ports (int autoirq, int autodma)
  * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
  * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
  */
-static int __init parport_pc_find_ports (int autoirq, int autodma)
+static void __init parport_pc_find_ports (int autoirq, int autodma)
 {
-       int count = 0, r;
+       int count = 0, err;
 
 #ifdef CONFIG_PARPORT_PC_SUPERIO
        detect_and_report_winbond ();
@@ -3140,23 +3175,17 @@ static int __init parport_pc_find_ports (int autoirq, int autodma)
 
        /* PnP ports, skip detection if SuperIO already found them */
        if (!count) {
-               r = pnp_register_driver (&parport_pc_pnp_driver);
-               if (r >= 0) {
+               err = pnp_register_driver (&parport_pc_pnp_driver);
+               if (!err)
                        pnp_registered_parport = 1;
-                       count += r;
-               }
        }
 
        /* ISA ports and whatever (see asm/parport.h). */
-       count += parport_pc_find_nonpci_ports (autoirq, autodma);
+       parport_pc_find_nonpci_ports (autoirq, autodma);
 
-       r = pci_register_driver (&parport_pc_pci_driver);
-       if (r)
-               return r;
-       pci_registered_parport = 1;
-       count += 1;
-
-       return count;
+       err = pci_register_driver (&parport_pc_pci_driver);
+       if (!err)
+               pci_registered_parport = 1;
 }
 
 /*
@@ -3381,11 +3410,15 @@ __setup("parport_init_mode=",parport_init_mode_setup);
 
 static int __init parport_pc_init(void)
 {
-       int count = 0;
+       int err;
 
        if (parse_parport_params())
                return -EINVAL;
 
+       err = platform_driver_register(&parport_pc_platform_driver);
+       if (err)
+               return err;
+
        if (io[0]) {
                int i;
                /* Only probe the ports we were given. */
@@ -3395,12 +3428,11 @@ static int __init parport_pc_init(void)
                                break;
                        if ((io_hi[i]) == PARPORT_IOHI_AUTO)
                               io_hi[i] = 0x400 + io[i];
-                       if (parport_pc_probe_port(io[i], io_hi[i],
-                                                 irqval[i], dmaval[i], NULL))
-                               count++;
+                       parport_pc_probe_port(io[i], io_hi[i],
+                                                 irqval[i], dmaval[i], NULL);
                }
        } else
-               count += parport_pc_find_ports (irqval[0], dmaval[0]);
+               parport_pc_find_ports (irqval[0], dmaval[0]);
 
        return 0;
 }
@@ -3411,6 +3443,7 @@ static void __exit parport_pc_exit(void)
                pci_unregister_driver (&parport_pc_pci_driver);
        if (pnp_registered_parport)
                pnp_unregister_driver (&parport_pc_pnp_driver);
+       platform_driver_unregister(&parport_pc_platform_driver);
 
        spin_lock(&ports_lock);
        while (!list_empty(&ports_list)) {
@@ -3419,6 +3452,9 @@ static void __exit parport_pc_exit(void)
                priv = list_entry(ports_list.next,
                                  struct parport_pc_private, list);
                port = priv->port;
+               if (port->dev && port->dev->bus == &platform_bus_type)
+                       platform_device_unregister(
+                               to_platform_device(port->dev));
                spin_unlock(&ports_lock);
                parport_pc_unregister_port(port);
                spin_lock(&ports_lock);