blob: 3ddd6cd98ac12d0d8cbf9124556f6688b677c9f8 [file] [log] [blame]
Dave Airlie53209182010-12-15 07:14:24 +10001/*
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 Howells760285e2012-10-02 18:01:07 +010010#include <drm/drm_usb.h>
11#include <drm/drm_crtc_helper.h>
Dave Airlie53209182010-12-15 07:14:24 +100012#include "udl_drv.h"
13
14static struct drm_driver driver;
15
Dave Airliee5a867a2012-06-16 07:41:28 +010016/*
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 Airlie53209182010-12-15 07:14:24 +100023static struct usb_device_id id_table[] = {
Dave Airliee5a867a2012-06-16 07:41:28 +010024 {.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 Airlie53209182010-12-15 07:14:24 +100031 {},
32};
33MODULE_DEVICE_TABLE(usb, id_table);
34
35MODULE_LICENSE("GPL");
36
37static 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
43static 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 Pinchart78b68552012-05-17 13:27:22 +020054static const struct vm_operations_struct udl_gem_vm_ops = {
Dave Airlie53209182010-12-15 07:14:24 +100055 .fault = udl_gem_fault,
56 .open = drm_gem_vm_open,
57 .close = drm_gem_vm_close,
58};
59
60static const struct file_operations udl_driver_fops = {
61 .owner = THIS_MODULE,
62 .open = drm_open,
Konstantin Khlebnikovfa9e8552012-03-31 13:29:25 +040063 .mmap = udl_drm_gem_mmap,
Dave Airlie53209182010-12-15 07:14:24 +100064 .poll = drm_poll,
65 .read = drm_read,
66 .unlocked_ioctl = drm_ioctl,
67 .release = drm_release,
Keith Packard804d74a2012-07-09 15:40:07 -070068#ifdef CONFIG_COMPAT
69 .compat_ioctl = drm_compat_ioctl,
70#endif
Dave Airlie53209182010-12-15 07:14:24 +100071 .llseek = noop_llseek,
72};
73
74static struct drm_driver driver = {
Dave Airlie96503f52011-12-21 11:23:44 +000075 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
Dave Airlie53209182010-12-15 07:14:24 +100076 .load = udl_driver_load,
77 .unload = udl_driver_unload,
78
79 /* gem hooks */
Dave Airlie53209182010-12-15 07:14:24 +100080 .gem_free_object = udl_gem_free_object,
81 .gem_vm_ops = &udl_gem_vm_ops,
82
83 .dumb_create = udl_dumb_create,
84 .dumb_map_offset = udl_gem_mmap,
Daniel Vetter43387b32013-07-16 09:12:04 +020085 .dumb_destroy = drm_gem_dumb_destroy,
Dave Airlie53209182010-12-15 07:14:24 +100086 .fops = &udl_driver_fops,
Dave Airlie96503f52011-12-21 11:23:44 +000087
88 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
89 .gem_prime_import = udl_gem_prime_import,
90
Dave Airlie53209182010-12-15 07:14:24 +100091 .name = DRIVER_NAME,
92 .desc = DRIVER_DESC,
93 .date = DRIVER_DATE,
94 .major = DRIVER_MAJOR,
95 .minor = DRIVER_MINOR,
96 .patchlevel = DRIVER_PATCHLEVEL,
97};
98
99static struct usb_driver udl_driver = {
100 .name = "udl",
101 .probe = udl_usb_probe,
102 .disconnect = udl_usb_disconnect,
103 .id_table = id_table,
104};
105
106static int __init udl_init(void)
107{
108 return drm_usb_init(&driver, &udl_driver);
109}
110
111static void __exit udl_exit(void)
112{
113 drm_usb_exit(&driver, &udl_driver);
114}
115
116module_init(udl_init);
117module_exit(udl_exit);