18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Media device
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2010 Nokia Corporation
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
88c2ecf20Sopenharmony_ci *	     Sakari Ailus <sakari.ailus@iki.fi>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _MEDIA_DEVICE_H
128c2ecf20Sopenharmony_ci#define _MEDIA_DEVICE_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/list.h>
158c2ecf20Sopenharmony_ci#include <linux/mutex.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <media/media-devnode.h>
188c2ecf20Sopenharmony_ci#include <media/media-entity.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct ida;
218c2ecf20Sopenharmony_cistruct device;
228c2ecf20Sopenharmony_cistruct media_device;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/**
258c2ecf20Sopenharmony_ci * struct media_entity_notify - Media Entity Notify
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * @list: List head
288c2ecf20Sopenharmony_ci * @notify_data: Input data to invoke the callback
298c2ecf20Sopenharmony_ci * @notify: Callback function pointer
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * Drivers may register a callback to take action when new entities get
328c2ecf20Sopenharmony_ci * registered with the media device. This handler is intended for creating
338c2ecf20Sopenharmony_ci * links between existing entities and should not create entities and register
348c2ecf20Sopenharmony_ci * them.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_cistruct media_entity_notify {
378c2ecf20Sopenharmony_ci	struct list_head list;
388c2ecf20Sopenharmony_ci	void *notify_data;
398c2ecf20Sopenharmony_ci	void (*notify)(struct media_entity *entity, void *notify_data);
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/**
438c2ecf20Sopenharmony_ci * struct media_device_ops - Media device operations
448c2ecf20Sopenharmony_ci * @link_notify: Link state change notification callback. This callback is
458c2ecf20Sopenharmony_ci *		 called with the graph_mutex held.
468c2ecf20Sopenharmony_ci * @req_alloc: Allocate a request. Set this if you need to allocate a struct
478c2ecf20Sopenharmony_ci *	       larger then struct media_request. @req_alloc and @req_free must
488c2ecf20Sopenharmony_ci *	       either both be set or both be NULL.
498c2ecf20Sopenharmony_ci * @req_free: Free a request. Set this if @req_alloc was set as well, leave
508c2ecf20Sopenharmony_ci *	      to NULL otherwise.
518c2ecf20Sopenharmony_ci * @req_validate: Validate a request, but do not queue yet. The req_queue_mutex
528c2ecf20Sopenharmony_ci *	          lock is held when this op is called.
538c2ecf20Sopenharmony_ci * @req_queue: Queue a validated request, cannot fail. If something goes
548c2ecf20Sopenharmony_ci *	       wrong when queueing this request then it should be marked
558c2ecf20Sopenharmony_ci *	       as such internally in the driver and any related buffers
568c2ecf20Sopenharmony_ci *	       must eventually return to vb2 with state VB2_BUF_STATE_ERROR.
578c2ecf20Sopenharmony_ci *	       The req_queue_mutex lock is held when this op is called.
588c2ecf20Sopenharmony_ci *	       It is important that vb2 buffer objects are queued last after
598c2ecf20Sopenharmony_ci *	       all other object types are queued: queueing a buffer kickstarts
608c2ecf20Sopenharmony_ci *	       the request processing, so all other objects related to the
618c2ecf20Sopenharmony_ci *	       request (and thus the buffer) must be available to the driver.
628c2ecf20Sopenharmony_ci *	       And once a buffer is queued, then the driver can complete
638c2ecf20Sopenharmony_ci *	       or delete objects from the request before req_queue exits.
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_cistruct media_device_ops {
668c2ecf20Sopenharmony_ci	int (*link_notify)(struct media_link *link, u32 flags,
678c2ecf20Sopenharmony_ci			   unsigned int notification);
688c2ecf20Sopenharmony_ci	struct media_request *(*req_alloc)(struct media_device *mdev);
698c2ecf20Sopenharmony_ci	void (*req_free)(struct media_request *req);
708c2ecf20Sopenharmony_ci	int (*req_validate)(struct media_request *req);
718c2ecf20Sopenharmony_ci	void (*req_queue)(struct media_request *req);
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/**
758c2ecf20Sopenharmony_ci * struct media_device - Media device
768c2ecf20Sopenharmony_ci * @dev:	Parent device
778c2ecf20Sopenharmony_ci * @devnode:	Media device node
788c2ecf20Sopenharmony_ci * @driver_name: Optional device driver name. If not set, calls to
798c2ecf20Sopenharmony_ci *		%MEDIA_IOC_DEVICE_INFO will return ``dev->driver->name``.
808c2ecf20Sopenharmony_ci *		This is needed for USB drivers for example, as otherwise
818c2ecf20Sopenharmony_ci *		they'll all appear as if the driver name was "usb".
828c2ecf20Sopenharmony_ci * @model:	Device model name
838c2ecf20Sopenharmony_ci * @serial:	Device serial number (optional)
848c2ecf20Sopenharmony_ci * @bus_info:	Unique and stable device location identifier
858c2ecf20Sopenharmony_ci * @hw_revision: Hardware device revision
868c2ecf20Sopenharmony_ci * @topology_version: Monotonic counter for storing the version of the graph
878c2ecf20Sopenharmony_ci *		topology. Should be incremented each time the topology changes.
888c2ecf20Sopenharmony_ci * @id:		Unique ID used on the last registered graph object
898c2ecf20Sopenharmony_ci * @entity_internal_idx: Unique internal entity ID used by the graph traversal
908c2ecf20Sopenharmony_ci *		algorithms
918c2ecf20Sopenharmony_ci * @entity_internal_idx_max: Allocated internal entity indices
928c2ecf20Sopenharmony_ci * @entities:	List of registered entities
938c2ecf20Sopenharmony_ci * @interfaces:	List of registered interfaces
948c2ecf20Sopenharmony_ci * @pads:	List of registered pads
958c2ecf20Sopenharmony_ci * @links:	List of registered links
968c2ecf20Sopenharmony_ci * @entity_notify: List of registered entity_notify callbacks
978c2ecf20Sopenharmony_ci * @graph_mutex: Protects access to struct media_device data
988c2ecf20Sopenharmony_ci * @pm_count_walk: Graph walk for power state walk. Access serialised using
998c2ecf20Sopenharmony_ci *		   graph_mutex.
1008c2ecf20Sopenharmony_ci *
1018c2ecf20Sopenharmony_ci * @source_priv: Driver Private data for enable/disable source handlers
1028c2ecf20Sopenharmony_ci * @enable_source: Enable Source Handler function pointer
1038c2ecf20Sopenharmony_ci * @disable_source: Disable Source Handler function pointer
1048c2ecf20Sopenharmony_ci *
1058c2ecf20Sopenharmony_ci * @ops:	Operation handler callbacks
1068c2ecf20Sopenharmony_ci * @req_queue_mutex: Serialise the MEDIA_REQUEST_IOC_QUEUE ioctl w.r.t.
1078c2ecf20Sopenharmony_ci *		     other operations that stop or start streaming.
1088c2ecf20Sopenharmony_ci * @request_id: Used to generate unique request IDs
1098c2ecf20Sopenharmony_ci *
1108c2ecf20Sopenharmony_ci * This structure represents an abstract high-level media device. It allows easy
1118c2ecf20Sopenharmony_ci * access to entities and provides basic media device-level support. The
1128c2ecf20Sopenharmony_ci * structure can be allocated directly or embedded in a larger structure.
1138c2ecf20Sopenharmony_ci *
1148c2ecf20Sopenharmony_ci * The parent @dev is a physical device. It must be set before registering the
1158c2ecf20Sopenharmony_ci * media device.
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * @model is a descriptive model name exported through sysfs. It doesn't have to
1188c2ecf20Sopenharmony_ci * be unique.
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci * @enable_source is a handler to find source entity for the
1218c2ecf20Sopenharmony_ci * sink entity  and activate the link between them if source
1228c2ecf20Sopenharmony_ci * entity is free. Drivers should call this handler before
1238c2ecf20Sopenharmony_ci * accessing the source.
1248c2ecf20Sopenharmony_ci *
1258c2ecf20Sopenharmony_ci * @disable_source is a handler to find source entity for the
1268c2ecf20Sopenharmony_ci * sink entity  and deactivate the link between them. Drivers
1278c2ecf20Sopenharmony_ci * should call this handler to release the source.
1288c2ecf20Sopenharmony_ci *
1298c2ecf20Sopenharmony_ci * Use-case: find tuner entity connected to the decoder
1308c2ecf20Sopenharmony_ci * entity and check if it is available, and activate the
1318c2ecf20Sopenharmony_ci * link between them from @enable_source and deactivate
1328c2ecf20Sopenharmony_ci * from @disable_source.
1338c2ecf20Sopenharmony_ci *
1348c2ecf20Sopenharmony_ci * .. note::
1358c2ecf20Sopenharmony_ci *
1368c2ecf20Sopenharmony_ci *    Bridge driver is expected to implement and set the
1378c2ecf20Sopenharmony_ci *    handler when &media_device is registered or when
1388c2ecf20Sopenharmony_ci *    bridge driver finds the media_device during probe.
1398c2ecf20Sopenharmony_ci *    Bridge driver sets source_priv with information
1408c2ecf20Sopenharmony_ci *    necessary to run @enable_source and @disable_source handlers.
1418c2ecf20Sopenharmony_ci *    Callers should hold graph_mutex to access and call @enable_source
1428c2ecf20Sopenharmony_ci *    and @disable_source handlers.
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_cistruct media_device {
1458c2ecf20Sopenharmony_ci	/* dev->driver_data points to this struct. */
1468c2ecf20Sopenharmony_ci	struct device *dev;
1478c2ecf20Sopenharmony_ci	struct media_devnode *devnode;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	char model[32];
1508c2ecf20Sopenharmony_ci	char driver_name[32];
1518c2ecf20Sopenharmony_ci	char serial[40];
1528c2ecf20Sopenharmony_ci	char bus_info[32];
1538c2ecf20Sopenharmony_ci	u32 hw_revision;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	u64 topology_version;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	u32 id;
1588c2ecf20Sopenharmony_ci	struct ida entity_internal_idx;
1598c2ecf20Sopenharmony_ci	int entity_internal_idx_max;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	struct list_head entities;
1628c2ecf20Sopenharmony_ci	struct list_head interfaces;
1638c2ecf20Sopenharmony_ci	struct list_head pads;
1648c2ecf20Sopenharmony_ci	struct list_head links;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	/* notify callback list invoked when a new entity is registered */
1678c2ecf20Sopenharmony_ci	struct list_head entity_notify;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	/* Serializes graph operations. */
1708c2ecf20Sopenharmony_ci	struct mutex graph_mutex;
1718c2ecf20Sopenharmony_ci	struct media_graph pm_count_walk;
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	void *source_priv;
1748c2ecf20Sopenharmony_ci	int (*enable_source)(struct media_entity *entity,
1758c2ecf20Sopenharmony_ci			     struct media_pipeline *pipe);
1768c2ecf20Sopenharmony_ci	void (*disable_source)(struct media_entity *entity);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	const struct media_device_ops *ops;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	struct mutex req_queue_mutex;
1818c2ecf20Sopenharmony_ci	atomic_t request_id;
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/* We don't need to include pci.h or usb.h here */
1858c2ecf20Sopenharmony_cistruct pci_dev;
1868c2ecf20Sopenharmony_cistruct usb_device;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/* Supported link_notify @notification values. */
1918c2ecf20Sopenharmony_ci#define MEDIA_DEV_NOTIFY_PRE_LINK_CH	0
1928c2ecf20Sopenharmony_ci#define MEDIA_DEV_NOTIFY_POST_LINK_CH	1
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/**
1958c2ecf20Sopenharmony_ci * media_entity_enum_init - Initialise an entity enumeration
1968c2ecf20Sopenharmony_ci *
1978c2ecf20Sopenharmony_ci * @ent_enum: Entity enumeration to be initialised
1988c2ecf20Sopenharmony_ci * @mdev: The related media device
1998c2ecf20Sopenharmony_ci *
2008c2ecf20Sopenharmony_ci * Return: zero on success or a negative error code.
2018c2ecf20Sopenharmony_ci */
2028c2ecf20Sopenharmony_cistatic inline __must_check int media_entity_enum_init(
2038c2ecf20Sopenharmony_ci	struct media_entity_enum *ent_enum, struct media_device *mdev)
2048c2ecf20Sopenharmony_ci{
2058c2ecf20Sopenharmony_ci	return __media_entity_enum_init(ent_enum,
2068c2ecf20Sopenharmony_ci					mdev->entity_internal_idx_max + 1);
2078c2ecf20Sopenharmony_ci}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/**
2108c2ecf20Sopenharmony_ci * media_device_init() - Initializes a media device element
2118c2ecf20Sopenharmony_ci *
2128c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
2138c2ecf20Sopenharmony_ci *
2148c2ecf20Sopenharmony_ci * This function initializes the media device prior to its registration.
2158c2ecf20Sopenharmony_ci * The media device initialization and registration is split in two functions
2168c2ecf20Sopenharmony_ci * to avoid race conditions and make the media device available to user-space
2178c2ecf20Sopenharmony_ci * before the media graph has been completed.
2188c2ecf20Sopenharmony_ci *
2198c2ecf20Sopenharmony_ci * So drivers need to first initialize the media device, register any entity
2208c2ecf20Sopenharmony_ci * within the media device, create pad to pad links and then finally register
2218c2ecf20Sopenharmony_ci * the media device by calling media_device_register() as a final step.
2228c2ecf20Sopenharmony_ci */
2238c2ecf20Sopenharmony_civoid media_device_init(struct media_device *mdev);
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci/**
2268c2ecf20Sopenharmony_ci * media_device_cleanup() - Cleanups a media device element
2278c2ecf20Sopenharmony_ci *
2288c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
2298c2ecf20Sopenharmony_ci *
2308c2ecf20Sopenharmony_ci * This function that will destroy the graph_mutex that is
2318c2ecf20Sopenharmony_ci * initialized in media_device_init().
2328c2ecf20Sopenharmony_ci */
2338c2ecf20Sopenharmony_civoid media_device_cleanup(struct media_device *mdev);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci/**
2368c2ecf20Sopenharmony_ci * __media_device_register() - Registers a media device element
2378c2ecf20Sopenharmony_ci *
2388c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
2398c2ecf20Sopenharmony_ci * @owner:	should be filled with %THIS_MODULE
2408c2ecf20Sopenharmony_ci *
2418c2ecf20Sopenharmony_ci * Users, should, instead, call the media_device_register() macro.
2428c2ecf20Sopenharmony_ci *
2438c2ecf20Sopenharmony_ci * The caller is responsible for initializing the &media_device structure
2448c2ecf20Sopenharmony_ci * before registration. The following fields of &media_device must be set:
2458c2ecf20Sopenharmony_ci *
2468c2ecf20Sopenharmony_ci *  - &media_entity.dev must point to the parent device (usually a &pci_dev,
2478c2ecf20Sopenharmony_ci *    &usb_interface or &platform_device instance).
2488c2ecf20Sopenharmony_ci *
2498c2ecf20Sopenharmony_ci *  - &media_entity.model must be filled with the device model name as a
2508c2ecf20Sopenharmony_ci *    NUL-terminated UTF-8 string. The device/model revision must not be
2518c2ecf20Sopenharmony_ci *    stored in this field.
2528c2ecf20Sopenharmony_ci *
2538c2ecf20Sopenharmony_ci * The following fields are optional:
2548c2ecf20Sopenharmony_ci *
2558c2ecf20Sopenharmony_ci *  - &media_entity.serial is a unique serial number stored as a
2568c2ecf20Sopenharmony_ci *    NUL-terminated ASCII string. The field is big enough to store a GUID
2578c2ecf20Sopenharmony_ci *    in text form. If the hardware doesn't provide a unique serial number
2588c2ecf20Sopenharmony_ci *    this field must be left empty.
2598c2ecf20Sopenharmony_ci *
2608c2ecf20Sopenharmony_ci *  - &media_entity.bus_info represents the location of the device in the
2618c2ecf20Sopenharmony_ci *    system as a NUL-terminated ASCII string. For PCI/PCIe devices
2628c2ecf20Sopenharmony_ci *    &media_entity.bus_info must be set to "PCI:" (or "PCIe:") followed by
2638c2ecf20Sopenharmony_ci *    the value of pci_name(). For USB devices,the usb_make_path() function
2648c2ecf20Sopenharmony_ci *    must be used. This field is used by applications to distinguish between
2658c2ecf20Sopenharmony_ci *    otherwise identical devices that don't provide a serial number.
2668c2ecf20Sopenharmony_ci *
2678c2ecf20Sopenharmony_ci *  - &media_entity.hw_revision is the hardware device revision in a
2688c2ecf20Sopenharmony_ci *    driver-specific format. When possible the revision should be formatted
2698c2ecf20Sopenharmony_ci *    with the KERNEL_VERSION() macro.
2708c2ecf20Sopenharmony_ci *
2718c2ecf20Sopenharmony_ci * .. note::
2728c2ecf20Sopenharmony_ci *
2738c2ecf20Sopenharmony_ci *    #) Upon successful registration a character device named media[0-9]+ is created. The device major and minor numbers are dynamic. The model name is exported as a sysfs attribute.
2748c2ecf20Sopenharmony_ci *
2758c2ecf20Sopenharmony_ci *    #) Unregistering a media device that hasn't been registered is **NOT** safe.
2768c2ecf20Sopenharmony_ci *
2778c2ecf20Sopenharmony_ci * Return: returns zero on success or a negative error code.
2788c2ecf20Sopenharmony_ci */
2798c2ecf20Sopenharmony_ciint __must_check __media_device_register(struct media_device *mdev,
2808c2ecf20Sopenharmony_ci					 struct module *owner);
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci/**
2848c2ecf20Sopenharmony_ci * media_device_register() - Registers a media device element
2858c2ecf20Sopenharmony_ci *
2868c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
2878c2ecf20Sopenharmony_ci *
2888c2ecf20Sopenharmony_ci * This macro calls __media_device_register() passing %THIS_MODULE as
2898c2ecf20Sopenharmony_ci * the __media_device_register() second argument (**owner**).
2908c2ecf20Sopenharmony_ci */
2918c2ecf20Sopenharmony_ci#define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE)
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/**
2948c2ecf20Sopenharmony_ci * media_device_unregister() - Unregisters a media device element
2958c2ecf20Sopenharmony_ci *
2968c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
2978c2ecf20Sopenharmony_ci *
2988c2ecf20Sopenharmony_ci * It is safe to call this function on an unregistered (but initialised)
2998c2ecf20Sopenharmony_ci * media device.
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_civoid media_device_unregister(struct media_device *mdev);
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/**
3048c2ecf20Sopenharmony_ci * media_device_register_entity() - registers a media entity inside a
3058c2ecf20Sopenharmony_ci *	previously registered media device.
3068c2ecf20Sopenharmony_ci *
3078c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
3088c2ecf20Sopenharmony_ci * @entity:	pointer to struct &media_entity to be registered
3098c2ecf20Sopenharmony_ci *
3108c2ecf20Sopenharmony_ci * Entities are identified by a unique positive integer ID. The media
3118c2ecf20Sopenharmony_ci * controller framework will such ID automatically. IDs are not guaranteed
3128c2ecf20Sopenharmony_ci * to be contiguous, and the ID number can change on newer Kernel versions.
3138c2ecf20Sopenharmony_ci * So, neither the driver nor userspace should hardcode ID numbers to refer
3148c2ecf20Sopenharmony_ci * to the entities, but, instead, use the framework to find the ID, when
3158c2ecf20Sopenharmony_ci * needed.
3168c2ecf20Sopenharmony_ci *
3178c2ecf20Sopenharmony_ci * The media_entity name, type and flags fields should be initialized before
3188c2ecf20Sopenharmony_ci * calling media_device_register_entity(). Entities embedded in higher-level
3198c2ecf20Sopenharmony_ci * standard structures can have some of those fields set by the higher-level
3208c2ecf20Sopenharmony_ci * framework.
3218c2ecf20Sopenharmony_ci *
3228c2ecf20Sopenharmony_ci * If the device has pads, media_entity_pads_init() should be called before
3238c2ecf20Sopenharmony_ci * this function. Otherwise, the &media_entity.pad and &media_entity.num_pads
3248c2ecf20Sopenharmony_ci * should be zeroed before calling this function.
3258c2ecf20Sopenharmony_ci *
3268c2ecf20Sopenharmony_ci * Entities have flags that describe the entity capabilities and state:
3278c2ecf20Sopenharmony_ci *
3288c2ecf20Sopenharmony_ci * %MEDIA_ENT_FL_DEFAULT
3298c2ecf20Sopenharmony_ci *    indicates the default entity for a given type.
3308c2ecf20Sopenharmony_ci *    This can be used to report the default audio and video devices or the
3318c2ecf20Sopenharmony_ci *    default camera sensor.
3328c2ecf20Sopenharmony_ci *
3338c2ecf20Sopenharmony_ci * .. note::
3348c2ecf20Sopenharmony_ci *
3358c2ecf20Sopenharmony_ci *    Drivers should set the entity function before calling this function.
3368c2ecf20Sopenharmony_ci *    Please notice that the values %MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN and
3378c2ecf20Sopenharmony_ci *    %MEDIA_ENT_F_UNKNOWN should not be used by the drivers.
3388c2ecf20Sopenharmony_ci */
3398c2ecf20Sopenharmony_ciint __must_check media_device_register_entity(struct media_device *mdev,
3408c2ecf20Sopenharmony_ci					      struct media_entity *entity);
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci/**
3438c2ecf20Sopenharmony_ci * media_device_unregister_entity() - unregisters a media entity.
3448c2ecf20Sopenharmony_ci *
3458c2ecf20Sopenharmony_ci * @entity:	pointer to struct &media_entity to be unregistered
3468c2ecf20Sopenharmony_ci *
3478c2ecf20Sopenharmony_ci * All links associated with the entity and all PADs are automatically
3488c2ecf20Sopenharmony_ci * unregistered from the media_device when this function is called.
3498c2ecf20Sopenharmony_ci *
3508c2ecf20Sopenharmony_ci * Unregistering an entity will not change the IDs of the other entities and
3518c2ecf20Sopenharmony_ci * the previoully used ID will never be reused for a newly registered entities.
3528c2ecf20Sopenharmony_ci *
3538c2ecf20Sopenharmony_ci * When a media device is unregistered, all its entities are unregistered
3548c2ecf20Sopenharmony_ci * automatically. No manual entities unregistration is then required.
3558c2ecf20Sopenharmony_ci *
3568c2ecf20Sopenharmony_ci * .. note::
3578c2ecf20Sopenharmony_ci *
3588c2ecf20Sopenharmony_ci *    The media_entity instance itself must be freed explicitly by
3598c2ecf20Sopenharmony_ci *    the driver if required.
3608c2ecf20Sopenharmony_ci */
3618c2ecf20Sopenharmony_civoid media_device_unregister_entity(struct media_entity *entity);
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci/**
3648c2ecf20Sopenharmony_ci * media_device_register_entity_notify() - Registers a media entity_notify
3658c2ecf20Sopenharmony_ci *					   callback
3668c2ecf20Sopenharmony_ci *
3678c2ecf20Sopenharmony_ci * @mdev:      The media device
3688c2ecf20Sopenharmony_ci * @nptr:      The media_entity_notify
3698c2ecf20Sopenharmony_ci *
3708c2ecf20Sopenharmony_ci * .. note::
3718c2ecf20Sopenharmony_ci *
3728c2ecf20Sopenharmony_ci *    When a new entity is registered, all the registered
3738c2ecf20Sopenharmony_ci *    media_entity_notify callbacks are invoked.
3748c2ecf20Sopenharmony_ci */
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ciint __must_check media_device_register_entity_notify(struct media_device *mdev,
3778c2ecf20Sopenharmony_ci					struct media_entity_notify *nptr);
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci/**
3808c2ecf20Sopenharmony_ci * media_device_unregister_entity_notify() - Unregister a media entity notify
3818c2ecf20Sopenharmony_ci *					     callback
3828c2ecf20Sopenharmony_ci *
3838c2ecf20Sopenharmony_ci * @mdev:      The media device
3848c2ecf20Sopenharmony_ci * @nptr:      The media_entity_notify
3858c2ecf20Sopenharmony_ci *
3868c2ecf20Sopenharmony_ci */
3878c2ecf20Sopenharmony_civoid media_device_unregister_entity_notify(struct media_device *mdev,
3888c2ecf20Sopenharmony_ci					struct media_entity_notify *nptr);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci/* Iterate over all entities. */
3918c2ecf20Sopenharmony_ci#define media_device_for_each_entity(entity, mdev)			\
3928c2ecf20Sopenharmony_ci	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci/* Iterate over all interfaces. */
3958c2ecf20Sopenharmony_ci#define media_device_for_each_intf(intf, mdev)			\
3968c2ecf20Sopenharmony_ci	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci/* Iterate over all pads. */
3998c2ecf20Sopenharmony_ci#define media_device_for_each_pad(pad, mdev)			\
4008c2ecf20Sopenharmony_ci	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci/* Iterate over all links. */
4038c2ecf20Sopenharmony_ci#define media_device_for_each_link(link, mdev)			\
4048c2ecf20Sopenharmony_ci	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/**
4078c2ecf20Sopenharmony_ci * media_device_pci_init() - create and initialize a
4088c2ecf20Sopenharmony_ci *	struct &media_device from a PCI device.
4098c2ecf20Sopenharmony_ci *
4108c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
4118c2ecf20Sopenharmony_ci * @pci_dev:	pointer to struct pci_dev
4128c2ecf20Sopenharmony_ci * @name:	media device name. If %NULL, the routine will use the default
4138c2ecf20Sopenharmony_ci *		name for the pci device, given by pci_name() macro.
4148c2ecf20Sopenharmony_ci */
4158c2ecf20Sopenharmony_civoid media_device_pci_init(struct media_device *mdev,
4168c2ecf20Sopenharmony_ci			   struct pci_dev *pci_dev,
4178c2ecf20Sopenharmony_ci			   const char *name);
4188c2ecf20Sopenharmony_ci/**
4198c2ecf20Sopenharmony_ci * __media_device_usb_init() - create and initialize a
4208c2ecf20Sopenharmony_ci *	struct &media_device from a PCI device.
4218c2ecf20Sopenharmony_ci *
4228c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
4238c2ecf20Sopenharmony_ci * @udev:	pointer to struct usb_device
4248c2ecf20Sopenharmony_ci * @board_name:	media device name. If %NULL, the routine will use the usb
4258c2ecf20Sopenharmony_ci *		product name, if available.
4268c2ecf20Sopenharmony_ci * @driver_name: name of the driver. if %NULL, the routine will use the name
4278c2ecf20Sopenharmony_ci *		given by ``udev->dev->driver->name``, with is usually the wrong
4288c2ecf20Sopenharmony_ci *		thing to do.
4298c2ecf20Sopenharmony_ci *
4308c2ecf20Sopenharmony_ci * .. note::
4318c2ecf20Sopenharmony_ci *
4328c2ecf20Sopenharmony_ci *    It is better to call media_device_usb_init() instead, as
4338c2ecf20Sopenharmony_ci *    such macro fills driver_name with %KBUILD_MODNAME.
4348c2ecf20Sopenharmony_ci */
4358c2ecf20Sopenharmony_civoid __media_device_usb_init(struct media_device *mdev,
4368c2ecf20Sopenharmony_ci			     struct usb_device *udev,
4378c2ecf20Sopenharmony_ci			     const char *board_name,
4388c2ecf20Sopenharmony_ci			     const char *driver_name);
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci#else
4418c2ecf20Sopenharmony_cistatic inline int media_device_register(struct media_device *mdev)
4428c2ecf20Sopenharmony_ci{
4438c2ecf20Sopenharmony_ci	return 0;
4448c2ecf20Sopenharmony_ci}
4458c2ecf20Sopenharmony_cistatic inline void media_device_unregister(struct media_device *mdev)
4468c2ecf20Sopenharmony_ci{
4478c2ecf20Sopenharmony_ci}
4488c2ecf20Sopenharmony_cistatic inline int media_device_register_entity(struct media_device *mdev,
4498c2ecf20Sopenharmony_ci						struct media_entity *entity)
4508c2ecf20Sopenharmony_ci{
4518c2ecf20Sopenharmony_ci	return 0;
4528c2ecf20Sopenharmony_ci}
4538c2ecf20Sopenharmony_cistatic inline void media_device_unregister_entity(struct media_entity *entity)
4548c2ecf20Sopenharmony_ci{
4558c2ecf20Sopenharmony_ci}
4568c2ecf20Sopenharmony_cistatic inline int media_device_register_entity_notify(
4578c2ecf20Sopenharmony_ci					struct media_device *mdev,
4588c2ecf20Sopenharmony_ci					struct media_entity_notify *nptr)
4598c2ecf20Sopenharmony_ci{
4608c2ecf20Sopenharmony_ci	return 0;
4618c2ecf20Sopenharmony_ci}
4628c2ecf20Sopenharmony_cistatic inline void media_device_unregister_entity_notify(
4638c2ecf20Sopenharmony_ci					struct media_device *mdev,
4648c2ecf20Sopenharmony_ci					struct media_entity_notify *nptr)
4658c2ecf20Sopenharmony_ci{
4668c2ecf20Sopenharmony_ci}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_cistatic inline void media_device_pci_init(struct media_device *mdev,
4698c2ecf20Sopenharmony_ci					 struct pci_dev *pci_dev,
4708c2ecf20Sopenharmony_ci					 char *name)
4718c2ecf20Sopenharmony_ci{
4728c2ecf20Sopenharmony_ci}
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_cistatic inline void __media_device_usb_init(struct media_device *mdev,
4758c2ecf20Sopenharmony_ci					   struct usb_device *udev,
4768c2ecf20Sopenharmony_ci					   char *board_name,
4778c2ecf20Sopenharmony_ci					   char *driver_name)
4788c2ecf20Sopenharmony_ci{
4798c2ecf20Sopenharmony_ci}
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci#endif /* CONFIG_MEDIA_CONTROLLER */
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci/**
4848c2ecf20Sopenharmony_ci * media_device_usb_init() - create and initialize a
4858c2ecf20Sopenharmony_ci *	struct &media_device from a PCI device.
4868c2ecf20Sopenharmony_ci *
4878c2ecf20Sopenharmony_ci * @mdev:	pointer to struct &media_device
4888c2ecf20Sopenharmony_ci * @udev:	pointer to struct usb_device
4898c2ecf20Sopenharmony_ci * @name:	media device name. If %NULL, the routine will use the usb
4908c2ecf20Sopenharmony_ci *		product name, if available.
4918c2ecf20Sopenharmony_ci *
4928c2ecf20Sopenharmony_ci * This macro calls media_device_usb_init() passing the
4938c2ecf20Sopenharmony_ci * media_device_usb_init() **driver_name** parameter filled with
4948c2ecf20Sopenharmony_ci * %KBUILD_MODNAME.
4958c2ecf20Sopenharmony_ci */
4968c2ecf20Sopenharmony_ci#define media_device_usb_init(mdev, udev, name) \
4978c2ecf20Sopenharmony_ci	__media_device_usb_init(mdev, udev, name, KBUILD_MODNAME)
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci#endif
500