blob: 8607e9e513db0d94129ea524b9a4abe5dd9653af [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 Herrmannd4f68a72014-08-29 12:12:45 +020010#include <drm/drmP.h>
David Howells760285e2012-10-02 18:01:07 +010011#include <drm/drm_crtc_helper.h>
Dave Airlie53209182010-12-15 07:14:24 +100012#include "udl_drv.h"
13
David Herrmann915b4d12014-08-29 12:12:43 +020014static int udl_driver_set_busid(struct drm_device *d, struct drm_master *m)
15{
16 return 0;
17}
18
Laurent Pinchart78b68552012-05-17 13:27:22 +020019static const struct vm_operations_struct udl_gem_vm_ops = {
Dave Airlie53209182010-12-15 07:14:24 +100020 .fault = udl_gem_fault,
21 .open = drm_gem_vm_open,
22 .close = drm_gem_vm_close,
23};
24
25static const struct file_operations udl_driver_fops = {
26 .owner = THIS_MODULE,
27 .open = drm_open,
Konstantin Khlebnikovfa9e8552012-03-31 13:29:25 +040028 .mmap = udl_drm_gem_mmap,
Dave Airlie53209182010-12-15 07:14:24 +100029 .poll = drm_poll,
30 .read = drm_read,
31 .unlocked_ioctl = drm_ioctl,
32 .release = drm_release,
Keith Packard804d74a2012-07-09 15:40:07 -070033#ifdef CONFIG_COMPAT
34 .compat_ioctl = drm_compat_ioctl,
35#endif
Dave Airlie53209182010-12-15 07:14:24 +100036 .llseek = noop_llseek,
37};
38
39static struct drm_driver driver = {
Dave Airlie96503f52011-12-21 11:23:44 +000040 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
Dave Airlie53209182010-12-15 07:14:24 +100041 .load = udl_driver_load,
42 .unload = udl_driver_unload,
David Herrmann915b4d12014-08-29 12:12:43 +020043 .set_busid = udl_driver_set_busid,
Dave Airlie53209182010-12-15 07:14:24 +100044
45 /* gem hooks */
Dave Airlie53209182010-12-15 07:14:24 +100046 .gem_free_object = udl_gem_free_object,
47 .gem_vm_ops = &udl_gem_vm_ops,
48
49 .dumb_create = udl_dumb_create,
50 .dumb_map_offset = udl_gem_mmap,
Daniel Vetter43387b32013-07-16 09:12:04 +020051 .dumb_destroy = drm_gem_dumb_destroy,
Dave Airlie53209182010-12-15 07:14:24 +100052 .fops = &udl_driver_fops,
Dave Airlie96503f52011-12-21 11:23:44 +000053
54 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
55 .gem_prime_import = udl_gem_prime_import,
56
Dave Airlie53209182010-12-15 07:14:24 +100057 .name = DRIVER_NAME,
58 .desc = DRIVER_DESC,
59 .date = DRIVER_DATE,
60 .major = DRIVER_MAJOR,
61 .minor = DRIVER_MINOR,
62 .patchlevel = DRIVER_PATCHLEVEL,
63};
64
David Herrmannd4f68a72014-08-29 12:12:45 +020065static int udl_usb_probe(struct usb_interface *interface,
66 const struct usb_device_id *id)
67{
68 struct usb_device *udev = interface_to_usbdev(interface);
69 struct drm_device *dev;
70 int r;
71
72 dev = drm_dev_alloc(&driver, &interface->dev);
73 if (!dev)
74 return -ENOMEM;
75
76 r = drm_dev_register(dev, (unsigned long)udev);
77 if (r)
78 goto err_free;
79
80 usb_set_intfdata(interface, dev);
81 DRM_INFO("Initialized udl on minor %d\n", dev->primary->index);
82
83 return 0;
84
85err_free:
86 drm_dev_unref(dev);
87 return r;
88}
89
90static void udl_usb_disconnect(struct usb_interface *interface)
91{
92 struct drm_device *dev = usb_get_intfdata(interface);
93
94 drm_kms_helper_poll_disable(dev);
95 drm_connector_unplug_all(dev);
96 udl_fbdev_unplug(dev);
97 udl_drop_usb(dev);
98 drm_unplug_dev(dev);
99}
100
101/*
102 * There are many DisplayLink-based graphics products, all with unique PIDs.
103 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
104 * We also require a match on SubClass (0x00) and Protocol (0x00),
105 * which is compatible with all known USB 2.0 era graphics chips and firmware,
106 * but allows DisplayLink to increment those for any future incompatible chips
107 */
108static struct usb_device_id id_table[] = {
109 {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
110 .bInterfaceSubClass = 0x00,
111 .bInterfaceProtocol = 0x00,
112 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
113 USB_DEVICE_ID_MATCH_INT_CLASS |
114 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
115 USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
116 {},
117};
118MODULE_DEVICE_TABLE(usb, id_table);
119
Dave Airlie53209182010-12-15 07:14:24 +1000120static struct usb_driver udl_driver = {
121 .name = "udl",
122 .probe = udl_usb_probe,
123 .disconnect = udl_usb_disconnect,
124 .id_table = id_table,
125};
126
127static int __init udl_init(void)
128{
David Herrmannd4f68a72014-08-29 12:12:45 +0200129 return usb_register(&udl_driver);
Dave Airlie53209182010-12-15 07:14:24 +1000130}
131
132static void __exit udl_exit(void)
133{
David Herrmannd4f68a72014-08-29 12:12:45 +0200134 usb_deregister(&udl_driver);
Dave Airlie53209182010-12-15 07:14:24 +1000135}
136
137module_init(udl_init);
138module_exit(udl_exit);
David Herrmannd4f68a72014-08-29 12:12:45 +0200139MODULE_LICENSE("GPL");