xref: /openbmc/linux/drivers/gpu/drm/udl/udl_drv.c (revision e8263235)
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 
20 static 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 
28 static 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 
35 DEFINE_DRM_GEM_FOPS(udl_driver_fops);
36 
37 static const 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 
54 static struct udl_device *udl_driver_create(struct usb_interface *interface)
55 {
56 	struct udl_device *udl;
57 	int r;
58 
59 	udl = devm_drm_dev_alloc(&interface->dev, &driver,
60 				 struct udl_device, drm);
61 	if (IS_ERR(udl))
62 		return udl;
63 
64 	r = udl_init(udl);
65 	if (r)
66 		return ERR_PTR(r);
67 
68 	usb_set_intfdata(interface, udl);
69 
70 	return udl;
71 }
72 
73 static int udl_usb_probe(struct usb_interface *interface,
74 			 const struct usb_device_id *id)
75 {
76 	int r;
77 	struct udl_device *udl;
78 
79 	udl = udl_driver_create(interface);
80 	if (IS_ERR(udl))
81 		return PTR_ERR(udl);
82 
83 	r = drm_dev_register(&udl->drm, 0);
84 	if (r)
85 		return r;
86 
87 	DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
88 
89 	drm_fbdev_generic_setup(&udl->drm, 0);
90 
91 	return 0;
92 }
93 
94 static void udl_usb_disconnect(struct usb_interface *interface)
95 {
96 	struct drm_device *dev = usb_get_intfdata(interface);
97 
98 	drm_kms_helper_poll_fini(dev);
99 	udl_drop_usb(dev);
100 	drm_dev_unplug(dev);
101 }
102 
103 /*
104  * There are many DisplayLink-based graphics products, all with unique PIDs.
105  * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
106  * We also require a match on SubClass (0x00) and Protocol (0x00),
107  * which is compatible with all known USB 2.0 era graphics chips and firmware,
108  * but allows DisplayLink to increment those for any future incompatible chips
109  */
110 static const struct usb_device_id id_table[] = {
111 	{.idVendor = 0x17e9, .bInterfaceClass = 0xff,
112 	 .bInterfaceSubClass = 0x00,
113 	 .bInterfaceProtocol = 0x00,
114 	 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
115 			USB_DEVICE_ID_MATCH_INT_CLASS |
116 			USB_DEVICE_ID_MATCH_INT_SUBCLASS |
117 			USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
118 	{},
119 };
120 MODULE_DEVICE_TABLE(usb, id_table);
121 
122 static struct usb_driver udl_driver = {
123 	.name = "udl",
124 	.probe = udl_usb_probe,
125 	.disconnect = udl_usb_disconnect,
126 	.suspend = udl_usb_suspend,
127 	.resume = udl_usb_resume,
128 	.id_table = id_table,
129 };
130 module_usb_driver(udl_driver);
131 MODULE_LICENSE("GPL");
132