aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ssb/pcihost_wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ssb/pcihost_wrapper.c')
-rw-r--r--drivers/ssb/pcihost_wrapper.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/drivers/ssb/pcihost_wrapper.c b/drivers/ssb/pcihost_wrapper.c
new file mode 100644
index 000000000000..82a10abef640
--- /dev/null
+++ b/drivers/ssb/pcihost_wrapper.c
@@ -0,0 +1,104 @@
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
19static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
20{
21 pci_save_state(dev);
22 pci_disable_device(dev);
23 pci_set_power_state(dev, pci_choose_state(dev, state));
24
25 return 0;
26}
27
28static int ssb_pcihost_resume(struct pci_dev *dev)
29{
30 int err;
31
32 pci_set_power_state(dev, 0);
33 err = pci_enable_device(dev);
34 if (err)
35 return err;
36 pci_restore_state(dev);
37
38 return 0;
39}
40#else /* CONFIG_PM */
41# define ssb_pcihost_suspend NULL
42# define ssb_pcihost_resume NULL
43#endif /* CONFIG_PM */
44
45static int ssb_pcihost_probe(struct pci_dev *dev,
46 const struct pci_device_id *id)
47{
48 struct ssb_bus *ssb;
49 int err = -ENOMEM;
50 const char *name;
51
52 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
53 if (!ssb)
54 goto out;
55 err = pci_enable_device(dev);
56 if (err)
57 goto err_kfree_ssb;
58 name = dev->dev.bus_id;
59 if (dev->driver && dev->driver->name)
60 name = dev->driver->name;
61 err = pci_request_regions(dev, name);
62 if (err)
63 goto err_pci_disable;
64 pci_set_master(dev);
65
66 err = ssb_bus_pcibus_register(ssb, dev);
67 if (err)
68 goto err_pci_release_regions;
69
70 pci_set_drvdata(dev, ssb);
71
72out:
73 return err;
74
75err_pci_release_regions:
76 pci_release_regions(dev);
77err_pci_disable:
78 pci_disable_device(dev);
79err_kfree_ssb:
80 kfree(ssb);
81 return err;
82}
83
84static void ssb_pcihost_remove(struct pci_dev *dev)
85{
86 struct ssb_bus *ssb = pci_get_drvdata(dev);
87
88 ssb_bus_unregister(ssb);
89 pci_release_regions(dev);
90 pci_disable_device(dev);
91 kfree(ssb);
92 pci_set_drvdata(dev, NULL);
93}
94
95int ssb_pcihost_register(struct pci_driver *driver)
96{
97 driver->probe = ssb_pcihost_probe;
98 driver->remove = ssb_pcihost_remove;
99 driver->suspend = ssb_pcihost_suspend;
100 driver->resume = ssb_pcihost_resume;
101
102 return pci_register_driver(driver);
103}
104EXPORT_SYMBOL(ssb_pcihost_register);