ieee1394: ohci1394: reformat PPC_PMAC platform code
[powerpc.git] / drivers / ieee1394 / ohci1394.c
index 8fd0030..3c9dc7d 100644 (file)
@@ -468,7 +468,6 @@ static int get_nb_iso_ctx(struct ti_ohci *ohci, int reg)
 /* Global initialization */
 static void ohci_initialize(struct ti_ohci *ohci)
 {
-       char irq_buf[16];
        quadlet_t buf;
        int num_ports, i;
 
@@ -586,11 +585,10 @@ static void ohci_initialize(struct ti_ohci *ohci)
        reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_linkEnable);
 
        buf = reg_read(ohci, OHCI1394_Version);
-       sprintf (irq_buf, "%d", ohci->dev->irq);
-       PRINT(KERN_INFO, "OHCI-1394 %d.%d (PCI): IRQ=[%s]  "
+       PRINT(KERN_INFO, "OHCI-1394 %d.%d (PCI): IRQ=[%d]  "
              "MMIO=[%llx-%llx]  Max Packet=[%d]  IR/IT contexts=[%d/%d]",
              ((((buf) >> 16) & 0xf) + (((buf) >> 20) & 0xf) * 10),
-             ((((buf) >> 4) & 0xf) + ((buf) & 0xf) * 10), irq_buf,
+             ((((buf) >> 4) & 0xf) + ((buf) & 0xf) * 10), ohci->dev->irq,
              (unsigned long long)pci_resource_start(ohci->dev, 0),
              (unsigned long long)pci_resource_start(ohci->dev, 0) + OHCI1394_REGISTER_SIZE - 1,
              ohci->max_packet_size,
@@ -1225,7 +1223,7 @@ static int ohci_iso_recv_init(struct hpsb_iso *iso)
        int ctx;
        int ret = -ENOMEM;
 
-       recv = kmalloc(sizeof(*recv), SLAB_KERNEL);
+       recv = kmalloc(sizeof(*recv), GFP_KERNEL);
        if (!recv)
                return -ENOMEM;
 
@@ -1918,7 +1916,7 @@ static int ohci_iso_xmit_init(struct hpsb_iso *iso)
        int ctx;
        int ret = -ENOMEM;
 
-       xmit = kmalloc(sizeof(*xmit), SLAB_KERNEL);
+       xmit = kmalloc(sizeof(*xmit), GFP_KERNEL);
        if (!xmit)
                return -ENOMEM;
 
@@ -2301,8 +2299,7 @@ static void ohci_schedule_iso_tasklets(struct ti_ohci *ohci,
        spin_unlock_irqrestore(&ohci->iso_tasklet_list_lock, flags);
 }
 
-static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
-                             struct pt_regs *regs_are_unused)
+static irqreturn_t ohci_irq_handler(int irq, void *dev_id)
 {
        quadlet_t event, node_id;
        struct ti_ohci *ohci = (struct ti_ohci *)dev_id;
@@ -3022,7 +3019,7 @@ alloc_dma_rcv_ctx(struct ti_ohci *ohci, struct dma_rcv_ctx *d,
                        return -ENOMEM;
                }
 
-               d->prg_cpu[i] = pci_pool_alloc(d->prg_pool, SLAB_KERNEL, d->prg_bus+i);
+               d->prg_cpu[i] = pci_pool_alloc(d->prg_pool, GFP_KERNEL, d->prg_bus+i);
                OHCI_DMA_ALLOC("pool dma_rcv prg[%d]", i);
 
                 if (d->prg_cpu[i] != NULL) {
@@ -3118,7 +3115,7 @@ alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d,
        OHCI_DMA_ALLOC("dma_rcv prg pool");
 
        for (i = 0; i < d->num_desc; i++) {
-               d->prg_cpu[i] = pci_pool_alloc(d->prg_pool, SLAB_KERNEL, d->prg_bus+i);
+               d->prg_cpu[i] = pci_pool_alloc(d->prg_pool, GFP_KERNEL, d->prg_bus+i);
                OHCI_DMA_ALLOC("pool dma_trm prg[%d]", i);
 
                 if (d->prg_cpu[i] != NULL) {
@@ -3218,6 +3215,18 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
        struct ti_ohci *ohci;   /* shortcut to currently handled device */
        resource_size_t ohci_base;
 
+#ifdef CONFIG_PPC_PMAC
+       /* Necessary on some machines if ohci1394 was loaded/ unloaded before */
+       if (machine_is(powermac)) {
+               struct device_node *ofn = pci_device_to_OF_node(dev);
+
+               if (ofn) {
+                       pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 1);
+                       pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1);
+               }
+       }
+#endif /* CONFIG_PPC_PMAC */
+
         if (pci_enable_device(dev))
                FAIL(-ENXIO, "Failed to enable OHCI hardware");
         pci_set_master(dev);
@@ -3506,17 +3515,14 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
 #endif
 
 #ifdef CONFIG_PPC_PMAC
-       /* On UniNorth, power down the cable and turn off the chip
-        * clock when the module is removed to save power on
-        * laptops. Turning it back ON is done by the arch code when
-        * pci_enable_device() is called */
+       /* On UniNorth, power down the cable and turn off the chip clock
+        * to save power on laptops */
        {
-               struct device_node* of_node;
+               struct device_node* ofn = pci_device_to_OF_node(ohci->dev);
 
-               of_node = pci_device_to_OF_node(ohci->dev);
-               if (of_node) {
-                       pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0);
-                       pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, of_node, 0, 0);
+               if (ofn) {
+                       pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0);
+                       pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0);
                }
        }
 #endif /* CONFIG_PPC_PMAC */
@@ -3530,49 +3536,101 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
 }
 
 #ifdef CONFIG_PM
-static int ohci1394_pci_resume (struct pci_dev *pdev)
+static int ohci1394_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
-/* PowerMac resume code comes first */
+       int err;
+       struct ti_ohci *ohci = pci_get_drvdata(pdev);
+
+       printk(KERN_INFO "%s does not fully support suspend and resume yet\n",
+              OHCI1394_DRIVER_NAME);
+
+       if (!ohci) {
+               printk(KERN_ERR "%s: tried to suspend nonexisting host\n",
+                      OHCI1394_DRIVER_NAME);
+               return -ENXIO;
+       }
+       DBGMSG("suspend called");
+
+       /* Clear the async DMA contexts and stop using the controller */
+       hpsb_bus_reset(ohci->host);
+
+       /* See ohci1394_pci_remove() for comments on this sequence */
+       reg_write(ohci, OHCI1394_ConfigROMhdr, 0);
+       reg_write(ohci, OHCI1394_BusOptions,
+                 (reg_read(ohci, OHCI1394_BusOptions) & 0x0000f007) |
+                 0x00ff0000);
+       reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff);
+       reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff);
+       reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 0xffffffff);
+       reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 0xffffffff);
+       reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 0xffffffff);
+       reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 0xffffffff);
+       set_phy_reg(ohci, 4, ~0xc0 & get_phy_reg(ohci, 4));
+       reg_write(ohci, OHCI1394_LinkControlClear, 0xffffffff);
+       ohci_devctl(ohci->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT);
+       ohci_soft_reset(ohci);
+
+       err = pci_save_state(pdev);
+       if (err) {
+               PRINT(KERN_ERR, "pci_save_state failed with %d", err);
+               return err;
+       }
+       err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
+       if (err)
+               DBGMSG("pci_set_power_state failed with %d", err);
+
+/* PowerMac suspend code comes last */
 #ifdef CONFIG_PPC_PMAC
        if (machine_is(powermac)) {
-               struct device_node *of_node;
+               struct device_node *ofn = pci_device_to_OF_node(pdev);
 
-               /* Re-enable 1394 */
-               of_node = pci_device_to_OF_node (pdev);
-               if (of_node)
-                       pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1);
+               if (ofn)
+                       pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0);
        }
 #endif /* CONFIG_PPC_PMAC */
 
-       pci_set_power_state(pdev, PCI_D0);
-       pci_restore_state(pdev);
-       return pci_enable_device(pdev);
+       return 0;
 }
 
-static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
+static int ohci1394_pci_resume(struct pci_dev *pdev)
 {
        int err;
+       struct ti_ohci *ohci = pci_get_drvdata(pdev);
 
-       err = pci_save_state(pdev);
-       if (err)
-               goto out;
-       err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
-       if (err)
-               goto out;
+       if (!ohci) {
+               printk(KERN_ERR "%s: tried to resume nonexisting host\n",
+                      OHCI1394_DRIVER_NAME);
+               return -ENXIO;
+       }
+       DBGMSG("resume called");
 
-/* PowerMac suspend code comes last */
+/* PowerMac resume code comes first */
 #ifdef CONFIG_PPC_PMAC
        if (machine_is(powermac)) {
-               struct device_node *of_node;
+               struct device_node *ofn = pci_device_to_OF_node(pdev);
 
-               /* Disable 1394 */
-               of_node = pci_device_to_OF_node (pdev);
-               if (of_node)
-                       pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0);
+               if (ofn)
+                       pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1);
        }
 #endif /* CONFIG_PPC_PMAC */
-out:
-       return err;
+
+       pci_set_power_state(pdev, PCI_D0);
+       pci_restore_state(pdev);
+       err = pci_enable_device(pdev);
+       if (err) {
+               PRINT(KERN_ERR, "pci_enable_device failed with %d", err);
+               return err;
+       }
+
+       /* See ohci1394_pci_probe() for comments on this sequence */
+       ohci_soft_reset(ohci);
+       reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_LPS);
+       reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff);
+       reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff);
+       mdelay(50);
+       ohci_initialize(ohci);
+
+       return 0;
 }
 #endif /* CONFIG_PM */