1 /* 2 * Copyright (C) 2012 Red Hat 3 * 4 * This file is subject to the terms and conditions of the GNU General Public 5 * License v2. See the file COPYING in the main directory of this archive for 6 * more details. 7 */ 8 9 #include <linux/module.h> 10 #include <drm/drmP.h> 11 #include <drm/drm_crtc_helper.h> 12 #include "udl_drv.h" 13 14 static int udl_driver_set_busid(struct drm_device *d, struct drm_master *m) 15 { 16 return 0; 17 } 18 19 static int udl_usb_suspend(struct usb_interface *interface, 20 pm_message_t message) 21 { 22 return 0; 23 } 24 25 static int udl_usb_resume(struct usb_interface *interface) 26 { 27 struct drm_device *dev = usb_get_intfdata(interface); 28 29 udl_modeset_restore(dev); 30 return 0; 31 } 32 33 static const struct vm_operations_struct udl_gem_vm_ops = { 34 .fault = udl_gem_fault, 35 .open = drm_gem_vm_open, 36 .close = drm_gem_vm_close, 37 }; 38 39 static const struct file_operations udl_driver_fops = { 40 .owner = THIS_MODULE, 41 .open = drm_open, 42 .mmap = udl_drm_gem_mmap, 43 .poll = drm_poll, 44 .read = drm_read, 45 .unlocked_ioctl = drm_ioctl, 46 .release = drm_release, 47 .compat_ioctl = drm_compat_ioctl, 48 .llseek = noop_llseek, 49 }; 50 51 static struct drm_driver driver = { 52 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, 53 .load = udl_driver_load, 54 .unload = udl_driver_unload, 55 .set_busid = udl_driver_set_busid, 56 57 /* gem hooks */ 58 .gem_free_object = udl_gem_free_object, 59 .gem_vm_ops = &udl_gem_vm_ops, 60 61 .dumb_create = udl_dumb_create, 62 .dumb_map_offset = udl_gem_mmap, 63 .dumb_destroy = drm_gem_dumb_destroy, 64 .fops = &udl_driver_fops, 65 66 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, 67 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, 68 .gem_prime_export = udl_gem_prime_export, 69 .gem_prime_import = udl_gem_prime_import, 70 71 .name = DRIVER_NAME, 72 .desc = DRIVER_DESC, 73 .date = DRIVER_DATE, 74 .major = DRIVER_MAJOR, 75 .minor = DRIVER_MINOR, 76 .patchlevel = DRIVER_PATCHLEVEL, 77 }; 78 79 static int udl_usb_probe(struct usb_interface *interface, 80 const struct usb_device_id *id) 81 { 82 struct usb_device *udev = interface_to_usbdev(interface); 83 struct drm_device *dev; 84 int r; 85 86 dev = drm_dev_alloc(&driver, &interface->dev); 87 if (IS_ERR(dev)) 88 return PTR_ERR(dev); 89 90 r = drm_dev_register(dev, (unsigned long)udev); 91 if (r) 92 goto err_free; 93 94 usb_set_intfdata(interface, dev); 95 DRM_INFO("Initialized udl on minor %d\n", dev->primary->index); 96 97 return 0; 98 99 err_free: 100 drm_dev_unref(dev); 101 return r; 102 } 103 104 static void udl_usb_disconnect(struct usb_interface *interface) 105 { 106 struct drm_device *dev = usb_get_intfdata(interface); 107 108 drm_kms_helper_poll_disable(dev); 109 udl_fbdev_unplug(dev); 110 udl_drop_usb(dev); 111 drm_unplug_dev(dev); 112 } 113 114 /* 115 * There are many DisplayLink-based graphics products, all with unique PIDs. 116 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff) 117 * We also require a match on SubClass (0x00) and Protocol (0x00), 118 * which is compatible with all known USB 2.0 era graphics chips and firmware, 119 * but allows DisplayLink to increment those for any future incompatible chips 120 */ 121 static struct usb_device_id id_table[] = { 122 {.idVendor = 0x17e9, .bInterfaceClass = 0xff, 123 .bInterfaceSubClass = 0x00, 124 .bInterfaceProtocol = 0x00, 125 .match_flags = USB_DEVICE_ID_MATCH_VENDOR | 126 USB_DEVICE_ID_MATCH_INT_CLASS | 127 USB_DEVICE_ID_MATCH_INT_SUBCLASS | 128 USB_DEVICE_ID_MATCH_INT_PROTOCOL,}, 129 {}, 130 }; 131 MODULE_DEVICE_TABLE(usb, id_table); 132 133 static struct usb_driver udl_driver = { 134 .name = "udl", 135 .probe = udl_usb_probe, 136 .disconnect = udl_usb_disconnect, 137 .suspend = udl_usb_suspend, 138 .resume = udl_usb_resume, 139 .id_table = id_table, 140 }; 141 module_usb_driver(udl_driver); 142 MODULE_LICENSE("GPL"); 143