Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 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> |
David Herrmann | d4f68a7 | 2014-08-29 12:12:45 +0200 | [diff] [blame] | 10 | #include <drm/drmP.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 11 | #include <drm/drm_crtc_helper.h> |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 12 | #include "udl_drv.h" |
| 13 | |
Haixia Shi | 737ba10 | 2016-08-30 14:50:21 -0700 | [diff] [blame] | 14 | static int udl_usb_suspend(struct usb_interface *interface, |
| 15 | pm_message_t message) |
| 16 | { |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | static int udl_usb_resume(struct usb_interface *interface) |
| 21 | { |
| 22 | struct drm_device *dev = usb_get_intfdata(interface); |
| 23 | |
| 24 | udl_modeset_restore(dev); |
| 25 | return 0; |
| 26 | } |
| 27 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 28 | static const struct vm_operations_struct udl_gem_vm_ops = { |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 29 | .fault = udl_gem_fault, |
| 30 | .open = drm_gem_vm_open, |
| 31 | .close = drm_gem_vm_close, |
| 32 | }; |
| 33 | |
| 34 | static const struct file_operations udl_driver_fops = { |
| 35 | .owner = THIS_MODULE, |
| 36 | .open = drm_open, |
Konstantin Khlebnikov | fa9e855 | 2012-03-31 13:29:25 +0400 | [diff] [blame] | 37 | .mmap = udl_drm_gem_mmap, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 38 | .poll = drm_poll, |
| 39 | .read = drm_read, |
| 40 | .unlocked_ioctl = drm_ioctl, |
| 41 | .release = drm_release, |
Keith Packard | 804d74a | 2012-07-09 15:40:07 -0700 | [diff] [blame] | 42 | .compat_ioctl = drm_compat_ioctl, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 43 | .llseek = noop_llseek, |
| 44 | }; |
| 45 | |
| 46 | static struct drm_driver driver = { |
Dave Airlie | 96503f5 | 2011-12-21 11:23:44 +0000 | [diff] [blame] | 47 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 48 | .load = udl_driver_load, |
| 49 | .unload = udl_driver_unload, |
| 50 | |
| 51 | /* gem hooks */ |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 52 | .gem_free_object = udl_gem_free_object, |
| 53 | .gem_vm_ops = &udl_gem_vm_ops, |
| 54 | |
| 55 | .dumb_create = udl_dumb_create, |
| 56 | .dumb_map_offset = udl_gem_mmap, |
Daniel Vetter | 43387b3 | 2013-07-16 09:12:04 +0200 | [diff] [blame] | 57 | .dumb_destroy = drm_gem_dumb_destroy, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 58 | .fops = &udl_driver_fops, |
Dave Airlie | 96503f5 | 2011-12-21 11:23:44 +0000 | [diff] [blame] | 59 | |
Haixia Shi | ebfdd6d | 2014-11-12 18:33:53 -0800 | [diff] [blame] | 60 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
Dave Airlie | 96503f5 | 2011-12-21 11:23:44 +0000 | [diff] [blame] | 61 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Haixia Shi | ebfdd6d | 2014-11-12 18:33:53 -0800 | [diff] [blame] | 62 | .gem_prime_export = udl_gem_prime_export, |
Dave Airlie | 96503f5 | 2011-12-21 11:23:44 +0000 | [diff] [blame] | 63 | .gem_prime_import = udl_gem_prime_import, |
| 64 | |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 65 | .name = DRIVER_NAME, |
| 66 | .desc = DRIVER_DESC, |
| 67 | .date = DRIVER_DATE, |
| 68 | .major = DRIVER_MAJOR, |
| 69 | .minor = DRIVER_MINOR, |
| 70 | .patchlevel = DRIVER_PATCHLEVEL, |
| 71 | }; |
| 72 | |
David Herrmann | d4f68a7 | 2014-08-29 12:12:45 +0200 | [diff] [blame] | 73 | static int udl_usb_probe(struct usb_interface *interface, |
| 74 | const struct usb_device_id *id) |
| 75 | { |
| 76 | struct usb_device *udev = interface_to_usbdev(interface); |
| 77 | struct drm_device *dev; |
| 78 | int r; |
| 79 | |
| 80 | dev = drm_dev_alloc(&driver, &interface->dev); |
Tom Gundersen | 0f28860 | 2016-09-21 16:59:19 +0200 | [diff] [blame] | 81 | if (IS_ERR(dev)) |
| 82 | return PTR_ERR(dev); |
David Herrmann | d4f68a7 | 2014-08-29 12:12:45 +0200 | [diff] [blame] | 83 | |
| 84 | r = drm_dev_register(dev, (unsigned long)udev); |
| 85 | if (r) |
| 86 | goto err_free; |
| 87 | |
| 88 | usb_set_intfdata(interface, dev); |
| 89 | DRM_INFO("Initialized udl on minor %d\n", dev->primary->index); |
| 90 | |
| 91 | return 0; |
| 92 | |
| 93 | err_free: |
| 94 | drm_dev_unref(dev); |
| 95 | return r; |
| 96 | } |
| 97 | |
| 98 | static void udl_usb_disconnect(struct usb_interface *interface) |
| 99 | { |
| 100 | struct drm_device *dev = usb_get_intfdata(interface); |
| 101 | |
| 102 | drm_kms_helper_poll_disable(dev); |
David Herrmann | d4f68a7 | 2014-08-29 12:12:45 +0200 | [diff] [blame] | 103 | udl_fbdev_unplug(dev); |
| 104 | udl_drop_usb(dev); |
Daniel Vetter | c07dcd6 | 2017-08-02 13:56:02 +0200 | [diff] [blame^] | 105 | drm_dev_unplug(dev); |
David Herrmann | d4f68a7 | 2014-08-29 12:12:45 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* |
| 109 | * There are many DisplayLink-based graphics products, all with unique PIDs. |
| 110 | * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff) |
| 111 | * We also require a match on SubClass (0x00) and Protocol (0x00), |
| 112 | * which is compatible with all known USB 2.0 era graphics chips and firmware, |
| 113 | * but allows DisplayLink to increment those for any future incompatible chips |
| 114 | */ |
| 115 | static struct usb_device_id id_table[] = { |
| 116 | {.idVendor = 0x17e9, .bInterfaceClass = 0xff, |
| 117 | .bInterfaceSubClass = 0x00, |
| 118 | .bInterfaceProtocol = 0x00, |
| 119 | .match_flags = USB_DEVICE_ID_MATCH_VENDOR | |
| 120 | USB_DEVICE_ID_MATCH_INT_CLASS | |
| 121 | USB_DEVICE_ID_MATCH_INT_SUBCLASS | |
| 122 | USB_DEVICE_ID_MATCH_INT_PROTOCOL,}, |
| 123 | {}, |
| 124 | }; |
| 125 | MODULE_DEVICE_TABLE(usb, id_table); |
| 126 | |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 127 | static struct usb_driver udl_driver = { |
| 128 | .name = "udl", |
| 129 | .probe = udl_usb_probe, |
| 130 | .disconnect = udl_usb_disconnect, |
Haixia Shi | 737ba10 | 2016-08-30 14:50:21 -0700 | [diff] [blame] | 131 | .suspend = udl_usb_suspend, |
| 132 | .resume = udl_usb_resume, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 133 | .id_table = id_table, |
| 134 | }; |
Amitoj Kaur Chawla | a6ddd2f1 | 2016-02-17 17:43:27 +0530 | [diff] [blame] | 135 | module_usb_driver(udl_driver); |
David Herrmann | d4f68a7 | 2014-08-29 12:12:45 +0200 | [diff] [blame] | 136 | MODULE_LICENSE("GPL"); |