2019-05-27 06:55:21 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-12-09 11:39:58 +00:00
|
|
|
/*
|
|
|
|
* Media device
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
|
|
|
|
* Sakari Ailus <sakari.ailus@iki.fi>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MEDIA_DEVICE_H
|
|
|
|
#define _MEDIA_DEVICE_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2010-03-07 18:04:59 +00:00
|
|
|
#include <linux/mutex.h>
|
2022-01-22 11:25:57 +00:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/platform_device.h>
|
2009-12-09 11:39:58 +00:00
|
|
|
|
|
|
|
#include <media/media-devnode.h>
|
2009-12-09 11:40:00 +00:00
|
|
|
#include <media/media-entity.h>
|
2009-12-09 11:39:58 +00:00
|
|
|
|
2015-12-16 13:32:17 +00:00
|
|
|
struct ida;
|
2018-05-21 08:54:27 +00:00
|
|
|
struct media_device;
|
2012-01-30 16:46:54 +00:00
|
|
|
|
2016-02-11 23:41:21 +00:00
|
|
|
/**
|
|
|
|
* struct media_entity_notify - Media Entity Notify
|
|
|
|
*
|
|
|
|
* @list: List head
|
|
|
|
* @notify_data: Input data to invoke the callback
|
|
|
|
* @notify: Callback function pointer
|
|
|
|
*
|
2016-03-14 22:24:25 +00:00
|
|
|
* Drivers may register a callback to take action when new entities get
|
|
|
|
* registered with the media device. This handler is intended for creating
|
|
|
|
* links between existing entities and should not create entities and register
|
|
|
|
* them.
|
2016-02-11 23:41:21 +00:00
|
|
|
*/
|
|
|
|
struct media_entity_notify {
|
|
|
|
struct list_head list;
|
|
|
|
void *notify_data;
|
|
|
|
void (*notify)(struct media_entity *entity, void *notify_data);
|
|
|
|
};
|
|
|
|
|
2015-11-03 02:27:51 +00:00
|
|
|
/**
|
|
|
|
* struct media_device_ops - Media device operations
|
|
|
|
* @link_notify: Link state change notification callback. This callback is
|
|
|
|
* called with the graph_mutex held.
|
2018-05-21 08:54:27 +00:00
|
|
|
* @req_alloc: Allocate a request. Set this if you need to allocate a struct
|
|
|
|
* larger then struct media_request. @req_alloc and @req_free must
|
|
|
|
* either both be set or both be NULL.
|
|
|
|
* @req_free: Free a request. Set this if @req_alloc was set as well, leave
|
|
|
|
* to NULL otherwise.
|
|
|
|
* @req_validate: Validate a request, but do not queue yet. The req_queue_mutex
|
|
|
|
* lock is held when this op is called.
|
|
|
|
* @req_queue: Queue a validated request, cannot fail. If something goes
|
|
|
|
* wrong when queueing this request then it should be marked
|
|
|
|
* as such internally in the driver and any related buffers
|
|
|
|
* must eventually return to vb2 with state VB2_BUF_STATE_ERROR.
|
|
|
|
* The req_queue_mutex lock is held when this op is called.
|
|
|
|
* It is important that vb2 buffer objects are queued last after
|
|
|
|
* all other object types are queued: queueing a buffer kickstarts
|
|
|
|
* the request processing, so all other objects related to the
|
|
|
|
* request (and thus the buffer) must be available to the driver.
|
|
|
|
* And once a buffer is queued, then the driver can complete
|
|
|
|
* or delete objects from the request before req_queue exits.
|
2015-11-03 02:27:51 +00:00
|
|
|
*/
|
|
|
|
struct media_device_ops {
|
|
|
|
int (*link_notify)(struct media_link *link, u32 flags,
|
|
|
|
unsigned int notification);
|
2018-05-21 08:54:27 +00:00
|
|
|
struct media_request *(*req_alloc)(struct media_device *mdev);
|
|
|
|
void (*req_free)(struct media_request *req);
|
|
|
|
int (*req_validate)(struct media_request *req);
|
|
|
|
void (*req_queue)(struct media_request *req);
|
2015-11-03 02:27:51 +00:00
|
|
|
};
|
|
|
|
|
2009-12-09 11:39:58 +00:00
|
|
|
/**
|
|
|
|
* struct media_device - Media device
|
|
|
|
* @dev: Parent device
|
|
|
|
* @devnode: Media device node
|
2016-02-11 16:24:23 +00:00
|
|
|
* @driver_name: Optional device driver name. If not set, calls to
|
2016-08-29 19:09:11 +00:00
|
|
|
* %MEDIA_IOC_DEVICE_INFO will return ``dev->driver->name``.
|
2016-02-11 16:24:23 +00:00
|
|
|
* This is needed for USB drivers for example, as otherwise
|
|
|
|
* they'll all appear as if the driver name was "usb".
|
2009-12-09 11:39:58 +00:00
|
|
|
* @model: Device model name
|
|
|
|
* @serial: Device serial number (optional)
|
|
|
|
* @bus_info: Unique and stable device location identifier
|
|
|
|
* @hw_revision: Hardware device revision
|
2015-08-23 12:40:26 +00:00
|
|
|
* @topology_version: Monotonic counter for storing the version of the graph
|
|
|
|
* topology. Should be incremented each time the topology changes.
|
2015-12-16 16:28:01 +00:00
|
|
|
* @id: Unique ID used on the last registered graph object
|
2015-12-16 15:58:31 +00:00
|
|
|
* @entity_internal_idx: Unique internal entity ID used by the graph traversal
|
|
|
|
* algorithms
|
|
|
|
* @entity_internal_idx_max: Allocated internal entity indices
|
2009-12-09 11:40:00 +00:00
|
|
|
* @entities: List of registered entities
|
2015-08-21 12:23:22 +00:00
|
|
|
* @interfaces: List of registered interfaces
|
2015-08-23 11:00:33 +00:00
|
|
|
* @pads: List of registered pads
|
|
|
|
* @links: List of registered links
|
2016-02-11 23:41:21 +00:00
|
|
|
* @entity_notify: List of registered entity_notify callbacks
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 13:55:24 +00:00
|
|
|
* @graph_mutex: Protects access to struct media_device data
|
2016-02-21 16:25:08 +00:00
|
|
|
* @pm_count_walk: Graph walk for power state walk. Access serialised using
|
|
|
|
* graph_mutex.
|
2016-02-11 23:41:22 +00:00
|
|
|
*
|
|
|
|
* @source_priv: Driver Private data for enable/disable source handlers
|
|
|
|
* @enable_source: Enable Source Handler function pointer
|
|
|
|
* @disable_source: Disable Source Handler function pointer
|
|
|
|
*
|
2015-11-03 02:27:51 +00:00
|
|
|
* @ops: Operation handler callbacks
|
2018-05-21 08:54:27 +00:00
|
|
|
* @req_queue_mutex: Serialise the MEDIA_REQUEST_IOC_QUEUE ioctl w.r.t.
|
|
|
|
* other operations that stop or start streaming.
|
|
|
|
* @request_id: Used to generate unique request IDs
|
2009-12-09 11:39:58 +00:00
|
|
|
*
|
|
|
|
* This structure represents an abstract high-level media device. It allows easy
|
|
|
|
* access to entities and provides basic media device-level support. The
|
|
|
|
* structure can be allocated directly or embedded in a larger structure.
|
|
|
|
*
|
|
|
|
* The parent @dev is a physical device. It must be set before registering the
|
|
|
|
* media device.
|
|
|
|
*
|
|
|
|
* @model is a descriptive model name exported through sysfs. It doesn't have to
|
|
|
|
* be unique.
|
2016-02-11 23:41:22 +00:00
|
|
|
*
|
|
|
|
* @enable_source is a handler to find source entity for the
|
|
|
|
* sink entity and activate the link between them if source
|
|
|
|
* entity is free. Drivers should call this handler before
|
|
|
|
* accessing the source.
|
|
|
|
*
|
|
|
|
* @disable_source is a handler to find source entity for the
|
|
|
|
* sink entity and deactivate the link between them. Drivers
|
|
|
|
* should call this handler to release the source.
|
|
|
|
*
|
|
|
|
* Use-case: find tuner entity connected to the decoder
|
|
|
|
* entity and check if it is available, and activate the
|
2020-07-14 22:05:49 +00:00
|
|
|
* link between them from @enable_source and deactivate
|
2016-08-29 19:09:11 +00:00
|
|
|
* from @disable_source.
|
|
|
|
*
|
|
|
|
* .. note::
|
|
|
|
*
|
|
|
|
* Bridge driver is expected to implement and set the
|
|
|
|
* handler when &media_device is registered or when
|
|
|
|
* bridge driver finds the media_device during probe.
|
|
|
|
* Bridge driver sets source_priv with information
|
|
|
|
* necessary to run @enable_source and @disable_source handlers.
|
2016-11-29 23:59:54 +00:00
|
|
|
* Callers should hold graph_mutex to access and call @enable_source
|
|
|
|
* and @disable_source handlers.
|
2009-12-09 11:39:58 +00:00
|
|
|
*/
|
|
|
|
struct media_device {
|
|
|
|
/* dev->driver_data points to this struct. */
|
|
|
|
struct device *dev;
|
2016-04-27 22:28:26 +00:00
|
|
|
struct media_devnode *devnode;
|
2009-12-09 11:39:58 +00:00
|
|
|
|
|
|
|
char model[32];
|
2016-02-11 16:24:23 +00:00
|
|
|
char driver_name[32];
|
2009-12-09 11:39:58 +00:00
|
|
|
char serial[40];
|
|
|
|
char bus_info[32];
|
|
|
|
u32 hw_revision;
|
2009-12-09 11:40:00 +00:00
|
|
|
|
2016-03-16 12:34:39 +00:00
|
|
|
u64 topology_version;
|
2015-08-23 12:40:26 +00:00
|
|
|
|
2015-12-16 16:28:01 +00:00
|
|
|
u32 id;
|
2015-12-16 13:32:17 +00:00
|
|
|
struct ida entity_internal_idx;
|
|
|
|
int entity_internal_idx_max;
|
2015-08-14 15:47:48 +00:00
|
|
|
|
2009-12-09 11:40:00 +00:00
|
|
|
struct list_head entities;
|
2015-08-21 12:23:22 +00:00
|
|
|
struct list_head interfaces;
|
2015-08-23 11:00:33 +00:00
|
|
|
struct list_head pads;
|
|
|
|
struct list_head links;
|
2009-12-09 11:40:00 +00:00
|
|
|
|
2016-02-11 23:41:21 +00:00
|
|
|
/* notify callback list invoked when a new entity is registered */
|
|
|
|
struct list_head entity_notify;
|
|
|
|
|
2010-03-07 18:04:59 +00:00
|
|
|
/* Serializes graph operations. */
|
|
|
|
struct mutex graph_mutex;
|
2016-11-21 16:48:30 +00:00
|
|
|
struct media_graph pm_count_walk;
|
2009-12-09 11:40:03 +00:00
|
|
|
|
2016-02-11 23:41:22 +00:00
|
|
|
void *source_priv;
|
|
|
|
int (*enable_source)(struct media_entity *entity,
|
|
|
|
struct media_pipeline *pipe);
|
|
|
|
void (*disable_source)(struct media_entity *entity);
|
|
|
|
|
2015-11-03 02:27:51 +00:00
|
|
|
const struct media_device_ops *ops;
|
2018-05-21 08:54:27 +00:00
|
|
|
|
|
|
|
struct mutex req_queue_mutex;
|
|
|
|
atomic_t request_id;
|
2009-12-09 11:39:58 +00:00
|
|
|
};
|
|
|
|
|
2022-01-22 11:25:57 +00:00
|
|
|
/* We don't need to include usb.h here */
|
2016-02-22 14:42:04 +00:00
|
|
|
struct usb_device;
|
|
|
|
|
2015-06-05 20:11:54 +00:00
|
|
|
#ifdef CONFIG_MEDIA_CONTROLLER
|
|
|
|
|
2013-05-31 13:37:26 +00:00
|
|
|
/* Supported link_notify @notification values. */
|
|
|
|
#define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
|
|
|
|
#define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
|
|
|
|
|
2015-12-11 22:57:08 +00:00
|
|
|
/**
|
|
|
|
* media_device_init() - Initializes a media device element
|
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
|
|
|
*
|
|
|
|
* This function initializes the media device prior to its registration.
|
|
|
|
* The media device initialization and registration is split in two functions
|
|
|
|
* to avoid race conditions and make the media device available to user-space
|
|
|
|
* before the media graph has been completed.
|
|
|
|
*
|
|
|
|
* So drivers need to first initialize the media device, register any entity
|
|
|
|
* within the media device, create pad to pad links and then finally register
|
|
|
|
* the media device by calling media_device_register() as a final step.
|
2022-01-27 09:25:48 +00:00
|
|
|
*
|
|
|
|
* The caller is responsible for initializing the media device before
|
|
|
|
* registration. The following fields must be set:
|
|
|
|
*
|
|
|
|
* - dev must point to the parent device
|
|
|
|
* - model must be filled with the device model name
|
2022-01-22 11:31:37 +00:00
|
|
|
*
|
|
|
|
* The bus_info field is set by media_device_init() for PCI and platform devices
|
|
|
|
* if the field begins with '\0'.
|
2015-12-11 22:57:08 +00:00
|
|
|
*/
|
|
|
|
void media_device_init(struct media_device *mdev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* media_device_cleanup() - Cleanups a media device element
|
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
|
|
|
*
|
|
|
|
* This function that will destroy the graph_mutex that is
|
|
|
|
* initialized in media_device_init().
|
|
|
|
*/
|
|
|
|
void media_device_cleanup(struct media_device *mdev);
|
|
|
|
|
2015-12-11 13:06:08 +00:00
|
|
|
/**
|
|
|
|
* __media_device_register() - Registers a media device element
|
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
|
|
|
* @owner: should be filled with %THIS_MODULE
|
|
|
|
*
|
|
|
|
* Users, should, instead, call the media_device_register() macro.
|
|
|
|
*
|
2016-08-29 19:09:11 +00:00
|
|
|
* The caller is responsible for initializing the &media_device structure
|
|
|
|
* before registration. The following fields of &media_device must be set:
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
2022-03-09 09:12:01 +00:00
|
|
|
* - &media_device.model must be filled with the device model name as a
|
2016-08-29 19:09:11 +00:00
|
|
|
* NUL-terminated UTF-8 string. The device/model revision must not be
|
|
|
|
* stored in this field.
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
|
|
|
* The following fields are optional:
|
|
|
|
*
|
2022-03-09 09:12:01 +00:00
|
|
|
* - &media_device.serial is a unique serial number stored as a
|
2016-08-29 19:09:11 +00:00
|
|
|
* NUL-terminated ASCII string. The field is big enough to store a GUID
|
|
|
|
* in text form. If the hardware doesn't provide a unique serial number
|
|
|
|
* this field must be left empty.
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
2022-03-09 09:12:01 +00:00
|
|
|
* - &media_device.bus_info represents the location of the device in the
|
2016-08-29 19:09:11 +00:00
|
|
|
* system as a NUL-terminated ASCII string. For PCI/PCIe devices
|
2022-03-09 09:12:01 +00:00
|
|
|
* &media_device.bus_info must be set to "PCI:" (or "PCIe:") followed by
|
2016-08-29 19:09:11 +00:00
|
|
|
* the value of pci_name(). For USB devices,the usb_make_path() function
|
|
|
|
* must be used. This field is used by applications to distinguish between
|
|
|
|
* otherwise identical devices that don't provide a serial number.
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
2022-03-09 09:12:01 +00:00
|
|
|
* - &media_device.hw_revision is the hardware device revision in a
|
2016-08-29 19:09:11 +00:00
|
|
|
* driver-specific format. When possible the revision should be formatted
|
|
|
|
* with the KERNEL_VERSION() macro.
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
2016-07-17 12:18:03 +00:00
|
|
|
* .. note::
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
2016-07-17 12:18:03 +00:00
|
|
|
* #) 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.
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
2016-07-17 12:18:03 +00:00
|
|
|
* #) Unregistering a media device that hasn't been registered is **NOT** safe.
|
2015-12-16 15:53:04 +00:00
|
|
|
*
|
|
|
|
* Return: returns zero on success or a negative error code.
|
2015-12-11 13:06:08 +00:00
|
|
|
*/
|
2013-12-12 15:38:17 +00:00
|
|
|
int __must_check __media_device_register(struct media_device *mdev,
|
|
|
|
struct module *owner);
|
2016-08-29 19:09:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* media_device_register() - Registers a media device element
|
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
|
|
|
*
|
|
|
|
* This macro calls __media_device_register() passing %THIS_MODULE as
|
|
|
|
* the __media_device_register() second argument (**owner**).
|
|
|
|
*/
|
2013-12-12 15:38:17 +00:00
|
|
|
#define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE)
|
2015-12-11 13:06:08 +00:00
|
|
|
|
|
|
|
/**
|
2016-03-16 12:04:03 +00:00
|
|
|
* media_device_unregister() - Unregisters a media device element
|
2015-12-11 13:06:08 +00:00
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
2015-12-16 15:53:04 +00:00
|
|
|
*
|
|
|
|
* It is safe to call this function on an unregistered (but initialised)
|
|
|
|
* media device.
|
2015-12-11 13:06:08 +00:00
|
|
|
*/
|
2009-12-09 11:39:58 +00:00
|
|
|
void media_device_unregister(struct media_device *mdev);
|
|
|
|
|
2015-12-11 13:06:08 +00:00
|
|
|
/**
|
|
|
|
* media_device_register_entity() - registers a media entity inside a
|
|
|
|
* previously registered media device.
|
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
|
|
|
* @entity: pointer to struct &media_entity to be registered
|
|
|
|
*
|
|
|
|
* Entities are identified by a unique positive integer ID. The media
|
|
|
|
* controller framework will such ID automatically. IDs are not guaranteed
|
|
|
|
* to be contiguous, and the ID number can change on newer Kernel versions.
|
|
|
|
* So, neither the driver nor userspace should hardcode ID numbers to refer
|
|
|
|
* to the entities, but, instead, use the framework to find the ID, when
|
|
|
|
* needed.
|
|
|
|
*
|
|
|
|
* The media_entity name, type and flags fields should be initialized before
|
|
|
|
* calling media_device_register_entity(). Entities embedded in higher-level
|
|
|
|
* standard structures can have some of those fields set by the higher-level
|
|
|
|
* framework.
|
|
|
|
*
|
|
|
|
* If the device has pads, media_entity_pads_init() should be called before
|
2016-08-29 19:09:11 +00:00
|
|
|
* this function. Otherwise, the &media_entity.pad and &media_entity.num_pads
|
2015-12-11 13:06:08 +00:00
|
|
|
* should be zeroed before calling this function.
|
|
|
|
*
|
|
|
|
* Entities have flags that describe the entity capabilities and state:
|
|
|
|
*
|
2016-08-29 19:09:11 +00:00
|
|
|
* %MEDIA_ENT_FL_DEFAULT
|
|
|
|
* indicates the default entity for a given type.
|
|
|
|
* This can be used to report the default audio and video devices or the
|
|
|
|
* default camera sensor.
|
2015-12-11 14:41:12 +00:00
|
|
|
*
|
2016-07-17 12:18:03 +00:00
|
|
|
* .. note::
|
|
|
|
*
|
|
|
|
* Drivers should set the entity function before calling this function.
|
|
|
|
* Please notice that the values %MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN and
|
|
|
|
* %MEDIA_ENT_F_UNKNOWN should not be used by the drivers.
|
2015-12-11 13:06:08 +00:00
|
|
|
*/
|
2009-12-09 11:40:00 +00:00
|
|
|
int __must_check media_device_register_entity(struct media_device *mdev,
|
|
|
|
struct media_entity *entity);
|
2015-12-11 13:06:08 +00:00
|
|
|
|
2016-07-17 12:18:03 +00:00
|
|
|
/**
|
2015-12-11 13:06:08 +00:00
|
|
|
* media_device_unregister_entity() - unregisters a media entity.
|
|
|
|
*
|
|
|
|
* @entity: pointer to struct &media_entity to be unregistered
|
|
|
|
*
|
|
|
|
* All links associated with the entity and all PADs are automatically
|
|
|
|
* unregistered from the media_device when this function is called.
|
|
|
|
*
|
|
|
|
* Unregistering an entity will not change the IDs of the other entities and
|
|
|
|
* the previoully used ID will never be reused for a newly registered entities.
|
|
|
|
*
|
|
|
|
* When a media device is unregistered, all its entities are unregistered
|
|
|
|
* automatically. No manual entities unregistration is then required.
|
|
|
|
*
|
2016-07-17 12:18:03 +00:00
|
|
|
* .. note::
|
|
|
|
*
|
|
|
|
* The media_entity instance itself must be freed explicitly by
|
|
|
|
* the driver if required.
|
2015-12-11 13:06:08 +00:00
|
|
|
*/
|
2009-12-09 11:40:00 +00:00
|
|
|
void media_device_unregister_entity(struct media_entity *entity);
|
2015-12-13 10:36:58 +00:00
|
|
|
|
2016-02-11 23:41:21 +00:00
|
|
|
/**
|
|
|
|
* media_device_register_entity_notify() - Registers a media entity_notify
|
|
|
|
* callback
|
|
|
|
*
|
|
|
|
* @mdev: The media device
|
|
|
|
* @nptr: The media_entity_notify
|
|
|
|
*
|
2016-08-29 19:09:11 +00:00
|
|
|
* .. note::
|
|
|
|
*
|
|
|
|
* When a new entity is registered, all the registered
|
|
|
|
* media_entity_notify callbacks are invoked.
|
2016-02-11 23:41:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int __must_check media_device_register_entity_notify(struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* media_device_unregister_entity_notify() - Unregister a media entity notify
|
|
|
|
* callback
|
|
|
|
*
|
|
|
|
* @mdev: The media device
|
|
|
|
* @nptr: The media_entity_notify
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void media_device_unregister_entity_notify(struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr);
|
|
|
|
|
2009-12-09 11:40:00 +00:00
|
|
|
/* Iterate over all entities. */
|
|
|
|
#define media_device_for_each_entity(entity, mdev) \
|
2015-08-23 10:51:33 +00:00
|
|
|
list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
|
2009-12-09 11:40:00 +00:00
|
|
|
|
2015-08-23 10:51:22 +00:00
|
|
|
/* Iterate over all interfaces. */
|
|
|
|
#define media_device_for_each_intf(intf, mdev) \
|
2015-08-23 10:51:33 +00:00
|
|
|
list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
|
2015-08-23 10:51:22 +00:00
|
|
|
|
2015-08-23 11:00:33 +00:00
|
|
|
/* Iterate over all pads. */
|
|
|
|
#define media_device_for_each_pad(pad, mdev) \
|
|
|
|
list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
|
|
|
|
|
|
|
|
/* Iterate over all links. */
|
|
|
|
#define media_device_for_each_link(link, mdev) \
|
|
|
|
list_for_each_entry(link, &(mdev)->links, graph_obj.list)
|
2016-02-22 14:42:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* media_device_pci_init() - create and initialize a
|
|
|
|
* struct &media_device from a PCI device.
|
|
|
|
*
|
2016-02-22 15:10:49 +00:00
|
|
|
* @mdev: pointer to struct &media_device
|
2016-02-22 14:42:04 +00:00
|
|
|
* @pci_dev: pointer to struct pci_dev
|
|
|
|
* @name: media device name. If %NULL, the routine will use the default
|
|
|
|
* name for the pci device, given by pci_name() macro.
|
|
|
|
*/
|
2016-02-22 15:10:49 +00:00
|
|
|
void media_device_pci_init(struct media_device *mdev,
|
|
|
|
struct pci_dev *pci_dev,
|
|
|
|
const char *name);
|
2016-02-22 14:42:04 +00:00
|
|
|
/**
|
|
|
|
* __media_device_usb_init() - create and initialize a
|
|
|
|
* struct &media_device from a PCI device.
|
|
|
|
*
|
2016-02-22 15:10:49 +00:00
|
|
|
* @mdev: pointer to struct &media_device
|
2016-02-22 14:42:04 +00:00
|
|
|
* @udev: pointer to struct usb_device
|
|
|
|
* @board_name: media device name. If %NULL, the routine will use the usb
|
|
|
|
* product name, if available.
|
|
|
|
* @driver_name: name of the driver. if %NULL, the routine will use the name
|
2016-08-29 19:09:11 +00:00
|
|
|
* given by ``udev->dev->driver->name``, with is usually the wrong
|
2016-02-22 14:42:04 +00:00
|
|
|
* thing to do.
|
|
|
|
*
|
2016-08-29 19:09:11 +00:00
|
|
|
* .. note::
|
|
|
|
*
|
|
|
|
* It is better to call media_device_usb_init() instead, as
|
|
|
|
* such macro fills driver_name with %KBUILD_MODNAME.
|
2016-02-22 14:42:04 +00:00
|
|
|
*/
|
2016-02-22 15:10:49 +00:00
|
|
|
void __media_device_usb_init(struct media_device *mdev,
|
|
|
|
struct usb_device *udev,
|
|
|
|
const char *board_name,
|
|
|
|
const char *driver_name);
|
2016-02-22 14:42:04 +00:00
|
|
|
|
2015-06-05 20:11:54 +00:00
|
|
|
#else
|
|
|
|
static inline int media_device_register(struct media_device *mdev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void media_device_unregister(struct media_device *mdev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
static inline int media_device_register_entity(struct media_device *mdev,
|
|
|
|
struct media_entity *entity)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void media_device_unregister_entity(struct media_entity *entity)
|
|
|
|
{
|
|
|
|
}
|
2016-02-11 23:41:21 +00:00
|
|
|
static inline int media_device_register_entity_notify(
|
|
|
|
struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void media_device_unregister_entity_notify(
|
|
|
|
struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr)
|
|
|
|
{
|
|
|
|
}
|
2016-02-22 14:42:04 +00:00
|
|
|
|
2016-02-22 15:10:49 +00:00
|
|
|
static inline void media_device_pci_init(struct media_device *mdev,
|
|
|
|
struct pci_dev *pci_dev,
|
|
|
|
char *name)
|
2016-02-22 14:42:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-22 15:10:49 +00:00
|
|
|
static inline void __media_device_usb_init(struct media_device *mdev,
|
|
|
|
struct usb_device *udev,
|
|
|
|
char *board_name,
|
|
|
|
char *driver_name)
|
2016-02-22 14:42:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:11:54 +00:00
|
|
|
#endif /* CONFIG_MEDIA_CONTROLLER */
|
2016-02-22 14:42:04 +00:00
|
|
|
|
2016-08-29 19:09:11 +00:00
|
|
|
/**
|
|
|
|
* media_device_usb_init() - create and initialize a
|
|
|
|
* struct &media_device from a PCI device.
|
|
|
|
*
|
|
|
|
* @mdev: pointer to struct &media_device
|
|
|
|
* @udev: pointer to struct usb_device
|
|
|
|
* @name: media device name. If %NULL, the routine will use the usb
|
|
|
|
* product name, if available.
|
|
|
|
*
|
|
|
|
* This macro calls media_device_usb_init() passing the
|
|
|
|
* media_device_usb_init() **driver_name** parameter filled with
|
|
|
|
* %KBUILD_MODNAME.
|
|
|
|
*/
|
2016-02-22 15:10:49 +00:00
|
|
|
#define media_device_usb_init(mdev, udev, name) \
|
|
|
|
__media_device_usb_init(mdev, udev, name, KBUILD_MODNAME)
|
2016-02-22 14:42:04 +00:00
|
|
|
|
2022-01-22 11:25:57 +00:00
|
|
|
/**
|
|
|
|
* media_set_bus_info() - Set bus_info field
|
|
|
|
*
|
|
|
|
* @bus_info: Variable where to write the bus info (char array)
|
|
|
|
* @bus_info_size: Length of the bus_info
|
|
|
|
* @dev: Related struct device
|
|
|
|
*
|
|
|
|
* Sets bus information based on &dev. This is currently done for PCI and
|
|
|
|
* platform devices. dev is required to be non-NULL for this to happen.
|
|
|
|
*
|
|
|
|
* This function is not meant to be called from drivers.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
media_set_bus_info(char *bus_info, size_t bus_info_size, struct device *dev)
|
|
|
|
{
|
|
|
|
if (!dev)
|
|
|
|
strscpy(bus_info, "no bus info", bus_info_size);
|
|
|
|
else if (dev_is_platform(dev))
|
|
|
|
snprintf(bus_info, bus_info_size, "platform:%s", dev_name(dev));
|
|
|
|
else if (dev_is_pci(dev))
|
|
|
|
snprintf(bus_info, bus_info_size, "PCI:%s", dev_name(dev));
|
|
|
|
}
|
|
|
|
|
2009-12-09 11:39:58 +00:00
|
|
|
#endif
|