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.
14 #include <linux/pci.h>
15 #include <linux/export.h>
16 #include <linux/slab.h>
17 #include <linux/ssb/ssb.h>
21 static int ssb_pcihost_suspend(struct pci_dev
*dev
, pm_message_t state
)
23 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
26 err
= ssb_bus_suspend(ssb
);
30 pci_disable_device(dev
);
31 pci_set_power_state(dev
, pci_choose_state(dev
, state
));
36 static int ssb_pcihost_resume(struct pci_dev
*dev
)
38 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
41 pci_set_power_state(dev
, PCI_D0
);
42 err
= pci_enable_device(dev
);
45 pci_restore_state(dev
);
46 err
= ssb_bus_resume(ssb
);
53 # define ssb_pcihost_suspend NULL
54 # define ssb_pcihost_resume NULL
55 #endif /* CONFIG_PM */
57 static int ssb_pcihost_probe(struct pci_dev
*dev
,
58 const struct pci_device_id
*id
)
65 ssb
= kzalloc(sizeof(*ssb
), GFP_KERNEL
);
68 err
= pci_enable_device(dev
);
71 name
= dev_name(&dev
->dev
);
72 if (dev
->driver
&& dev
->driver
->name
)
73 name
= dev
->driver
->name
;
74 err
= pci_request_regions(dev
, name
);
79 /* Disable the RETRY_TIMEOUT register (0x41) to keep
80 * PCI Tx retries from interfering with C3 CPU state */
81 pci_read_config_dword(dev
, 0x40, &val
);
82 if ((val
& 0x0000ff00) != 0)
83 pci_write_config_dword(dev
, 0x40, val
& 0xffff00ff);
85 err
= ssb_bus_pcibus_register(ssb
, dev
);
87 goto err_pci_release_regions
;
89 pci_set_drvdata(dev
, ssb
);
94 err_pci_release_regions
:
95 pci_release_regions(dev
);
97 pci_disable_device(dev
);
103 static void ssb_pcihost_remove(struct pci_dev
*dev
)
105 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
107 ssb_bus_unregister(ssb
);
108 pci_release_regions(dev
);
109 pci_disable_device(dev
);
111 pci_set_drvdata(dev
, NULL
);
114 int ssb_pcihost_register(struct pci_driver
*driver
)
116 driver
->probe
= ssb_pcihost_probe
;
117 driver
->remove
= ssb_pcihost_remove
;
118 driver
->suspend
= ssb_pcihost_suspend
;
119 driver
->resume
= ssb_pcihost_resume
;
121 return pci_register_driver(driver
);
123 EXPORT_SYMBOL(ssb_pcihost_register
);