udl_drv.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012 Red Hat
  4. */
  5. #include <linux/module.h>
  6. #include <drm/clients/drm_client_setup.h>
  7. #include <drm/drm_drv.h>
  8. #include <drm/drm_fbdev_shmem.h>
  9. #include <drm/drm_file.h>
  10. #include <drm/drm_gem_shmem_helper.h>
  11. #include <drm/drm_managed.h>
  12. #include <drm/drm_modeset_helper.h>
  13. #include <drm/drm_ioctl.h>
  14. #include <drm/drm_probe_helper.h>
  15. #include <drm/drm_print.h>
  16. #include "udl_drv.h"
  17. static int udl_usb_suspend(struct usb_interface *interface,
  18. pm_message_t message)
  19. {
  20. struct drm_device *dev = usb_get_intfdata(interface);
  21. struct udl_device *udl = to_udl(dev);
  22. int ret;
  23. ret = drm_mode_config_helper_suspend(dev);
  24. if (ret)
  25. return ret;
  26. udl_sync_pending_urbs(udl);
  27. return 0;
  28. }
  29. static int udl_usb_resume(struct usb_interface *interface)
  30. {
  31. struct drm_device *dev = usb_get_intfdata(interface);
  32. return drm_mode_config_helper_resume(dev);
  33. }
  34. static int udl_usb_reset_resume(struct usb_interface *interface)
  35. {
  36. struct drm_device *dev = usb_get_intfdata(interface);
  37. struct udl_device *udl = to_udl(dev);
  38. udl_select_std_channel(udl);
  39. return drm_mode_config_helper_resume(dev);
  40. }
  41. DEFINE_DRM_GEM_FOPS(udl_driver_fops);
  42. static const struct drm_driver driver = {
  43. .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
  44. /* GEM hooks */
  45. .fops = &udl_driver_fops,
  46. DRM_GEM_SHMEM_DRIVER_OPS,
  47. DRM_FBDEV_SHMEM_DRIVER_OPS,
  48. .name = DRIVER_NAME,
  49. .desc = DRIVER_DESC,
  50. .major = DRIVER_MAJOR,
  51. .minor = DRIVER_MINOR,
  52. .patchlevel = DRIVER_PATCHLEVEL,
  53. };
  54. static struct udl_device *udl_driver_create(struct usb_interface *interface)
  55. {
  56. struct udl_device *udl;
  57. int r;
  58. udl = devm_drm_dev_alloc(&interface->dev, &driver,
  59. struct udl_device, drm);
  60. if (IS_ERR(udl))
  61. return udl;
  62. r = udl_init(udl);
  63. if (r)
  64. return ERR_PTR(r);
  65. usb_set_intfdata(interface, udl);
  66. return udl;
  67. }
  68. static int udl_usb_probe(struct usb_interface *interface,
  69. const struct usb_device_id *id)
  70. {
  71. int r;
  72. struct udl_device *udl;
  73. udl = udl_driver_create(interface);
  74. if (IS_ERR(udl))
  75. return PTR_ERR(udl);
  76. r = drm_dev_register(&udl->drm, 0);
  77. if (r)
  78. return r;
  79. DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
  80. drm_client_setup(&udl->drm, NULL);
  81. return 0;
  82. }
  83. static void udl_usb_disconnect(struct usb_interface *interface)
  84. {
  85. struct drm_device *dev = usb_get_intfdata(interface);
  86. struct udl_device *udl = to_udl(dev);
  87. drm_dev_unplug(dev);
  88. udl_drop_usb(udl);
  89. }
  90. /*
  91. * There are many DisplayLink-based graphics products, all with unique PIDs.
  92. * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
  93. * We also require a match on SubClass (0x00) and Protocol (0x00),
  94. * which is compatible with all known USB 2.0 era graphics chips and firmware,
  95. * but allows DisplayLink to increment those for any future incompatible chips
  96. */
  97. static const struct usb_device_id id_table[] = {
  98. {.idVendor = 0x17e9, .bInterfaceClass = 0xff,
  99. .bInterfaceSubClass = 0x00,
  100. .bInterfaceProtocol = 0x00,
  101. .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
  102. USB_DEVICE_ID_MATCH_INT_CLASS |
  103. USB_DEVICE_ID_MATCH_INT_SUBCLASS |
  104. USB_DEVICE_ID_MATCH_INT_PROTOCOL,},
  105. {},
  106. };
  107. MODULE_DEVICE_TABLE(usb, id_table);
  108. static struct usb_driver udl_driver = {
  109. .name = "udl",
  110. .probe = udl_usb_probe,
  111. .disconnect = udl_usb_disconnect,
  112. .suspend = udl_usb_suspend,
  113. .resume = udl_usb_resume,
  114. .reset_resume = udl_usb_reset_resume,
  115. .id_table = id_table,
  116. };
  117. module_usb_driver(udl_driver);
  118. MODULE_DESCRIPTION("KMS driver for the USB displaylink video adapters");
  119. MODULE_LICENSE("GPL");