blob: 3cec30611417578591f165f61eb6e97c29f4c7a8 [file] [log] [blame]
David Howells760285e2012-10-02 18:01:07 +01001#include <drm/drmP.h>
Dave Airliea250b9f2010-12-15 07:13:55 +10002#include <linux/usb.h>
Dave Airlieb10c6d42012-04-19 09:33:32 +01003#include <linux/module.h>
Dave Airliea250b9f2010-12-15 07:13:55 +10004
Dave Airliea250b9f2010-12-15 07:13:55 +10005int 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 struct usb_device *usbdev;
11 int ret;
12
13 DRM_DEBUG("\n");
14
15 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
16 if (!dev)
17 return -ENOMEM;
18
19 usbdev = interface_to_usbdev(interface);
20 dev->usbdev = usbdev;
21 dev->dev = &usbdev->dev;
22
23 mutex_lock(&drm_global_mutex);
24
25 ret = drm_fill_in_dev(dev, NULL, driver);
26 if (ret) {
27 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
28 goto err_g1;
29 }
30
31 usb_set_intfdata(interface, dev);
32 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
33 if (ret)
34 goto err_g1;
35
36 ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY);
37 if (ret)
38 goto err_g2;
39
40 if (dev->driver->load) {
41 ret = dev->driver->load(dev, 0);
42 if (ret)
43 goto err_g3;
44 }
45
46 /* setup the grouping for the legacy output */
47 ret = drm_mode_group_init_legacy_group(dev,
48 &dev->primary->mode_group);
49 if (ret)
50 goto err_g3;
51
52 list_add_tail(&dev->driver_item, &driver->device_list);
53
54 mutex_unlock(&drm_global_mutex);
55
56 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
57 driver->name, driver->major, driver->minor, driver->patchlevel,
58 driver->date, dev->primary->index);
59
60 return 0;
61
62err_g3:
63 drm_put_minor(&dev->primary);
64err_g2:
65 drm_put_minor(&dev->control);
66err_g1:
67 kfree(dev);
68 mutex_unlock(&drm_global_mutex);
69 return ret;
70
71}
72EXPORT_SYMBOL(drm_get_usb_dev);
73
74static int drm_usb_get_irq(struct drm_device *dev)
75{
76 return 0;
77}
78
79static const char *drm_usb_get_name(struct drm_device *dev)
80{
81 return "USB";
82}
83
84static int drm_usb_set_busid(struct drm_device *dev,
85 struct drm_master *master)
86{
87 return 0;
88}
89
90static struct drm_bus drm_usb_bus = {
91 .bus_type = DRIVER_BUS_USB,
92 .get_irq = drm_usb_get_irq,
93 .get_name = drm_usb_get_name,
94 .set_busid = drm_usb_set_busid,
95};
96
97int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver)
98{
99 int res;
100 DRM_DEBUG("\n");
101
102 INIT_LIST_HEAD(&driver->device_list);
103 driver->kdriver.usb = udriver;
104 driver->bus = &drm_usb_bus;
105
106 res = usb_register(udriver);
107 return res;
108}
109EXPORT_SYMBOL(drm_usb_init);
110
111void drm_usb_exit(struct drm_driver *driver,
112 struct usb_driver *udriver)
113{
114 usb_deregister(udriver);
115}
116EXPORT_SYMBOL(drm_usb_exit);
Dave Airlieb10c6d42012-04-19 09:33:32 +0100117
118MODULE_AUTHOR("David Airlie");
119MODULE_DESCRIPTION("USB DRM support");
120MODULE_LICENSE("GPL and additional rights");