[PATCH v2 1/3] drm: Add USB helpers

Daniel Vetter daniel at ffwll.ch
Tue Nov 3 10:48:45 UTC 2020


On Tue, Nov 03, 2020 at 11:36:54AM +0100, Thomas Zimmermann wrote:
> DRM drivers for USB devices can share a few helpers. It's currently only
> a function to retrieve the USB device's structure from the DRM device.
> 
> Putting this code next to the DRM device would make all of DRM depend on
> USB headers. So it's in a separate header file.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>

This seems like overkill for just sharing 1 inline function. Plus it might
tempt people into adding more bus functions again, and maybe I'm a bit too
much burned on the midlayer here, but that doesn't sound like a great
idea.

If we need bus helpers, they should be in the bus library (maybe there
should be a combo of interface_to_usbdev(to_usb_interface()) in the usb
code, but not in drm code).

The pci helpers are really the awkward historical exception because of the
utter horror show that is DRIVER_LEGACY shadow attach driver mode.
-Daniel

> ---
>  Documentation/gpu/drm-internals.rst |  5 +++++
>  include/drm/drm_usb_helper.h        | 25 +++++++++++++++++++++++++
>  2 files changed, 30 insertions(+)
>  create mode 100644 include/drm/drm_usb_helper.h
> 
> diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst
> index 12272b168580..642679407f36 100644
> --- a/Documentation/gpu/drm-internals.rst
> +++ b/Documentation/gpu/drm-internals.rst
> @@ -197,6 +197,11 @@ Utilities
>  .. kernel-doc:: include/drm/drm_util.h
>     :internal:
>  
> +USB helpers
> +-----------
> +
> +.. kernel-doc:: include/drm/drm_usb_helper.h
> +   :internal:
>  
>  Legacy Support Code
>  ===================
> diff --git a/include/drm/drm_usb_helper.h b/include/drm/drm_usb_helper.h
> new file mode 100644
> index 000000000000..6e8feff890ac
> --- /dev/null
> +++ b/include/drm/drm_usb_helper.h
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: GPL-2.0 or MIT */
> +
> +#ifndef DRM_USB_HELPER_H
> +#define DRM_USB_HELPER_H
> +
> +#include <linux/usb.h>
> +
> +#include <drm/drm_device.h>
> +
> +/**
> + * drm_dev_get_usb_device - Returns a DRM device's USB device
> + * @dev:	The DRM device
> + *
> + * For USB-based DRM devices, returns the corresponding USB device. The
> + * DRM device must store the USB interface's device in its dev field.
> + *
> + * RETURNS:
> + * The USB device
> + */
> +static inline struct usb_device *drm_dev_get_usb_device(struct drm_device *dev)
> +{
> +	return interface_to_usbdev(to_usb_interface(dev->dev));
> +}
> +
> +#endif
> -- 
> 2.29.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list