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 <m@bues.ch>
11 * Licensed under the GNU/GPL. See COPYING for details.
15 #include <linux/pci.h>
16 #include <linux/export.h>
17 #include <linux/slab.h>
18 #include <linux/ssb/ssb.h>
21 #ifdef CONFIG_PM_SLEEP
22 static int ssb_pcihost_suspend(struct device
*d
)
24 struct pci_dev
*dev
= to_pci_dev(d
);
25 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
28 err
= ssb_bus_suspend(ssb
);
32 pci_disable_device(dev
);
34 /* if there is a wakeup enabled child device on ssb bus,
35 enable pci wakeup posibility. */
36 device_set_wakeup_enable(d
, d
->power
.wakeup_path
);
38 pci_prepare_to_sleep(dev
);
43 static int ssb_pcihost_resume(struct device
*d
)
45 struct pci_dev
*dev
= to_pci_dev(d
);
46 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
49 pci_back_from_sleep(dev
);
50 err
= pci_enable_device(dev
);
53 pci_restore_state(dev
);
54 err
= ssb_bus_resume(ssb
);
61 static const struct dev_pm_ops ssb_pcihost_pm_ops
= {
62 SET_SYSTEM_SLEEP_PM_OPS(ssb_pcihost_suspend
, ssb_pcihost_resume
)
65 #endif /* CONFIG_PM_SLEEP */
67 static int ssb_pcihost_probe(struct pci_dev
*dev
,
68 const struct pci_device_id
*id
)
75 ssb
= kzalloc(sizeof(*ssb
), GFP_KERNEL
);
78 err
= pci_enable_device(dev
);
81 name
= dev_name(&dev
->dev
);
82 if (dev
->driver
&& dev
->driver
->name
)
83 name
= dev
->driver
->name
;
84 err
= pci_request_regions(dev
, name
);
89 /* Disable the RETRY_TIMEOUT register (0x41) to keep
90 * PCI Tx retries from interfering with C3 CPU state */
91 pci_read_config_dword(dev
, 0x40, &val
);
92 if ((val
& 0x0000ff00) != 0)
93 pci_write_config_dword(dev
, 0x40, val
& 0xffff00ff);
95 err
= ssb_bus_pcibus_register(ssb
, dev
);
97 goto err_pci_release_regions
;
99 pci_set_drvdata(dev
, ssb
);
104 err_pci_release_regions
:
105 pci_release_regions(dev
);
107 pci_disable_device(dev
);
113 static void ssb_pcihost_remove(struct pci_dev
*dev
)
115 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
117 ssb_bus_unregister(ssb
);
118 pci_release_regions(dev
);
119 pci_disable_device(dev
);
121 pci_set_drvdata(dev
, NULL
);
124 int ssb_pcihost_register(struct pci_driver
*driver
)
126 driver
->probe
= ssb_pcihost_probe
;
127 driver
->remove
= ssb_pcihost_remove
;
128 #ifdef CONFIG_PM_SLEEP
129 driver
->driver
.pm
= &ssb_pcihost_pm_ops
;
132 return pci_register_driver(driver
);
134 EXPORT_SYMBOL(ssb_pcihost_register
);