usb-acpi.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "usb.h"
  20. static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
  21. {
  22. struct usb_device *udev;
  23. struct device *parent;
  24. acpi_handle *parent_handle;
  25. if (!is_usb_device(dev))
  26. return -ENODEV;
  27. udev = to_usb_device(dev);
  28. parent = dev->parent;
  29. parent_handle = DEVICE_ACPI_HANDLE(parent);
  30. if (!parent_handle)
  31. return -ENODEV;
  32. *handle = acpi_get_child(parent_handle, udev->portnum);
  33. if (!*handle)
  34. return -ENODEV;
  35. return 0;
  36. }
  37. static struct acpi_bus_type usb_acpi_bus = {
  38. .bus = &usb_bus_type,
  39. .find_bridge = NULL,
  40. .find_device = usb_acpi_find_device,
  41. };
  42. int usb_acpi_register(void)
  43. {
  44. return register_acpi_bus_type(&usb_acpi_bus);
  45. }
  46. void usb_acpi_unregister(void)
  47. {
  48. unregister_acpi_bus_type(&usb_acpi_bus);
  49. }