18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * media-dev-allocator.h - Media Controller Device Allocator API 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2019 Shuah Khan <shuah@kernel.org> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Credits: Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* 118c2ecf20Sopenharmony_ci * This file adds a global ref-counted Media Controller Device Instance API. 128c2ecf20Sopenharmony_ci * A system wide global media device list is managed and each media device 138c2ecf20Sopenharmony_ci * includes a kref count. The last put on the media device releases the media 148c2ecf20Sopenharmony_ci * device instance. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef _MEDIA_DEV_ALLOCATOR_H 188c2ecf20Sopenharmony_ci#define _MEDIA_DEV_ALLOCATOR_H 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct usb_device; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#if defined(CONFIG_MEDIA_CONTROLLER) && IS_ENABLED(CONFIG_USB) 238c2ecf20Sopenharmony_ci/** 248c2ecf20Sopenharmony_ci * media_device_usb_allocate() - Allocate and return struct &media device 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * @udev: struct &usb_device pointer 278c2ecf20Sopenharmony_ci * @module_name: should be filled with %KBUILD_MODNAME 288c2ecf20Sopenharmony_ci * @owner: struct module pointer %THIS_MODULE for the driver. 298c2ecf20Sopenharmony_ci * %THIS_MODULE is null for a built-in driver. 308c2ecf20Sopenharmony_ci * It is safe even when %THIS_MODULE is null. 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * This interface should be called to allocate a Media Device when multiple 338c2ecf20Sopenharmony_ci * drivers share usb_device and the media device. This interface allocates 348c2ecf20Sopenharmony_ci * &media_device structure and calls media_device_usb_init() to initialize 358c2ecf20Sopenharmony_ci * it. 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_cistruct media_device *media_device_usb_allocate(struct usb_device *udev, 398c2ecf20Sopenharmony_ci const char *module_name, 408c2ecf20Sopenharmony_ci struct module *owner); 418c2ecf20Sopenharmony_ci/** 428c2ecf20Sopenharmony_ci * media_device_delete() - Release media device. Calls kref_put(). 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * @mdev: struct &media_device pointer 458c2ecf20Sopenharmony_ci * @module_name: should be filled with %KBUILD_MODNAME 468c2ecf20Sopenharmony_ci * @owner: struct module pointer %THIS_MODULE for the driver. 478c2ecf20Sopenharmony_ci * %THIS_MODULE is null for a built-in driver. 488c2ecf20Sopenharmony_ci * It is safe even when %THIS_MODULE is null. 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * This interface should be called to put Media Device Instance kref. 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_civoid media_device_delete(struct media_device *mdev, const char *module_name, 538c2ecf20Sopenharmony_ci struct module *owner); 548c2ecf20Sopenharmony_ci#else 558c2ecf20Sopenharmony_cistatic inline struct media_device *media_device_usb_allocate( 568c2ecf20Sopenharmony_ci struct usb_device *udev, const char *module_name, 578c2ecf20Sopenharmony_ci struct module *owner) 588c2ecf20Sopenharmony_ci { return NULL; } 598c2ecf20Sopenharmony_cistatic inline void media_device_delete( 608c2ecf20Sopenharmony_ci struct media_device *mdev, const char *module_name, 618c2ecf20Sopenharmony_ci struct module *owner) { } 628c2ecf20Sopenharmony_ci#endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */ 638c2ecf20Sopenharmony_ci#endif /* _MEDIA_DEV_ALLOCATOR_H */ 64