162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * media-dev-allocator.h - Media Controller Device Allocator API
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2019 Shuah Khan <shuah@kernel.org>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Credits: Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * This file adds a global ref-counted Media Controller Device Instance API.
1262306a36Sopenharmony_ci * A system wide global media device list is managed and each media device
1362306a36Sopenharmony_ci * includes a kref count. The last put on the media device releases the media
1462306a36Sopenharmony_ci * device instance.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#ifndef _MEDIA_DEV_ALLOCATOR_H
1862306a36Sopenharmony_ci#define _MEDIA_DEV_ALLOCATOR_H
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct usb_device;
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#if defined(CONFIG_MEDIA_CONTROLLER) && IS_ENABLED(CONFIG_USB)
2362306a36Sopenharmony_ci/**
2462306a36Sopenharmony_ci * media_device_usb_allocate() - Allocate and return struct &media device
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * @udev:		struct &usb_device pointer
2762306a36Sopenharmony_ci * @module_name:	should be filled with %KBUILD_MODNAME
2862306a36Sopenharmony_ci * @owner:		struct module pointer %THIS_MODULE for the driver.
2962306a36Sopenharmony_ci *			%THIS_MODULE is null for a built-in driver.
3062306a36Sopenharmony_ci *			It is safe even when %THIS_MODULE is null.
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci * This interface should be called to allocate a Media Device when multiple
3362306a36Sopenharmony_ci * drivers share usb_device and the media device. This interface allocates
3462306a36Sopenharmony_ci * &media_device structure and calls media_device_usb_init() to initialize
3562306a36Sopenharmony_ci * it.
3662306a36Sopenharmony_ci *
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_cistruct media_device *media_device_usb_allocate(struct usb_device *udev,
3962306a36Sopenharmony_ci					       const char *module_name,
4062306a36Sopenharmony_ci					       struct module *owner);
4162306a36Sopenharmony_ci/**
4262306a36Sopenharmony_ci * media_device_delete() - Release media device. Calls kref_put().
4362306a36Sopenharmony_ci *
4462306a36Sopenharmony_ci * @mdev:		struct &media_device pointer
4562306a36Sopenharmony_ci * @module_name:	should be filled with %KBUILD_MODNAME
4662306a36Sopenharmony_ci * @owner:		struct module pointer %THIS_MODULE for the driver.
4762306a36Sopenharmony_ci *			%THIS_MODULE is null for a built-in driver.
4862306a36Sopenharmony_ci *			It is safe even when %THIS_MODULE is null.
4962306a36Sopenharmony_ci *
5062306a36Sopenharmony_ci * This interface should be called to put Media Device Instance kref.
5162306a36Sopenharmony_ci */
5262306a36Sopenharmony_civoid media_device_delete(struct media_device *mdev, const char *module_name,
5362306a36Sopenharmony_ci			 struct module *owner);
5462306a36Sopenharmony_ci#else
5562306a36Sopenharmony_cistatic inline struct media_device *media_device_usb_allocate(
5662306a36Sopenharmony_ci			struct usb_device *udev, const char *module_name,
5762306a36Sopenharmony_ci			struct module *owner)
5862306a36Sopenharmony_ci			{ return NULL; }
5962306a36Sopenharmony_cistatic inline void media_device_delete(
6062306a36Sopenharmony_ci			struct media_device *mdev, const char *module_name,
6162306a36Sopenharmony_ci			struct module *owner) { }
6262306a36Sopenharmony_ci#endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */
6362306a36Sopenharmony_ci#endif /* _MEDIA_DEV_ALLOCATOR_H */
64