Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / pci / pcie / portdrv_bus.c
1 /*
2 * File: portdrv_bus.c
3 * Purpose: PCI Express Port Bus Driver's Bus Overloading Functions
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
15 #include <linux/pcieport_if.h>
16 #include "portdrv.h"
17
18 static int pcie_port_bus_match(struct device *dev, struct device_driver *drv);
19
20 struct bus_type pcie_port_bus_type = {
21 .name = "pci_express",
22 .match = pcie_port_bus_match,
23 };
24 EXPORT_SYMBOL_GPL(pcie_port_bus_type);
25
26 static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
27 {
28 struct pcie_device *pciedev;
29 struct pcie_port_data *port_data;
30 struct pcie_port_service_driver *driver;
31
32 if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)
33 return 0;
34
35 pciedev = to_pcie_device(dev);
36 driver = to_service_driver(drv);
37
38 if (driver->service != pciedev->service)
39 return 0;
40
41 port_data = pci_get_drvdata(pciedev->port);
42
43 if (driver->port_type != PCIE_ANY_PORT
44 && driver->port_type != port_data->port_type)
45 return 0;
46
47 return 1;
48 }
49
50 int pcie_port_bus_register(void)
51 {
52 return bus_register(&pcie_port_bus_type);
53 }
54
55 void pcie_port_bus_unregister(void)
56 {
57 bus_unregister(&pcie_port_bus_type);
58 }