blob: 50bfc1b2f3bf56c0461532640b4437bc3c53c4ec [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
Shaohua Li75cde0e2006-02-08 17:11:40 +080033static int pcie_portdrv_save_config(struct pci_dev *dev)
long5823d102005-06-22 09:09:54 -070034{
Shaohua Li75cde0e2006-02-08 17:11:40 +080035 return pci_save_state(dev);
long5823d102005-06-22 09:09:54 -070036}
37
Greg Kroah-Hartman95a62962005-07-28 11:37:33 -070038static int pcie_portdrv_restore_config(struct pci_dev *dev)
long5823d102005-06-22 09:09:54 -070039{
Greg Kroah-Hartman95a62962005-07-28 11:37:33 -070040 int retval;
long5823d102005-06-22 09:09:54 -070041
42 pci_restore_state(dev);
Greg Kroah-Hartman95a62962005-07-28 11:37:33 -070043 retval = pci_enable_device(dev);
44 if (retval)
45 return retval;
long5823d102005-06-22 09:09:54 -070046 pci_set_master(dev);
Greg Kroah-Hartman95a62962005-07-28 11:37:33 -070047 return 0;
long5823d102005-06-22 09:09:54 -070048}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/*
51 * pcie_portdrv_probe - Probe PCI-Express port devices
52 * @dev: PCI-Express port device being probed
53 *
54 * If detected invokes the pcie_port_device_register() method for
55 * this port device.
56 *
57 */
58static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
59 const struct pci_device_id *id )
60{
61 int status;
62
63 status = pcie_port_device_probe(dev);
64 if (status)
65 return status;
66
67 if (pci_enable_device(dev) < 0)
68 return -ENODEV;
69
70 pci_set_master(dev);
71 if (!dev->irq) {
72 printk(KERN_WARNING
73 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
74 __FUNCTION__, dev->device, dev->vendor);
75 }
76 if (pcie_port_device_register(dev))
77 return -ENOMEM;
78
79 return 0;
80}
81
82static void pcie_portdrv_remove (struct pci_dev *dev)
83{
84 pcie_port_device_remove(dev);
long5823d102005-06-22 09:09:54 -070085 kfree(pci_get_drvdata(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
88#ifdef CONFIG_PM
Pavel Machek7f4927c2005-04-16 15:25:33 -070089static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
long5823d102005-06-22 09:09:54 -070091 int ret = pcie_port_device_suspend(dev, state);
92
Shaohua Li75cde0e2006-02-08 17:11:40 +080093 if (!ret)
94 ret = pcie_portdrv_save_config(dev);
long5823d102005-06-22 09:09:54 -070095 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98static int pcie_portdrv_resume (struct pci_dev *dev)
99{
long5823d102005-06-22 09:09:54 -0700100 pcie_portdrv_restore_config(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return pcie_port_device_resume(dev);
102}
103#endif
104
105/*
106 * LINUX Device Driver Model
107 */
108static const struct pci_device_id port_pci_ids[] = { {
109 /* handle any PCI-Express port */
110 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
111 }, { /* end: all zeroes */ }
112};
113MODULE_DEVICE_TABLE(pci, port_pci_ids);
114
115static struct pci_driver pcie_portdrv = {
116 .name = (char *)device_name,
117 .id_table = &port_pci_ids[0],
118
119 .probe = pcie_portdrv_probe,
120 .remove = pcie_portdrv_remove,
121
122#ifdef CONFIG_PM
123 .suspend = pcie_portdrv_suspend,
124 .resume = pcie_portdrv_resume,
125#endif /* PM */
126};
127
128static int __init pcie_portdrv_init(void)
129{
130 int retval = 0;
131
132 pcie_port_bus_register();
133 retval = pci_register_driver(&pcie_portdrv);
134 if (retval)
135 pcie_port_bus_unregister();
136 return retval;
137}
138
139static void __exit pcie_portdrv_exit(void)
140{
141 pci_unregister_driver(&pcie_portdrv);
142 pcie_port_bus_unregister();
143}
144
145module_init(pcie_portdrv_init);
146module_exit(pcie_portdrv_exit);