port.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * usb port device code
  3. *
  4. * Copyright (C) 2012 Intel Corp
  5. *
  6. * Author: Lan Tianyu <tianyu.lan@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * for more details.
  16. *
  17. */
  18. #include "hub.h"
  19. static void usb_port_device_release(struct device *dev)
  20. {
  21. struct usb_port *port_dev = to_usb_port(dev);
  22. kfree(port_dev);
  23. }
  24. struct device_type usb_port_device_type = {
  25. .name = "usb_port",
  26. .release = usb_port_device_release,
  27. };
  28. int usb_hub_create_port_device(struct usb_hub *hub, int port1)
  29. {
  30. struct usb_port *port_dev = NULL;
  31. int retval;
  32. port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
  33. if (!port_dev) {
  34. retval = -ENOMEM;
  35. goto exit;
  36. }
  37. hub->ports[port1 - 1] = port_dev;
  38. port_dev->dev.parent = hub->intfdev;
  39. port_dev->dev.type = &usb_port_device_type;
  40. dev_set_name(&port_dev->dev, "port%d", port1);
  41. retval = device_register(&port_dev->dev);
  42. if (retval)
  43. goto error_register;
  44. return 0;
  45. error_register:
  46. put_device(&port_dev->dev);
  47. exit:
  48. return retval;
  49. }
  50. void usb_hub_remove_port_device(struct usb_hub *hub,
  51. int port1)
  52. {
  53. device_unregister(&hub->ports[port1 - 1]->dev);
  54. }