blob: f2fe94aab901a8edbb6cbac827bad1e27a15b242 [file] [log] [blame]
David Howells760285e2012-10-02 18:01:07 +01001#include <drm/drmP.h>
Rashika8eed55b2014-01-06 19:58:28 +05302#include <drm/drm_usb.h>
Dave Airliea250b9f2010-12-15 07:13:55 +10003#include <linux/usb.h>
Dave Airlieb10c6d42012-04-19 09:33:32 +01004#include <linux/module.h>
Dave Airliea250b9f2010-12-15 07:13:55 +10005
Dave Airliea250b9f2010-12-15 07:13:55 +10006int 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 Airliea250b9f2010-12-15 07:13:55 +100011 int ret;
12
13 DRM_DEBUG("\n");
14
David Herrmann1bb72532013-10-02 11:23:34 +020015 dev = drm_dev_alloc(driver, &interface->dev);
Dave Airliea250b9f2010-12-15 07:13:55 +100016 if (!dev)
17 return -ENOMEM;
18
David Herrmann1bb72532013-10-02 11:23:34 +020019 dev->usbdev = interface_to_usbdev(interface);
Dave Airliea250b9f2010-12-15 07:13:55 +100020 usb_set_intfdata(interface, dev);
David Herrmannc22f0ac2013-10-02 11:23:35 +020021
22 ret = drm_dev_register(dev, 0);
Dave Airliea250b9f2010-12-15 07:13:55 +100023 if (ret)
David Herrmannc22f0ac2013-10-02 11:23:35 +020024 goto err_free;
Dave Airliea250b9f2010-12-15 07:13:55 +100025
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 Herrmannc22f0ac2013-10-02 11:23:35 +020032err_free:
David Herrmann099d1c22014-01-29 10:21:36 +010033 drm_dev_unref(dev);
Dave Airliea250b9f2010-12-15 07:13:55 +100034 return ret;
35
36}
37EXPORT_SYMBOL(drm_get_usb_dev);
38
Dave Airliea250b9f2010-12-15 07:13:55 +100039static int drm_usb_set_busid(struct drm_device *dev,
40 struct drm_master *master)
41{
42 return 0;
43}
44
45static struct drm_bus drm_usb_bus = {
Dave Airliea250b9f2010-12-15 07:13:55 +100046 .set_busid = drm_usb_set_busid,
47};
Thierry Redingc6a1af8a2014-05-19 13:39:07 +020048
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 Airliea250b9f2010-12-15 07:13:55 +100059int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver)
60{
61 int res;
62 DRM_DEBUG("\n");
63
Dave Airliea250b9f2010-12-15 07:13:55 +100064 driver->bus = &drm_usb_bus;
65
66 res = usb_register(udriver);
67 return res;
68}
69EXPORT_SYMBOL(drm_usb_init);
70
Thierry Redingc6a1af8a2014-05-19 13:39:07 +020071/**
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 Airliea250b9f2010-12-15 07:13:55 +100079void drm_usb_exit(struct drm_driver *driver,
80 struct usb_driver *udriver)
81{
82 usb_deregister(udriver);
83}
84EXPORT_SYMBOL(drm_usb_exit);
Dave Airlieb10c6d42012-04-19 09:33:32 +010085
86MODULE_AUTHOR("David Airlie");
87MODULE_DESCRIPTION("USB DRM support");
88MODULE_LICENSE("GPL and additional rights");