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 <drm/drm_probe_helper.h> 13 #include "udl_drv.h" 14 15 static int udl_usb_suspend(struct usb_interface *interface, 16 pm_message_t message) 17 { 18 struct drm_device *dev = usb_get_intfdata(interface); 19 20 drm_kms_helper_poll_disable(dev); 21 return 0; 22 } 23 24 static int udl_usb_resume(struct usb_interface *interface) 25 { 26 struct drm_device *dev = usb_get_intfdata(interface); 27 28 drm_kms_helper_poll_enable(dev); 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 .release = udl_driver_release, 56 57 /* gem hooks */ 58 .gem_free_object_unlocked = 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 .fops = &udl_driver_fops, 64 65 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, 66 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, 67 .gem_prime_export = udl_gem_prime_export, 68 .gem_prime_import = udl_gem_prime_import, 69 70 .name = DRIVER_NAME, 71 .desc = DRIVER_DESC, 72 .date = DRIVER_DATE, 73 .major = DRIVER_MAJOR, 74 .minor = DRIVER_MINOR, 75 .patchlevel = DRIVER_PATCHLEVEL, 76 }; 77 78 static int udl_usb_probe(struct usb_interface *interface, 79 const struct usb_device_id *id) 80 { 81 struct usb_device *udev = interface_to_usbdev(interface); 82 struct drm_device *dev; 83 int r; 84 85 dev = drm_dev_alloc(&driver, &interface->dev); 86 if (IS_ERR(dev)) 87 return PTR_ERR(dev); 88 89 r = drm_dev_register(dev, (unsigned long)udev); 90 if (r) 91 goto err_free; 92 93 usb_set_intfdata(interface, dev); 94 DRM_INFO("Initialized udl on minor %d\n", dev->primary->index); 95 96 return 0; 97 98 err_free: 99 drm_dev_put(dev); 100 return r; 101 } 102 103 static void udl_usb_disconnect(struct usb_interface *interface) 104 { 105 struct drm_device *dev = usb_get_intfdata(interface); 106 107 drm_kms_helper_poll_disable(dev); 108 udl_fbdev_unplug(dev); 109 udl_drop_usb(dev); 110 drm_dev_unplug(dev); 111 } 112 113 /* 114 * There are many DisplayLink-based graphics products, all with unique PIDs. 115 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff) 116 * We also require a match on SubClass (0x00) and Protocol (0x00), 117 * which is compatible with all known USB 2.0 era graphics chips and firmware, 118 * but allows DisplayLink to increment those for any future incompatible chips 119 */ 120 static const struct usb_device_id id_table[] = { 121 {.idVendor = 0x17e9, .bInterfaceClass = 0xff, 122 .bInterfaceSubClass = 0x00, 123 .bInterfaceProtocol = 0x00, 124 .match_flags = USB_DEVICE_ID_MATCH_VENDOR | 125 USB_DEVICE_ID_MATCH_INT_CLASS | 126 USB_DEVICE_ID_MATCH_INT_SUBCLASS | 127 USB_DEVICE_ID_MATCH_INT_PROTOCOL,}, 128 {}, 129 }; 130 MODULE_DEVICE_TABLE(usb, id_table); 131 132 static struct usb_driver udl_driver = { 133 .name = "udl", 134 .probe = udl_usb_probe, 135 .disconnect = udl_usb_disconnect, 136 .suspend = udl_usb_suspend, 137 .resume = udl_usb_resume, 138 .id_table = id_table, 139 }; 140 module_usb_driver(udl_driver); 141 MODULE_LICENSE("GPL"); 142