blob: 3284199ce3969557126d54ef7e5d5371aded3a8c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File: portdrv_pci.c
3 * Purpose: PCI Express Port Bus Driver
4 *
5 * Copyright (C) 2004 Intel
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */
8
9#include <linux/module.h>
10#include <linux/pci.h>
11#include <linux/kernel.h>
12#include <linux/errno.h>
13#include <linux/pm.h>
14#include <linux/init.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/pcieport_if.h>
17
18#include "portdrv.h"
19
20/*
21 * Version Information
22 */
23#define DRIVER_VERSION "v1.0"
24#define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
25#define DRIVER_DESC "PCIE Port Bus Driver"
26MODULE_AUTHOR(DRIVER_AUTHOR);
27MODULE_DESCRIPTION(DRIVER_DESC);
28MODULE_LICENSE("GPL");
29
30/* global data */
31static const char device_name[] = "pcieport-driver";
32
33/*
34 * pcie_portdrv_probe - Probe PCI-Express port devices
35 * @dev: PCI-Express port device being probed
36 *
37 * If detected invokes the pcie_port_device_register() method for
38 * this port device.
39 *
40 */
41static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
42 const struct pci_device_id *id )
43{
44 int status;
45
46 status = pcie_port_device_probe(dev);
47 if (status)
48 return status;
49
50 if (pci_enable_device(dev) < 0)
51 return -ENODEV;
52
53 pci_set_master(dev);
54 if (!dev->irq) {
55 printk(KERN_WARNING
56 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
57 __FUNCTION__, dev->device, dev->vendor);
58 }
Randy Dunlape4fd1f42006-07-06 21:36:01 -070059 if (pcie_port_device_register(dev)) {
60 pci_disable_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return -ENOMEM;
Randy Dunlape4fd1f42006-07-06 21:36:01 -070062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 return 0;
65}
66
67static void pcie_portdrv_remove (struct pci_dev *dev)
68{
69 pcie_port_device_remove(dev);
long5823d102005-06-22 09:09:54 -070070 kfree(pci_get_drvdata(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73#ifdef CONFIG_PM
Henrik Kretzschmar60854832006-07-06 18:05:51 +040074static int pcie_portdrv_save_config(struct pci_dev *dev)
75{
76 return pci_save_state(dev);
77}
78
79static int pcie_portdrv_restore_config(struct pci_dev *dev)
80{
81 int retval;
82
83 pci_restore_state(dev);
84 retval = pci_enable_device(dev);
85 if (retval)
86 return retval;
87 pci_set_master(dev);
88 return 0;
89}
90
Pavel Machek7f4927c2005-04-16 15:25:33 -070091static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
long5823d102005-06-22 09:09:54 -070093 int ret = pcie_port_device_suspend(dev, state);
94
Shaohua Li75cde0e2006-02-08 17:11:40 +080095 if (!ret)
96 ret = pcie_portdrv_save_config(dev);
long5823d102005-06-22 09:09:54 -070097 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
100static int pcie_portdrv_resume (struct pci_dev *dev)
101{
long5823d102005-06-22 09:09:54 -0700102 pcie_portdrv_restore_config(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return pcie_port_device_resume(dev);
104}
105#endif
106
107/*
108 * LINUX Device Driver Model
109 */
110static const struct pci_device_id port_pci_ids[] = { {
111 /* handle any PCI-Express port */
112 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
113 }, { /* end: all zeroes */ }
114};
115MODULE_DEVICE_TABLE(pci, port_pci_ids);
116
117static struct pci_driver pcie_portdrv = {
118 .name = (char *)device_name,
119 .id_table = &port_pci_ids[0],
120
121 .probe = pcie_portdrv_probe,
122 .remove = pcie_portdrv_remove,
123
124#ifdef CONFIG_PM
125 .suspend = pcie_portdrv_suspend,
126 .resume = pcie_portdrv_resume,
127#endif /* PM */
128};
129
130static int __init pcie_portdrv_init(void)
131{
Randy Dunlap20d51662006-07-08 22:58:25 -0700132 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Randy Dunlap20d51662006-07-08 22:58:25 -0700134 retval = pcie_port_bus_register();
135 if (retval) {
136 printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
137 goto out;
138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 retval = pci_register_driver(&pcie_portdrv);
140 if (retval)
141 pcie_port_bus_unregister();
Randy Dunlap20d51662006-07-08 22:58:25 -0700142 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return retval;
144}
145
146static void __exit pcie_portdrv_exit(void)
147{
148 pci_unregister_driver(&pcie_portdrv);
149 pcie_port_bus_unregister();
150}
151
152module_init(pcie_portdrv_init);
153module_exit(pcie_portdrv_exit);