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