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> |
| 10 | #include "drm_usb.h" |
| 11 | #include "drm_crtc_helper.h" |
| 12 | #include "udl_drv.h" |
| 13 | |
| 14 | static struct drm_driver driver; |
| 15 | |
Dave Airlie | e5a867a | 2012-06-16 07:41:28 +0100 | [diff] [blame] | 16 | /* |
| 17 | * There are many DisplayLink-based graphics products, all with unique PIDs. |
| 18 | * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff) |
| 19 | * We also require a match on SubClass (0x00) and Protocol (0x00), |
| 20 | * which is compatible with all known USB 2.0 era graphics chips and firmware, |
| 21 | * but allows DisplayLink to increment those for any future incompatible chips |
| 22 | */ |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 23 | static struct usb_device_id id_table[] = { |
Dave Airlie | e5a867a | 2012-06-16 07:41:28 +0100 | [diff] [blame] | 24 | {.idVendor = 0x17e9, .bInterfaceClass = 0xff, |
| 25 | .bInterfaceSubClass = 0x00, |
| 26 | .bInterfaceProtocol = 0x00, |
| 27 | .match_flags = USB_DEVICE_ID_MATCH_VENDOR | |
| 28 | USB_DEVICE_ID_MATCH_INT_CLASS | |
| 29 | USB_DEVICE_ID_MATCH_INT_SUBCLASS | |
| 30 | USB_DEVICE_ID_MATCH_INT_PROTOCOL,}, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 31 | {}, |
| 32 | }; |
| 33 | MODULE_DEVICE_TABLE(usb, id_table); |
| 34 | |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
| 37 | static int udl_usb_probe(struct usb_interface *interface, |
| 38 | const struct usb_device_id *id) |
| 39 | { |
| 40 | return drm_get_usb_dev(interface, id, &driver); |
| 41 | } |
| 42 | |
| 43 | static void udl_usb_disconnect(struct usb_interface *interface) |
| 44 | { |
| 45 | struct drm_device *dev = usb_get_intfdata(interface); |
| 46 | |
| 47 | drm_kms_helper_poll_disable(dev); |
| 48 | drm_connector_unplug_all(dev); |
| 49 | udl_fbdev_unplug(dev); |
| 50 | udl_drop_usb(dev); |
| 51 | drm_unplug_dev(dev); |
| 52 | } |
| 53 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 54 | static const struct vm_operations_struct udl_gem_vm_ops = { |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 55 | .fault = udl_gem_fault, |
| 56 | .open = drm_gem_vm_open, |
| 57 | .close = drm_gem_vm_close, |
| 58 | }; |
| 59 | |
| 60 | static const struct file_operations udl_driver_fops = { |
| 61 | .owner = THIS_MODULE, |
| 62 | .open = drm_open, |
Konstantin Khlebnikov | fa9e855 | 2012-03-31 13:29:25 +0400 | [diff] [blame] | 63 | .mmap = udl_drm_gem_mmap, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 64 | .poll = drm_poll, |
| 65 | .read = drm_read, |
| 66 | .unlocked_ioctl = drm_ioctl, |
| 67 | .release = drm_release, |
| 68 | .fasync = drm_fasync, |
| 69 | .llseek = noop_llseek, |
| 70 | }; |
| 71 | |
| 72 | static struct drm_driver driver = { |
Dave Airlie | 96503f5 | 2011-12-21 11:23:44 +0000 | [diff] [blame] | 73 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 74 | .load = udl_driver_load, |
| 75 | .unload = udl_driver_unload, |
| 76 | |
| 77 | /* gem hooks */ |
| 78 | .gem_init_object = udl_gem_init_object, |
| 79 | .gem_free_object = udl_gem_free_object, |
| 80 | .gem_vm_ops = &udl_gem_vm_ops, |
| 81 | |
| 82 | .dumb_create = udl_dumb_create, |
| 83 | .dumb_map_offset = udl_gem_mmap, |
| 84 | .dumb_destroy = udl_dumb_destroy, |
| 85 | .fops = &udl_driver_fops, |
Dave Airlie | 96503f5 | 2011-12-21 11:23:44 +0000 | [diff] [blame] | 86 | |
| 87 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 88 | .gem_prime_import = udl_gem_prime_import, |
| 89 | |
Dave Airlie | 5320918 | 2010-12-15 07:14:24 +1000 | [diff] [blame] | 90 | .name = DRIVER_NAME, |
| 91 | .desc = DRIVER_DESC, |
| 92 | .date = DRIVER_DATE, |
| 93 | .major = DRIVER_MAJOR, |
| 94 | .minor = DRIVER_MINOR, |
| 95 | .patchlevel = DRIVER_PATCHLEVEL, |
| 96 | }; |
| 97 | |
| 98 | static struct usb_driver udl_driver = { |
| 99 | .name = "udl", |
| 100 | .probe = udl_usb_probe, |
| 101 | .disconnect = udl_usb_disconnect, |
| 102 | .id_table = id_table, |
| 103 | }; |
| 104 | |
| 105 | static int __init udl_init(void) |
| 106 | { |
| 107 | return drm_usb_init(&driver, &udl_driver); |
| 108 | } |
| 109 | |
| 110 | static void __exit udl_exit(void) |
| 111 | { |
| 112 | drm_usb_exit(&driver, &udl_driver); |
| 113 | } |
| 114 | |
| 115 | module_init(udl_init); |
| 116 | module_exit(udl_exit); |