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_fbdev_generic.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>
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 int ret;
25
26 ret = drm_mode_config_helper_suspend(dev);
27 if (ret)
28 return ret;
29
30 udl_sync_pending_urbs(dev);
31 return 0;
32}
33
34static int udl_usb_resume(struct usb_interface *interface)
35{
36 struct drm_device *dev = usb_get_intfdata(interface);
37
38 return drm_mode_config_helper_resume(dev);
39}
40
41static int udl_usb_reset_resume(struct usb_interface *interface)
42{
43 struct drm_device *dev = usb_get_intfdata(interface);
44 struct udl_device *udl = to_udl(dev);
45
46 udl_select_std_channel(udl);
47
48 return drm_mode_config_helper_resume(dev);
49}
50
51/*
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.
55 */
56static struct drm_gem_object *udl_driver_gem_prime_import(struct drm_device *dev,
57 struct dma_buf *dma_buf)
58{
59 struct udl_device *udl = to_udl(dev);
60
61 if (!udl->dmadev)
62 return ERR_PTR(-ENODEV);
63
64 return drm_gem_prime_import_dev(dev, dma_buf, udl->dmadev);
65}
66
67DEFINE_DRM_GEM_FOPS(udl_driver_fops);
68
69static const struct drm_driver driver = {
70 .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
71
72 /* GEM hooks */
73 .fops = &udl_driver_fops,
74 DRM_GEM_SHMEM_DRIVER_OPS,
75 .gem_prime_import = udl_driver_gem_prime_import,
76
77 .name = DRIVER_NAME,
78 .desc = DRIVER_DESC,
79 .date = DRIVER_DATE,
80 .major = DRIVER_MAJOR,
81 .minor = DRIVER_MINOR,
82 .patchlevel = DRIVER_PATCHLEVEL,
83};
84
85static struct udl_device *udl_driver_create(struct usb_interface *interface)
86{
87 struct udl_device *udl;
88 int r;
89
90 udl = devm_drm_dev_alloc(&interface->dev, &driver,
91 struct udl_device, drm);
92 if (IS_ERR(udl))
93 return udl;
94
95 r = udl_init(udl);
96 if (r)
97 return ERR_PTR(r);
98
99 usb_set_intfdata(interface, udl);
100
101 return udl;
102}
103
104static int udl_usb_probe(struct usb_interface *interface,
105 const struct usb_device_id *id)
106{
107 int r;
108 struct udl_device *udl;
109
110 udl = udl_driver_create(interface);
111 if (IS_ERR(udl))
112 return PTR_ERR(udl);
113
114 r = drm_dev_register(&udl->drm, 0);
115 if (r)
116 return r;
117
118 DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
119
120 drm_fbdev_generic_setup(&udl->drm, 0);
121
122 return 0;
123}
124
125static void udl_usb_disconnect(struct usb_interface *interface)
126{
127 struct drm_device *dev = usb_get_intfdata(interface);
128
129 drm_kms_helper_poll_fini(dev);
130 udl_drop_usb(dev);
131 drm_dev_unplug(dev);
132}
133
134/*
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
140 */
141static 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,},
149 {},
150};
151MODULE_DEVICE_TABLE(usb, id_table);
152
153static struct usb_driver udl_driver = {
154 .name = "udl",
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,
161};
162module_usb_driver(udl_driver);
163MODULE_LICENSE("GPL");
1/*
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>
10#include <drm/drm_usb.h>
11#include <drm/drm_crtc_helper.h>
12#include "udl_drv.h"
13
14static struct drm_driver driver;
15
16/*
17 * There are many DisplayLink-based graphics products, all with unique PIDs.
18 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
19 * We also require a match on SubClass (0x00) and Protocol (0x00),
20 * which is compatible with all known USB 2.0 era graphics chips and firmware,
21 * but allows DisplayLink to increment those for any future incompatible chips
22 */
23static struct usb_device_id id_table[] = {
24 {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
25 .bInterfaceSubClass = 0x00,
26 .bInterfaceProtocol = 0x00,
27 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
28 USB_DEVICE_ID_MATCH_INT_CLASS |
29 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
30 USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
31 {},
32};
33MODULE_DEVICE_TABLE(usb, id_table);
34
35MODULE_LICENSE("GPL");
36
37static int udl_usb_probe(struct usb_interface *interface,
38 const struct usb_device_id *id)
39{
40 return drm_get_usb_dev(interface, id, &driver);
41}
42
43static void udl_usb_disconnect(struct usb_interface *interface)
44{
45 struct drm_device *dev = usb_get_intfdata(interface);
46
47 drm_kms_helper_poll_disable(dev);
48 drm_connector_unplug_all(dev);
49 udl_fbdev_unplug(dev);
50 udl_drop_usb(dev);
51 drm_unplug_dev(dev);
52}
53
54static const struct vm_operations_struct udl_gem_vm_ops = {
55 .fault = udl_gem_fault,
56 .open = drm_gem_vm_open,
57 .close = drm_gem_vm_close,
58};
59
60static const struct file_operations udl_driver_fops = {
61 .owner = THIS_MODULE,
62 .open = drm_open,
63 .mmap = udl_drm_gem_mmap,
64 .poll = drm_poll,
65 .read = drm_read,
66 .unlocked_ioctl = drm_ioctl,
67 .release = drm_release,
68#ifdef CONFIG_COMPAT
69 .compat_ioctl = drm_compat_ioctl,
70#endif
71 .llseek = noop_llseek,
72};
73
74static struct drm_driver driver = {
75 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
76 .load = udl_driver_load,
77 .unload = udl_driver_unload,
78
79 /* gem hooks */
80 .gem_free_object = udl_gem_free_object,
81 .gem_vm_ops = &udl_gem_vm_ops,
82
83 .dumb_create = udl_dumb_create,
84 .dumb_map_offset = udl_gem_mmap,
85 .dumb_destroy = drm_gem_dumb_destroy,
86 .fops = &udl_driver_fops,
87
88 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
89 .gem_prime_import = udl_gem_prime_import,
90
91 .name = DRIVER_NAME,
92 .desc = DRIVER_DESC,
93 .date = DRIVER_DATE,
94 .major = DRIVER_MAJOR,
95 .minor = DRIVER_MINOR,
96 .patchlevel = DRIVER_PATCHLEVEL,
97};
98
99static struct usb_driver udl_driver = {
100 .name = "udl",
101 .probe = udl_usb_probe,
102 .disconnect = udl_usb_disconnect,
103 .id_table = id_table,
104};
105
106static int __init udl_init(void)
107{
108 return drm_usb_init(&driver, &udl_driver);
109}
110
111static void __exit udl_exit(void)
112{
113 drm_usb_exit(&driver, &udl_driver);
114}
115
116module_init(udl_init);
117module_exit(udl_exit);