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