xref: /linux/include/media/media-dev-allocator.h (revision 69bfec7548f4c1595bac0e3ddfc0458a5af31f4c)
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 <shuah@kernel.org>
6  *
7  * Credits: Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8  */
9 
10 /*
11  * This file adds a global ref-counted Media Controller Device Instance API.
12  * A system wide global media device list is managed and each media device
13  * includes a kref count. The last put on the media device releases the media
14  * device instance.
15  */
16 
17 #ifndef _MEDIA_DEV_ALLOCATOR_H
18 #define _MEDIA_DEV_ALLOCATOR_H
19 
20 struct usb_device;
21 
22 #if defined(CONFIG_MEDIA_CONTROLLER) && IS_ENABLED(CONFIG_USB)
23 /**
24  * media_device_usb_allocate() - Allocate and return struct &media device
25  *
26  * @udev:		struct &usb_device pointer
27  * @module_name:	should be filled with %KBUILD_MODNAME
28  * @owner:		struct module pointer %THIS_MODULE for the driver.
29  *			%THIS_MODULE is null for a built-in driver.
30  *			It is safe even when %THIS_MODULE is null.
31  *
32  * This interface should be called to allocate a Media Device when multiple
33  * drivers share usb_device and the media device. This interface allocates
34  * &media_device structure and calls media_device_usb_init() to initialize
35  * it.
36  *
37  */
38 struct media_device *media_device_usb_allocate(struct usb_device *udev,
39 					       const char *module_name,
40 					       struct module *owner);
41 /**
42  * media_device_delete() - Release media device. Calls kref_put().
43  *
44  * @mdev:		struct &media_device pointer
45  * @module_name:	should be filled with %KBUILD_MODNAME
46  * @owner:		struct module pointer %THIS_MODULE for the driver.
47  *			%THIS_MODULE is null for a built-in driver.
48  *			It is safe even when %THIS_MODULE is null.
49  *
50  * This interface should be called to put Media Device Instance kref.
51  */
52 void media_device_delete(struct media_device *mdev, const char *module_name,
53 			 struct module *owner);
54 #else
55 static inline struct media_device *media_device_usb_allocate(
56 			struct usb_device *udev, const char *module_name,
57 			struct module *owner)
58 			{ return NULL; }
59 static inline void media_device_delete(
60 			struct media_device *mdev, const char *module_name,
61 			struct module *owner) { }
62 #endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */
63 #endif /* _MEDIA_DEV_ALLOCATOR_H */
64