media-dev-allocator.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * media-dev-allocator.h - Media Controller Device Allocator API
  4. *
  5. * Copyright (c) 2019 Shuah Khan <[email protected]>
  6. *
  7. * Credits: Suggested by Laurent Pinchart <[email protected]>
  8. */
  9. /*
  10. * This file adds a global ref-counted Media Controller Device Instance API.
  11. * A system wide global media device list is managed and each media device
  12. * includes a kref count. The last put on the media device releases the media
  13. * device instance.
  14. */
  15. #ifndef _MEDIA_DEV_ALLOCATOR_H
  16. #define _MEDIA_DEV_ALLOCATOR_H
  17. struct usb_device;
  18. #if defined(CONFIG_MEDIA_CONTROLLER) && IS_ENABLED(CONFIG_USB)
  19. /**
  20. * media_device_usb_allocate() - Allocate and return struct &media device
  21. *
  22. * @udev: struct &usb_device pointer
  23. * @module_name: should be filled with %KBUILD_MODNAME
  24. * @owner: struct module pointer %THIS_MODULE for the driver.
  25. * %THIS_MODULE is null for a built-in driver.
  26. * It is safe even when %THIS_MODULE is null.
  27. *
  28. * This interface should be called to allocate a Media Device when multiple
  29. * drivers share usb_device and the media device. This interface allocates
  30. * &media_device structure and calls media_device_usb_init() to initialize
  31. * it.
  32. *
  33. */
  34. struct media_device *media_device_usb_allocate(struct usb_device *udev,
  35. const char *module_name,
  36. struct module *owner);
  37. /**
  38. * media_device_delete() - Release media device. Calls kref_put().
  39. *
  40. * @mdev: struct &media_device pointer
  41. * @module_name: should be filled with %KBUILD_MODNAME
  42. * @owner: struct module pointer %THIS_MODULE for the driver.
  43. * %THIS_MODULE is null for a built-in driver.
  44. * It is safe even when %THIS_MODULE is null.
  45. *
  46. * This interface should be called to put Media Device Instance kref.
  47. */
  48. void media_device_delete(struct media_device *mdev, const char *module_name,
  49. struct module *owner);
  50. #else
  51. static inline struct media_device *media_device_usb_allocate(
  52. struct usb_device *udev, const char *module_name,
  53. struct module *owner)
  54. { return NULL; }
  55. static inline void media_device_delete(
  56. struct media_device *mdev, const char *module_name,
  57. struct module *owner) { }
  58. #endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */
  59. #endif /* _MEDIA_DEV_ALLOCATOR_H */