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/slab.h>
16 #include <linux/ssb/ssb.h>
20 static int ssb_pcihost_suspend(struct pci_dev
*dev
, pm_message_t state
)
22 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
25 err
= ssb_bus_suspend(ssb
);
29 pci_disable_device(dev
);
30 pci_set_power_state(dev
, pci_choose_state(dev
, state
));
35 static int ssb_pcihost_resume(struct pci_dev
*dev
)
37 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
40 pci_set_power_state(dev
, 0);
41 err
= pci_enable_device(dev
);
44 pci_restore_state(dev
);
45 err
= ssb_bus_resume(ssb
);
52 # define ssb_pcihost_suspend NULL
53 # define ssb_pcihost_resume NULL
54 #endif /* CONFIG_PM */
56 static int ssb_pcihost_probe(struct pci_dev
*dev
,
57 const struct pci_device_id
*id
)
64 ssb
= kzalloc(sizeof(*ssb
), GFP_KERNEL
);
67 err
= pci_enable_device(dev
);
70 name
= dev_name(&dev
->dev
);
71 if (dev
->driver
&& dev
->driver
->name
)
72 name
= dev
->driver
->name
;
73 err
= pci_request_regions(dev
, name
);
78 /* Disable the RETRY_TIMEOUT register (0x41) to keep
79 * PCI Tx retries from interfering with C3 CPU state */
80 pci_read_config_dword(dev
, 0x40, &val
);
81 if ((val
& 0x0000ff00) != 0)
82 pci_write_config_dword(dev
, 0x40, val
& 0xffff00ff);
84 err
= ssb_bus_pcibus_register(ssb
, dev
);
86 goto err_pci_release_regions
;
88 pci_set_drvdata(dev
, ssb
);
93 err_pci_release_regions
:
94 pci_release_regions(dev
);
96 pci_disable_device(dev
);
102 static void ssb_pcihost_remove(struct pci_dev
*dev
)
104 struct ssb_bus
*ssb
= pci_get_drvdata(dev
);
106 ssb_bus_unregister(ssb
);
107 pci_release_regions(dev
);
108 pci_disable_device(dev
);
110 pci_set_drvdata(dev
, NULL
);
113 int ssb_pcihost_register(struct pci_driver
*driver
)
115 driver
->probe
= ssb_pcihost_probe
;
116 driver
->remove
= ssb_pcihost_remove
;
117 driver
->suspend
= ssb_pcihost_suspend
;
118 driver
->resume
= ssb_pcihost_resume
;
120 return pci_register_driver(driver
);
122 EXPORT_SYMBOL(ssb_pcihost_register
);