blob: 96c44ede5d69323fd314c2926e2394806090a7d8 [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
Haixia Shi737ba102016-08-30 14:50:21 -070014static int udl_usb_suspend(struct usb_interface *interface,
15 pm_message_t message)
16{
17 return 0;
18}
19
20static 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 Pinchart78b68552012-05-17 13:27:22 +020028static const struct vm_operations_struct udl_gem_vm_ops = {
Dave Airlie53209182010-12-15 07:14:24 +100029 .fault = udl_gem_fault,
30 .open = drm_gem_vm_open,
31 .close = drm_gem_vm_close,
32};
33
34static const struct file_operations udl_driver_fops = {
35 .owner = THIS_MODULE,
36 .open = drm_open,
Konstantin Khlebnikovfa9e8552012-03-31 13:29:25 +040037 .mmap = udl_drm_gem_mmap,
Dave Airlie53209182010-12-15 07:14:24 +100038 .poll = drm_poll,
39 .read = drm_read,
40 .unlocked_ioctl = drm_ioctl,
41 .release = drm_release,
Keith Packard804d74a2012-07-09 15:40:07 -070042 .compat_ioctl = drm_compat_ioctl,
Dave Airlie53209182010-12-15 07:14:24 +100043 .llseek = noop_llseek,
44};
45
46static struct drm_driver driver = {
Dave Airlie96503f52011-12-21 11:23:44 +000047 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
Dave Airlie53209182010-12-15 07:14:24 +100048 .load = udl_driver_load,
49 .unload = udl_driver_unload,
50
51 /* gem hooks */
Dave Airlie53209182010-12-15 07:14:24 +100052 .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 Vetter43387b32013-07-16 09:12:04 +020057 .dumb_destroy = drm_gem_dumb_destroy,
Dave Airlie53209182010-12-15 07:14:24 +100058 .fops = &udl_driver_fops,
Dave Airlie96503f52011-12-21 11:23:44 +000059
Haixia Shiebfdd6d2014-11-12 18:33:53 -080060 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
Dave Airlie96503f52011-12-21 11:23:44 +000061 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
Haixia Shiebfdd6d2014-11-12 18:33:53 -080062 .gem_prime_export = udl_gem_prime_export,
Dave Airlie96503f52011-12-21 11:23:44 +000063 .gem_prime_import = udl_gem_prime_import,
64
Dave Airlie53209182010-12-15 07:14:24 +100065 .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 Herrmannd4f68a72014-08-29 12:12:45 +020073static 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 Gundersen0f288602016-09-21 16:59:19 +020081 if (IS_ERR(dev))
82 return PTR_ERR(dev);
David Herrmannd4f68a72014-08-29 12:12:45 +020083
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
93err_free:
94 drm_dev_unref(dev);
95 return r;
96}
97
98static 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 Herrmannd4f68a72014-08-29 12:12:45 +0200103 udl_fbdev_unplug(dev);
104 udl_drop_usb(dev);
Daniel Vetterc07dcd62017-08-02 13:56:02 +0200105 drm_dev_unplug(dev);
David Herrmannd4f68a72014-08-29 12:12:45 +0200106}
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 */
115static 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};
125MODULE_DEVICE_TABLE(usb, id_table);
126
Dave Airlie53209182010-12-15 07:14:24 +1000127static struct usb_driver udl_driver = {
128 .name = "udl",
129 .probe = udl_usb_probe,
130 .disconnect = udl_usb_disconnect,
Haixia Shi737ba102016-08-30 14:50:21 -0700131 .suspend = udl_usb_suspend,
132 .resume = udl_usb_resume,
Dave Airlie53209182010-12-15 07:14:24 +1000133 .id_table = id_table,
134};
Amitoj Kaur Chawlaa6ddd2f12016-02-17 17:43:27 +0530135module_usb_driver(udl_driver);
David Herrmannd4f68a72014-08-29 12:12:45 +0200136MODULE_LICENSE("GPL");