cab5cb7c256cdb513a957245e80c0be935616fe6
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / usb / core / usb-acpi.c
1 /*
2 * USB-ACPI glue code
3 *
4 * Copyright 2012 Red Hat <mjg@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
9 *
10 */
11 #include <linux/module.h>
12 #include <linux/usb.h>
13 #include <linux/device.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/acpi.h>
17 #include <linux/pci.h>
18 #include <acpi/acpi_bus.h>
19
20 #include "usb.h"
21
22 static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
23 {
24 struct usb_device *udev;
25 struct device *parent;
26 acpi_handle *parent_handle;
27
28 if (!is_usb_device(dev))
29 return -ENODEV;
30
31 udev = to_usb_device(dev);
32 parent = dev->parent;
33 parent_handle = DEVICE_ACPI_HANDLE(parent);
34
35 if (!parent_handle)
36 return -ENODEV;
37
38 *handle = acpi_get_child(parent_handle, udev->portnum);
39
40 if (!*handle)
41 return -ENODEV;
42
43 return 0;
44 }
45
46 static struct acpi_bus_type usb_acpi_bus = {
47 .bus = &usb_bus_type,
48 .find_bridge = NULL,
49 .find_device = usb_acpi_find_device,
50 };
51
52 int usb_acpi_register(void)
53 {
54 return register_acpi_bus_type(&usb_acpi_bus);
55 }
56
57 void usb_acpi_unregister(void)
58 {
59 unregister_acpi_bus_type(&usb_acpi_bus);
60 }