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