1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012 Red Hat
6 #include <linux/module.h>
8 #include <drm/drm_crtc_helper.h>
9 #include <drm/drm_drv.h>
10 #include <drm/drm_fb_helper.h>
11 #include <drm/drm_file.h>
12 #include <drm/drm_gem_shmem_helper.h>
13 #include <drm/drm_managed.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);
25 return drm_mode_config_helper_suspend(dev);
28 static int udl_usb_resume(struct usb_interface *interface)
30 struct drm_device *dev = usb_get_intfdata(interface);
32 return drm_mode_config_helper_resume(dev);
35 DEFINE_DRM_GEM_FOPS(udl_driver_fops);
37 static struct drm_driver driver = {
38 .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
41 .gem_create_object = udl_driver_gem_create_object,
43 .fops = &udl_driver_fops,
44 DRM_GEM_SHMEM_DRIVER_OPS,
49 .major = DRIVER_MAJOR,
50 .minor = DRIVER_MINOR,
51 .patchlevel = DRIVER_PATCHLEVEL,
54 static struct udl_device *udl_driver_create(struct usb_interface *interface)
56 struct usb_device *udev = interface_to_usbdev(interface);
57 struct udl_device *udl;
60 udl = kzalloc(sizeof(*udl), GFP_KERNEL);
62 return ERR_PTR(-ENOMEM);
64 r = drm_dev_init(&udl->drm, &driver, &interface->dev);
71 udl->drm.dev_private = udl;
72 drmm_add_final_kfree(&udl->drm, udl);
76 drm_dev_put(&udl->drm);
80 usb_set_intfdata(interface, udl);
84 static int udl_usb_probe(struct usb_interface *interface,
85 const struct usb_device_id *id)
88 struct udl_device *udl;
90 udl = udl_driver_create(interface);
94 r = drm_dev_register(&udl->drm, 0);
98 DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
100 drm_fbdev_generic_setup(&udl->drm, 0);
105 drm_dev_put(&udl->drm);
109 static void udl_usb_disconnect(struct usb_interface *interface)
111 struct drm_device *dev = usb_get_intfdata(interface);
113 drm_kms_helper_poll_fini(dev);
120 * There are many DisplayLink-based graphics products, all with unique PIDs.
121 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
122 * We also require a match on SubClass (0x00) and Protocol (0x00),
123 * which is compatible with all known USB 2.0 era graphics chips and firmware,
124 * but allows DisplayLink to increment those for any future incompatible chips
126 static const struct usb_device_id id_table[] = {
127 {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
128 .bInterfaceSubClass = 0x00,
129 .bInterfaceProtocol = 0x00,
130 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
131 USB_DEVICE_ID_MATCH_INT_CLASS |
132 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
133 USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
136 MODULE_DEVICE_TABLE(usb, id_table);
138 static struct usb_driver udl_driver = {
140 .probe = udl_usb_probe,
141 .disconnect = udl_usb_disconnect,
142 .suspend = udl_usb_suspend,
143 .resume = udl_usb_resume,
144 .id_table = id_table,
146 module_usb_driver(udl_driver);
147 MODULE_LICENSE("GPL");