drm_usb.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <drm/drmP.h>
  2. #include <drm/drm_usb.h>
  3. #include <linux/usb.h>
  4. #include <linux/module.h>
  5. int drm_get_usb_dev(struct usb_interface *interface,
  6. const struct usb_device_id *id,
  7. struct drm_driver *driver)
  8. {
  9. struct drm_device *dev;
  10. int ret;
  11. DRM_DEBUG("\n");
  12. dev = drm_dev_alloc(driver, &interface->dev);
  13. if (!dev)
  14. return -ENOMEM;
  15. dev->usbdev = interface_to_usbdev(interface);
  16. usb_set_intfdata(interface, dev);
  17. ret = drm_dev_register(dev, 0);
  18. if (ret)
  19. goto err_free;
  20. DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
  21. driver->name, driver->major, driver->minor, driver->patchlevel,
  22. driver->date, dev->primary->index);
  23. return 0;
  24. err_free:
  25. drm_dev_unref(dev);
  26. return ret;
  27. }
  28. EXPORT_SYMBOL(drm_get_usb_dev);
  29. static int drm_usb_set_busid(struct drm_device *dev,
  30. struct drm_master *master)
  31. {
  32. return 0;
  33. }
  34. static struct drm_bus drm_usb_bus = {
  35. .set_busid = drm_usb_set_busid,
  36. };
  37. /**
  38. * drm_usb_init - Register matching USB devices with the DRM subsystem
  39. * @driver: DRM device driver
  40. * @udriver: USB device driver
  41. *
  42. * Registers one or more devices matched by a USB driver with the DRM
  43. * subsystem.
  44. *
  45. * Return: 0 on success or a negative error code on failure.
  46. */
  47. int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver)
  48. {
  49. int res;
  50. DRM_DEBUG("\n");
  51. driver->bus = &drm_usb_bus;
  52. res = usb_register(udriver);
  53. return res;
  54. }
  55. EXPORT_SYMBOL(drm_usb_init);
  56. /**
  57. * drm_usb_exit - Unregister matching USB devices from the DRM subsystem
  58. * @driver: DRM device driver
  59. * @udriver: USB device driver
  60. *
  61. * Unregisters one or more devices matched by a USB driver from the DRM
  62. * subsystem.
  63. */
  64. void drm_usb_exit(struct drm_driver *driver,
  65. struct usb_driver *udriver)
  66. {
  67. usb_deregister(udriver);
  68. }
  69. EXPORT_SYMBOL(drm_usb_exit);
  70. MODULE_AUTHOR("David Airlie");
  71. MODULE_DESCRIPTION("USB DRM support");
  72. MODULE_LICENSE("GPL and additional rights");