File Index
Files and directories
Sign in
FILE

udl_drv.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/udl/udl_drv.c C
  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/clients/drm_client_setup.h>
  9#include <drm/drm_drv.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	struct udl_device *udl = to_udl(dev);
 26	int ret;
 27
 28	ret = drm_mode_config_helper_suspend(dev);
 29	if (ret)
 30		return ret;
 31
 32	udl_sync_pending_urbs(udl);
 33	return 0;
 34}
 35
 36static int udl_usb_resume(struct usb_interface *interface)
 37{
 38	struct drm_device *dev = usb_get_intfdata(interface);
 39
 40	return drm_mode_config_helper_resume(dev);
 41}
 42
 43static int udl_usb_reset_resume(struct usb_interface *interface)
 44{
 45	struct drm_device *dev = usb_get_intfdata(interface);
 46	struct udl_device *udl = to_udl(dev);
 47
 48	udl_select_std_channel(udl);
 49
 50	return drm_mode_config_helper_resume(dev);
 51}
 52
 53DEFINE_DRM_GEM_FOPS(udl_driver_fops);
 54
 55static const struct drm_driver driver = {
 56	.driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
 57
 58	/* GEM hooks */
 59	.fops = &udl_driver_fops,
 60	DRM_GEM_SHMEM_DRIVER_OPS,
 61	DRM_FBDEV_SHMEM_DRIVER_OPS,
 62
 63	.name = DRIVER_NAME,
 64	.desc = DRIVER_DESC,
 65	.major = DRIVER_MAJOR,
 66	.minor = DRIVER_MINOR,
 67	.patchlevel = DRIVER_PATCHLEVEL,
 68};
 69
 70static struct udl_device *udl_driver_create(struct usb_interface *interface)
 71{
 72	struct udl_device *udl;
 73	int r;
 74
 75	udl = devm_drm_dev_alloc(&interface->dev, &driver,
 76				 struct udl_device, drm);
 77	if (IS_ERR(udl))
 78		return udl;
 79
 80	r = udl_init(udl);
 81	if (r)
 82		return ERR_PTR(r);
 83
 84	usb_set_intfdata(interface, udl);
 85
 86	return udl;
 87}
 88
 89static int udl_usb_probe(struct usb_interface *interface,
 90			 const struct usb_device_id *id)
 91{
 92	int r;
 93	struct udl_device *udl;
 94
 95	udl = udl_driver_create(interface);
 96	if (IS_ERR(udl))
 97		return PTR_ERR(udl);
 98
 99	r = drm_dev_register(&udl->drm, 0);
100	if (r)
101		return r;
102
103	DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
104
105	drm_client_setup(&udl->drm, NULL);
106
107	return 0;
108}
109
110static void udl_usb_disconnect(struct usb_interface *interface)
111{
112	struct drm_device *dev = usb_get_intfdata(interface);
113	struct udl_device *udl = to_udl(dev);
114
115	drm_dev_unplug(dev);
116	udl_drop_usb(udl);
117}
118
119/*
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
125 */
126static 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,},
134	{},
135};
136MODULE_DEVICE_TABLE(usb, id_table);
137
138static struct usb_driver udl_driver = {
139	.name = "udl",
140	.probe = udl_usb_probe,
141	.disconnect = udl_usb_disconnect,
142	.suspend = udl_usb_suspend,
143	.resume = udl_usb_resume,
144	.reset_resume = udl_usb_reset_resume,
145	.id_table = id_table,
146};
147module_usb_driver(udl_driver);
148MODULE_DESCRIPTION("KMS driver for the USB displaylink video adapters");
149MODULE_LICENSE("GPL");
~/ Read-only file preview.