Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2012 Red Hat
4 */
5
6#include <linux/module.h>
7
8#include <drm/drm_drv.h>
9#include <drm/drm_client_setup.h>
10#include <drm/drm_fbdev_shmem.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_modeset_helper.h>
15#include <drm/drm_ioctl.h>
16#include <drm/drm_probe_helper.h>
17#include <drm/drm_print.h>
18
19#include "udl_drv.h"
20
21static int udl_usb_suspend(struct usb_interface *interface,
22 pm_message_t message)
23{
24 struct drm_device *dev = usb_get_intfdata(interface);
25 int ret;
26
27 ret = drm_mode_config_helper_suspend(dev);
28 if (ret)
29 return ret;
30
31 udl_sync_pending_urbs(dev);
32 return 0;
33}
34
35static int udl_usb_resume(struct usb_interface *interface)
36{
37 struct drm_device *dev = usb_get_intfdata(interface);
38
39 return drm_mode_config_helper_resume(dev);
40}
41
42static int udl_usb_reset_resume(struct usb_interface *interface)
43{
44 struct drm_device *dev = usb_get_intfdata(interface);
45 struct udl_device *udl = to_udl(dev);
46
47 udl_select_std_channel(udl);
48
49 return drm_mode_config_helper_resume(dev);
50}
51
52/*
53 * FIXME: Dma-buf sharing requires DMA support by the importing device.
54 * This function is a workaround to make USB devices work as well.
55 * See todo.rst for how to fix the issue in the dma-buf framework.
56 */
57static struct drm_gem_object *udl_driver_gem_prime_import(struct drm_device *dev,
58 struct dma_buf *dma_buf)
59{
60 struct udl_device *udl = to_udl(dev);
61
62 if (!udl->dmadev)
63 return ERR_PTR(-ENODEV);
64
65 return drm_gem_prime_import_dev(dev, dma_buf, udl->dmadev);
66}
67
68DEFINE_DRM_GEM_FOPS(udl_driver_fops);
69
70static const struct drm_driver driver = {
71 .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
72
73 /* GEM hooks */
74 .fops = &udl_driver_fops,
75 DRM_GEM_SHMEM_DRIVER_OPS,
76 .gem_prime_import = udl_driver_gem_prime_import,
77 DRM_FBDEV_SHMEM_DRIVER_OPS,
78
79 .name = DRIVER_NAME,
80 .desc = DRIVER_DESC,
81 .date = DRIVER_DATE,
82 .major = DRIVER_MAJOR,
83 .minor = DRIVER_MINOR,
84 .patchlevel = DRIVER_PATCHLEVEL,
85};
86
87static struct udl_device *udl_driver_create(struct usb_interface *interface)
88{
89 struct udl_device *udl;
90 int r;
91
92 udl = devm_drm_dev_alloc(&interface->dev, &driver,
93 struct udl_device, drm);
94 if (IS_ERR(udl))
95 return udl;
96
97 r = udl_init(udl);
98 if (r)
99 return ERR_PTR(r);
100
101 usb_set_intfdata(interface, udl);
102
103 return udl;
104}
105
106static int udl_usb_probe(struct usb_interface *interface,
107 const struct usb_device_id *id)
108{
109 int r;
110 struct udl_device *udl;
111
112 udl = udl_driver_create(interface);
113 if (IS_ERR(udl))
114 return PTR_ERR(udl);
115
116 r = drm_dev_register(&udl->drm, 0);
117 if (r)
118 return r;
119
120 DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
121
122 drm_client_setup(&udl->drm, NULL);
123
124 return 0;
125}
126
127static void udl_usb_disconnect(struct usb_interface *interface)
128{
129 struct drm_device *dev = usb_get_intfdata(interface);
130
131 drm_kms_helper_poll_fini(dev);
132 udl_drop_usb(dev);
133 drm_dev_unplug(dev);
134}
135
136/*
137 * There are many DisplayLink-based graphics products, all with unique PIDs.
138 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
139 * We also require a match on SubClass (0x00) and Protocol (0x00),
140 * which is compatible with all known USB 2.0 era graphics chips and firmware,
141 * but allows DisplayLink to increment those for any future incompatible chips
142 */
143static const struct usb_device_id id_table[] = {
144 {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
145 .bInterfaceSubClass = 0x00,
146 .bInterfaceProtocol = 0x00,
147 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
148 USB_DEVICE_ID_MATCH_INT_CLASS |
149 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
150 USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
151 {},
152};
153MODULE_DEVICE_TABLE(usb, id_table);
154
155static struct usb_driver udl_driver = {
156 .name = "udl",
157 .probe = udl_usb_probe,
158 .disconnect = udl_usb_disconnect,
159 .suspend = udl_usb_suspend,
160 .resume = udl_usb_resume,
161 .reset_resume = udl_usb_reset_resume,
162 .id_table = id_table,
163};
164module_usb_driver(udl_driver);
165MODULE_DESCRIPTION("KMS driver for the USB displaylink video adapters");
166MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2012 Red Hat
4 */
5
6#include <linux/module.h>
7
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>
17
18#include "udl_drv.h"
19
20static int udl_usb_suspend(struct usb_interface *interface,
21 pm_message_t message)
22{
23 struct drm_device *dev = usb_get_intfdata(interface);
24
25 return drm_mode_config_helper_suspend(dev);
26}
27
28static int udl_usb_resume(struct usb_interface *interface)
29{
30 struct drm_device *dev = usb_get_intfdata(interface);
31
32 return drm_mode_config_helper_resume(dev);
33}
34
35DEFINE_DRM_GEM_FOPS(udl_driver_fops);
36
37static struct drm_driver driver = {
38 .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
39
40 /* GEM hooks */
41 .gem_create_object = drm_gem_shmem_create_object_cached,
42
43 .fops = &udl_driver_fops,
44 DRM_GEM_SHMEM_DRIVER_OPS,
45
46 .name = DRIVER_NAME,
47 .desc = DRIVER_DESC,
48 .date = DRIVER_DATE,
49 .major = DRIVER_MAJOR,
50 .minor = DRIVER_MINOR,
51 .patchlevel = DRIVER_PATCHLEVEL,
52};
53
54static struct udl_device *udl_driver_create(struct usb_interface *interface)
55{
56 struct usb_device *udev = interface_to_usbdev(interface);
57 struct udl_device *udl;
58 int r;
59
60 udl = devm_drm_dev_alloc(&interface->dev, &driver,
61 struct udl_device, drm);
62 if (IS_ERR(udl))
63 return udl;
64
65 udl->udev = udev;
66
67 r = udl_init(udl);
68 if (r)
69 return ERR_PTR(r);
70
71 usb_set_intfdata(interface, udl);
72
73 return udl;
74}
75
76static int udl_usb_probe(struct usb_interface *interface,
77 const struct usb_device_id *id)
78{
79 int r;
80 struct udl_device *udl;
81
82 udl = udl_driver_create(interface);
83 if (IS_ERR(udl))
84 return PTR_ERR(udl);
85
86 r = drm_dev_register(&udl->drm, 0);
87 if (r)
88 return r;
89
90 DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
91
92 drm_fbdev_generic_setup(&udl->drm, 0);
93
94 return 0;
95}
96
97static void udl_usb_disconnect(struct usb_interface *interface)
98{
99 struct drm_device *dev = usb_get_intfdata(interface);
100
101 drm_kms_helper_poll_fini(dev);
102 udl_drop_usb(dev);
103 drm_dev_unplug(dev);
104}
105
106/*
107 * There are many DisplayLink-based graphics products, all with unique PIDs.
108 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
109 * We also require a match on SubClass (0x00) and Protocol (0x00),
110 * which is compatible with all known USB 2.0 era graphics chips and firmware,
111 * but allows DisplayLink to increment those for any future incompatible chips
112 */
113static const struct usb_device_id id_table[] = {
114 {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
115 .bInterfaceSubClass = 0x00,
116 .bInterfaceProtocol = 0x00,
117 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
118 USB_DEVICE_ID_MATCH_INT_CLASS |
119 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
120 USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
121 {},
122};
123MODULE_DEVICE_TABLE(usb, id_table);
124
125static struct usb_driver udl_driver = {
126 .name = "udl",
127 .probe = udl_usb_probe,
128 .disconnect = udl_usb_disconnect,
129 .suspend = udl_usb_suspend,
130 .resume = udl_usb_resume,
131 .id_table = id_table,
132};
133module_usb_driver(udl_driver);
134MODULE_LICENSE("GPL");