Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / media / media-entity.h
CommitLineData
53e269c1
LP
1/*
2 * Media entity
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _MEDIA_ENTITY_H
24#define _MEDIA_ENTITY_H
25
26#include <linux/list.h>
1651333b 27#include <linux/media.h>
53e269c1 28
e02188c9
LP
29struct media_pipeline {
30};
31
53e269c1
LP
32struct media_link {
33 struct media_pad *source; /* Source pad */
34 struct media_pad *sink; /* Sink pad */
35 struct media_link *reverse; /* Link in the reverse direction */
36 unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
37};
38
39struct media_pad {
40 struct media_entity *entity; /* Entity this pad belongs to */
41 u16 index; /* Pad index in the entity pads array */
42 unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
43};
44
97548ed4
LP
45struct media_entity_operations {
46 int (*link_setup)(struct media_entity *entity,
47 const struct media_pad *local,
48 const struct media_pad *remote, u32 flags);
af88be38 49 int (*link_validate)(struct media_link *link);
97548ed4
LP
50};
51
53e269c1
LP
52struct media_entity {
53 struct list_head list;
54 struct media_device *parent; /* Media device this entity belongs to*/
55 u32 id; /* Entity ID, unique in the parent media
56 * device context */
57 const char *name; /* Entity name */
58 u32 type; /* Entity type (MEDIA_ENT_T_*) */
59 u32 revision; /* Entity revision, driver specific */
60 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
61 u32 group_id; /* Entity group ID */
62
63 u16 num_pads; /* Number of sink and source pads */
64 u16 num_links; /* Number of existing links, both
65 * enabled and disabled */
66 u16 num_backlinks; /* Number of backlinks */
67 u16 max_links; /* Maximum number of links */
68
69 struct media_pad *pads; /* Pads array (num_pads elements) */
70 struct media_link *links; /* Links array (max_links elements)*/
71
97548ed4
LP
72 const struct media_entity_operations *ops; /* Entity operations */
73
503c3d82
LP
74 /* Reference counts must never be negative, but are signed integers on
75 * purpose: a simple WARN_ON(<0) check can be used to detect reference
76 * count bugs that would make them negative.
77 */
e02188c9 78 int stream_count; /* Stream count for the entity. */
503c3d82
LP
79 int use_count; /* Use count for the entity. */
80
e02188c9
LP
81 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
82
53e269c1
LP
83 union {
84 /* Node specifications */
85 struct {
86 u32 major;
87 u32 minor;
88 } v4l;
89 struct {
90 u32 major;
91 u32 minor;
92 } fb;
93 struct {
94 u32 card;
95 u32 device;
96 u32 subdevice;
97 } alsa;
98 int dvb;
99
100 /* Sub-device specifications */
101 /* Nothing needed yet */
fa5034c6 102 } info;
53e269c1
LP
103};
104
105static inline u32 media_entity_type(struct media_entity *entity)
106{
107 return entity->type & MEDIA_ENT_TYPE_MASK;
108}
109
110static inline u32 media_entity_subtype(struct media_entity *entity)
111{
112 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
113}
114
a5ccc48a
SA
115#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
116
117struct media_entity_graph {
118 struct {
119 struct media_entity *entity;
120 int link;
121 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
122 int top;
123};
124
53e269c1
LP
125int media_entity_init(struct media_entity *entity, u16 num_pads,
126 struct media_pad *pads, u16 extra_links);
127void media_entity_cleanup(struct media_entity *entity);
e02188c9 128
53e269c1
LP
129int media_entity_create_link(struct media_entity *source, u16 source_pad,
130 struct media_entity *sink, u16 sink_pad, u32 flags);
97548ed4
LP
131int __media_entity_setup_link(struct media_link *link, u32 flags);
132int media_entity_setup_link(struct media_link *link, u32 flags);
133struct media_link *media_entity_find_link(struct media_pad *source,
134 struct media_pad *sink);
135struct media_pad *media_entity_remote_source(struct media_pad *pad);
53e269c1 136
503c3d82
LP
137struct media_entity *media_entity_get(struct media_entity *entity);
138void media_entity_put(struct media_entity *entity);
139
a5ccc48a
SA
140void media_entity_graph_walk_start(struct media_entity_graph *graph,
141 struct media_entity *entity);
142struct media_entity *
143media_entity_graph_walk_next(struct media_entity_graph *graph);
af88be38
SA
144__must_check int media_entity_pipeline_start(struct media_entity *entity,
145 struct media_pipeline *pipe);
e02188c9 146void media_entity_pipeline_stop(struct media_entity *entity);
a5ccc48a 147
97548ed4
LP
148#define media_entity_call(entity, operation, args...) \
149 (((entity)->ops && (entity)->ops->operation) ? \
150 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
151
53e269c1 152#endif