3
  *   	ˆl–Ü4ý( ©³( 	Å€fàB¦-ÿÁƒœ_†I|¥�+ÅÄ Õ    	/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * media-dev-allocator.h - Media Controller Device Allocator API
 *
 * Copyright (c) 2019 Shuah Khan <shuah@kernel.org>
 *
 * Credits: Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com>
 */

/*
 * This file adds a global ref-counted Media Controller Device Instance API.
 * A system wide global media device list is managed and each media device
 * includes a kref count. The last put on the media device releases the media
 * device instance.
 */

#ifndef _MEDIA_DEV_ALLOCATOR_H
#define _MEDIA_DEV_ALLOCATOR_H

struct usb_device;

#if defined(CONFIG_MEDIA_CONTROLLER) && IS_ENABLED(CONFIG_USB)
/**
 * media_device_usb_allocate() - Allocate and return struct &media device
 *
 * @udev:		struct &usb_device pointer
 * @module_name:	should be filled with %KBUILD_MODNAME
 * @owner:		struct module pointer %THIS_MODULE for the driver.
 *			%THIS_MODULE is null for a built-in driver.
 *			It is safe even when %THIS_MODULE is null.
 *
 * This interface should be called to allocate a Media Device when multiple
 * drivers share usb_device and the media device. This interface allocates
 * &media_device structure and calls media_device_usb_init() to initialize
 * it.
 *
 */
struct media_device *media_device_usb_allocate(struct usb_device *udev,
					       const char *module_name,
					       struct module *owner);
/**
 * media_device_delete() - Release media device. Calls kref_put().
 *
 * @mdev:		struct &media_device pointer
 * @module_name:	should be filled with %KBUILD_MODNAME
 * @owner:		struct module pointer %THIS_MODULE for the driver.
 *			%THIS_MODULE is null for a built-in driver.
 *			It is safe even when %THIS_MODULE is null.
 *
 * This interface should be called to put Media Device Instance kref.
 */
void media_device_delete(struct media_device *mdev, const char *module_name,
			 struct module *owner);
#else
static inline struct media_device *media_device_usb_allocate(
			struct usb_device *udev, const char *module_name,
			struct module *owner)
			{ return NULL; }
static inline void media_device_delete(
			struct media_device *mdev, const char *module_name,
			struct module *owner) { }
#endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */
#endif /* _MEDIA_DEV_ALLOCATOR_H */
      ˆl–ß=¿J	•2ÛB‚ œP@¸Ènå1hßÃ0ÆÅ      ˆl–ßi~”Je¶…8 �q¦î	•1hßÄ0ÇÆ     ˆÁÄ„ã_ÀÇÆ '´    /* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
 */

#ifndef _LINUX_IOPOLL_H
#define _LINUX_IOPOLL_H

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/ktime.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/io.h>

/**
 * poll_timeout_us - Periodically poll and perform an operation until
 *                   a condition is met or a timeout occurs
 *
 * @op: Operation
 * @cond: Break condition
 * @sleep_us: Maximum time to sleep between operations in us (0 tight-loops).
 *            Please read usleep_range() function description for details and
 *            limitations.
 * @timeout_us: Timeout in us, 0 means never timeout
 * @sleep_before_op: if it is true, sleep @sleep_us before operation.
 *
 * When available, you'll probably want to use one of the specialized
 * macros defined below rather than this macro directly.
 *
 * Returns: 0 on success and -ETIMEDOUT upon a timeout. Must not
 * be called from atomic context if sleep_us or timeout_us are used.
 */
#define poll_timeout_us(op, cond, sleep_us, timeout_us, sleep_before_op) \
({ \
	u64 __timeout_us = (timeout_us); \
	unsigned long __sleep_us = (sleep_us); \
	ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
	might_sleep_if((__sleep_us) != 0); \
	if ((sleep_before_op) && __sleep_us) \
		usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
	for (;;) { \
		op; \
		if (cond) \
			break; \
		if (__timeout_us && \
		    ktime_compare(ktime_get(), __timeout) > 0) { \
			op; \
			break; \
		} \
		if (__sleep_us) \
			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
		c