ide-floppy: add more debugging to idefloppy_pc_intr()
[pandora-kernel.git] / drivers / ssb / pcihost_wrapper.c
1 /*
2  * Sonics Silicon Backplane
3  * PCI Hostdevice wrapper
4  *
5  * Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
6  * Copyright (c) 2005 Stefano Brivio <st3@riseup.net>
7  * Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
8  * Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
9  * Copyright (c) 2005-2007 Michael Buesch <mbuesch@freenet.de>
10  *
11  * Licensed under the GNU/GPL. See COPYING for details.
12  */
13
14 #include <linux/pci.h>
15 #include <linux/ssb/ssb.h>
16
17
18 #ifdef CONFIG_PM
19 static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
20 {
21         struct ssb_bus *ssb = pci_get_drvdata(dev);
22         int err;
23
24         err = ssb_bus_suspend(ssb);
25         if (err)
26                 return err;
27         pci_save_state(dev);
28         pci_disable_device(dev);
29         pci_set_power_state(dev, pci_choose_state(dev, state));
30
31         return 0;
32 }
33
34 static int ssb_pcihost_resume(struct pci_dev *dev)
35 {
36         struct ssb_bus *ssb = pci_get_drvdata(dev);
37         int err;
38
39         pci_set_power_state(dev, 0);
40         err = pci_enable_device(dev);
41         if (err)
42                 return err;
43         pci_restore_state(dev);
44         err = ssb_bus_resume(ssb);
45         if (err)
46                 return err;
47
48         return 0;
49 }
50 #else /* CONFIG_PM */
51 # define ssb_pcihost_suspend    NULL
52 # define ssb_pcihost_resume     NULL
53 #endif /* CONFIG_PM */
54
55 static int ssb_pcihost_probe(struct pci_dev *dev,
56                              const struct pci_device_id *id)
57 {
58         struct ssb_bus *ssb;
59         int err = -ENOMEM;
60         const char *name;
61
62         ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
63         if (!ssb)
64                 goto out;
65         err = pci_enable_device(dev);
66         if (err)
67                 goto err_kfree_ssb;
68         name = dev->dev.bus_id;
69         if (dev->driver && dev->driver->name)
70                 name = dev->driver->name;
71         err = pci_request_regions(dev, name);
72         if (err)
73                 goto err_pci_disable;
74         pci_set_master(dev);
75
76         err = ssb_bus_pcibus_register(ssb, dev);
77         if (err)
78                 goto err_pci_release_regions;
79
80         pci_set_drvdata(dev, ssb);
81
82 out:
83         return err;
84
85 err_pci_release_regions:
86         pci_release_regions(dev);
87 err_pci_disable:
88         pci_disable_device(dev);
89 err_kfree_ssb:
90         kfree(ssb);
91         return err;
92 }
93
94 static void ssb_pcihost_remove(struct pci_dev *dev)
95 {
96         struct ssb_bus *ssb = pci_get_drvdata(dev);
97
98         ssb_bus_unregister(ssb);
99         pci_release_regions(dev);
100         pci_disable_device(dev);
101         kfree(ssb);
102         pci_set_drvdata(dev, NULL);
103 }
104
105 int ssb_pcihost_register(struct pci_driver *driver)
106 {
107         driver->probe = ssb_pcihost_probe;
108         driver->remove = ssb_pcihost_remove;
109         driver->suspend = ssb_pcihost_suspend;
110         driver->resume = ssb_pcihost_resume;
111
112         return pci_register_driver(driver);
113 }
114 EXPORT_SYMBOL(ssb_pcihost_register);