1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012 Red Hat
6 #include <linux/module.h>
8 #include <drm/drm_drv.h>
9 #include <drm/drm_fbdev_shmem.h>
10 #include <drm/drm_file.h>
11 #include <drm/drm_gem_shmem_helper.h>
12 #include <drm/drm_managed.h>
13 #include <drm/drm_modeset_helper.h>
14 #include <drm/drm_ioctl.h>
15 #include <drm/drm_probe_helper.h>
16 #include <drm/drm_print.h>
20 static int udl_usb_suspend(struct usb_interface *interface,
23 struct drm_device *dev = usb_get_intfdata(interface);
26 ret = drm_mode_config_helper_suspend(dev);
30 udl_sync_pending_urbs(dev);
34 static int udl_usb_resume(struct usb_interface *interface)
36 struct drm_device *dev = usb_get_intfdata(interface);
38 return drm_mode_config_helper_resume(dev);
41 static int udl_usb_reset_resume(struct usb_interface *interface)
43 struct drm_device *dev = usb_get_intfdata(interface);
44 struct udl_device *udl = to_udl(dev);
46 udl_select_std_channel(udl);
48 return drm_mode_config_helper_resume(dev);
52 * FIXME: Dma-buf sharing requires DMA support by the importing device.
53 * This function is a workaround to make USB devices work as well.
54 * See todo.rst for how to fix the issue in the dma-buf framework.
56 static struct drm_gem_object *udl_driver_gem_prime_import(struct drm_device *dev,
57 struct dma_buf *dma_buf)
59 struct udl_device *udl = to_udl(dev);
62 return ERR_PTR(-ENODEV);
64 return drm_gem_prime_import_dev(dev, dma_buf, udl->dmadev);
67 DEFINE_DRM_GEM_FOPS(udl_driver_fops);
69 static const struct drm_driver driver = {
70 .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
73 .fops = &udl_driver_fops,
74 DRM_GEM_SHMEM_DRIVER_OPS,
75 .gem_prime_import = udl_driver_gem_prime_import,
80 .major = DRIVER_MAJOR,
81 .minor = DRIVER_MINOR,
82 .patchlevel = DRIVER_PATCHLEVEL,
85 static struct udl_device *udl_driver_create(struct usb_interface *interface)
87 struct udl_device *udl;
90 udl = devm_drm_dev_alloc(&interface->dev, &driver,
91 struct udl_device, drm);
99 usb_set_intfdata(interface, udl);
104 static int udl_usb_probe(struct usb_interface *interface,
105 const struct usb_device_id *id)
108 struct udl_device *udl;
110 udl = udl_driver_create(interface);
114 r = drm_dev_register(&udl->drm, 0);
118 DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
120 drm_fbdev_shmem_setup(&udl->drm, 0);
125 static void udl_usb_disconnect(struct usb_interface *interface)
127 struct drm_device *dev = usb_get_intfdata(interface);
129 drm_kms_helper_poll_fini(dev);
135 * There are many DisplayLink-based graphics products, all with unique PIDs.
136 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
137 * We also require a match on SubClass (0x00) and Protocol (0x00),
138 * which is compatible with all known USB 2.0 era graphics chips and firmware,
139 * but allows DisplayLink to increment those for any future incompatible chips
141 static const struct usb_device_id id_table[] = {
142 {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
143 .bInterfaceSubClass = 0x00,
144 .bInterfaceProtocol = 0x00,
145 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
146 USB_DEVICE_ID_MATCH_INT_CLASS |
147 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
148 USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
151 MODULE_DEVICE_TABLE(usb, id_table);
153 static struct usb_driver udl_driver = {
155 .probe = udl_usb_probe,
156 .disconnect = udl_usb_disconnect,
157 .suspend = udl_usb_suspend,
158 .resume = udl_usb_resume,
159 .reset_resume = udl_usb_reset_resume,
160 .id_table = id_table,
162 module_usb_driver(udl_driver);
163 MODULE_DESCRIPTION("KMS driver for the USB displaylink video adapters");
164 MODULE_LICENSE("GPL");