PCI ACPI: AER driver should only register PCIe devices with _OSC
[pv_ops_mirror.git] / drivers / ssb / pcihost_wrapper.c
blob82a10abef64045053a6acfcfd6c5d45c5c4c156f
1 /*
2 * Sonics Silicon Backplane
3 * PCI Hostdevice wrapper
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>
11 * Licensed under the GNU/GPL. See COPYING for details.
14 #include <linux/pci.h>
15 #include <linux/ssb/ssb.h>
18 #ifdef CONFIG_PM
19 static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
21 pci_save_state(dev);
22 pci_disable_device(dev);
23 pci_set_power_state(dev, pci_choose_state(dev, state));
25 return 0;
28 static int ssb_pcihost_resume(struct pci_dev *dev)
30 int err;
32 pci_set_power_state(dev, 0);
33 err = pci_enable_device(dev);
34 if (err)
35 return err;
36 pci_restore_state(dev);
38 return 0;
40 #else /* CONFIG_PM */
41 # define ssb_pcihost_suspend NULL
42 # define ssb_pcihost_resume NULL
43 #endif /* CONFIG_PM */
45 static int ssb_pcihost_probe(struct pci_dev *dev,
46 const struct pci_device_id *id)
48 struct ssb_bus *ssb;
49 int err = -ENOMEM;
50 const char *name;
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);
66 err = ssb_bus_pcibus_register(ssb, dev);
67 if (err)
68 goto err_pci_release_regions;
70 pci_set_drvdata(dev, ssb);
72 out:
73 return err;
75 err_pci_release_regions:
76 pci_release_regions(dev);
77 err_pci_disable:
78 pci_disable_device(dev);
79 err_kfree_ssb:
80 kfree(ssb);
81 return err;
84 static void ssb_pcihost_remove(struct pci_dev *dev)
86 struct ssb_bus *ssb = pci_get_drvdata(dev);
88 ssb_bus_unregister(ssb);
89 pci_release_regions(dev);
90 pci_disable_device(dev);
91 kfree(ssb);
92 pci_set_drvdata(dev, NULL);
95 int ssb_pcihost_register(struct pci_driver *driver)
97 driver->probe = ssb_pcihost_probe;
98 driver->remove = ssb_pcihost_remove;
99 driver->suspend = ssb_pcihost_suspend;
100 driver->resume = ssb_pcihost_resume;
102 return pci_register_driver(driver);
104 EXPORT_SYMBOL(ssb_pcihost_register);