David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 1 | #include <drm/drmP.h> |
Rashika | 8eed55b | 2014-01-06 19:58:28 +0530 | [diff] [blame] | 2 | #include <drm/drm_usb.h> |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 3 | #include <linux/usb.h> |
Dave Airlie | b10c6d4 | 2012-04-19 09:33:32 +0100 | [diff] [blame] | 4 | #include <linux/module.h> |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 5 | |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 6 | int drm_get_usb_dev(struct usb_interface *interface, |
| 7 | const struct usb_device_id *id, |
| 8 | struct drm_driver *driver) |
| 9 | { |
| 10 | struct drm_device *dev; |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 11 | int ret; |
| 12 | |
| 13 | DRM_DEBUG("\n"); |
| 14 | |
David Herrmann | 1bb7253 | 2013-10-02 11:23:34 +0200 | [diff] [blame] | 15 | dev = drm_dev_alloc(driver, &interface->dev); |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 16 | if (!dev) |
| 17 | return -ENOMEM; |
| 18 | |
David Herrmann | 1bb7253 | 2013-10-02 11:23:34 +0200 | [diff] [blame] | 19 | dev->usbdev = interface_to_usbdev(interface); |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 20 | usb_set_intfdata(interface, dev); |
David Herrmann | c22f0ac | 2013-10-02 11:23:35 +0200 | [diff] [blame] | 21 | |
| 22 | ret = drm_dev_register(dev, 0); |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 23 | if (ret) |
David Herrmann | c22f0ac | 2013-10-02 11:23:35 +0200 | [diff] [blame] | 24 | goto err_free; |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 25 | |
| 26 | DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", |
| 27 | driver->name, driver->major, driver->minor, driver->patchlevel, |
| 28 | driver->date, dev->primary->index); |
| 29 | |
| 30 | return 0; |
| 31 | |
David Herrmann | c22f0ac | 2013-10-02 11:23:35 +0200 | [diff] [blame] | 32 | err_free: |
David Herrmann | 099d1c2 | 2014-01-29 10:21:36 +0100 | [diff] [blame] | 33 | drm_dev_unref(dev); |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 34 | return ret; |
| 35 | |
| 36 | } |
| 37 | EXPORT_SYMBOL(drm_get_usb_dev); |
| 38 | |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 39 | static int drm_usb_set_busid(struct drm_device *dev, |
| 40 | struct drm_master *master) |
| 41 | { |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static struct drm_bus drm_usb_bus = { |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 46 | .set_busid = drm_usb_set_busid, |
| 47 | }; |
Thierry Reding | c6a1af8a | 2014-05-19 13:39:07 +0200 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * drm_usb_init - Register matching USB devices with the DRM subsystem |
| 51 | * @driver: DRM device driver |
| 52 | * @udriver: USB device driver |
| 53 | * |
| 54 | * Registers one or more devices matched by a USB driver with the DRM |
| 55 | * subsystem. |
| 56 | * |
| 57 | * Return: 0 on success or a negative error code on failure. |
| 58 | */ |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 59 | int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver) |
| 60 | { |
| 61 | int res; |
| 62 | DRM_DEBUG("\n"); |
| 63 | |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 64 | driver->bus = &drm_usb_bus; |
| 65 | |
| 66 | res = usb_register(udriver); |
| 67 | return res; |
| 68 | } |
| 69 | EXPORT_SYMBOL(drm_usb_init); |
| 70 | |
Thierry Reding | c6a1af8a | 2014-05-19 13:39:07 +0200 | [diff] [blame] | 71 | /** |
| 72 | * drm_usb_exit - Unregister matching USB devices from the DRM subsystem |
| 73 | * @driver: DRM device driver |
| 74 | * @udriver: USB device driver |
| 75 | * |
| 76 | * Unregisters one or more devices matched by a USB driver from the DRM |
| 77 | * subsystem. |
| 78 | */ |
Dave Airlie | a250b9f | 2010-12-15 07:13:55 +1000 | [diff] [blame] | 79 | void drm_usb_exit(struct drm_driver *driver, |
| 80 | struct usb_driver *udriver) |
| 81 | { |
| 82 | usb_deregister(udriver); |
| 83 | } |
| 84 | EXPORT_SYMBOL(drm_usb_exit); |
Dave Airlie | b10c6d4 | 2012-04-19 09:33:32 +0100 | [diff] [blame] | 85 | |
| 86 | MODULE_AUTHOR("David Airlie"); |
| 87 | MODULE_DESCRIPTION("USB DRM support"); |
| 88 | MODULE_LICENSE("GPL and additional rights"); |