[media] media: Links setup
[firefly-linux-kernel-4.4.55.git] / include / media / media-entity.h
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>
27 #include <linux/media.h>
28
29 struct media_link {
30         struct media_pad *source;       /* Source pad */
31         struct media_pad *sink;         /* Sink pad  */
32         struct media_link *reverse;     /* Link in the reverse direction */
33         unsigned long flags;            /* Link flags (MEDIA_LNK_FL_*) */
34 };
35
36 struct media_pad {
37         struct media_entity *entity;    /* Entity this pad belongs to */
38         u16 index;                      /* Pad index in the entity pads array */
39         unsigned long flags;            /* Pad flags (MEDIA_PAD_FL_*) */
40 };
41
42 struct media_entity_operations {
43         int (*link_setup)(struct media_entity *entity,
44                           const struct media_pad *local,
45                           const struct media_pad *remote, u32 flags);
46 };
47
48 struct media_entity {
49         struct list_head list;
50         struct media_device *parent;    /* Media device this entity belongs to*/
51         u32 id;                         /* Entity ID, unique in the parent media
52                                          * device context */
53         const char *name;               /* Entity name */
54         u32 type;                       /* Entity type (MEDIA_ENT_T_*) */
55         u32 revision;                   /* Entity revision, driver specific */
56         unsigned long flags;            /* Entity flags (MEDIA_ENT_FL_*) */
57         u32 group_id;                   /* Entity group ID */
58
59         u16 num_pads;                   /* Number of sink and source pads */
60         u16 num_links;                  /* Number of existing links, both
61                                          * enabled and disabled */
62         u16 num_backlinks;              /* Number of backlinks */
63         u16 max_links;                  /* Maximum number of links */
64
65         struct media_pad *pads;         /* Pads array (num_pads elements) */
66         struct media_link *links;       /* Links array (max_links elements)*/
67
68         const struct media_entity_operations *ops;      /* Entity operations */
69
70         /* Reference counts must never be negative, but are signed integers on
71          * purpose: a simple WARN_ON(<0) check can be used to detect reference
72          * count bugs that would make them negative.
73          */
74         int use_count;                  /* Use count for the entity. */
75
76         union {
77                 /* Node specifications */
78                 struct {
79                         u32 major;
80                         u32 minor;
81                 } v4l;
82                 struct {
83                         u32 major;
84                         u32 minor;
85                 } fb;
86                 struct {
87                         u32 card;
88                         u32 device;
89                         u32 subdevice;
90                 } alsa;
91                 int dvb;
92
93                 /* Sub-device specifications */
94                 /* Nothing needed yet */
95         };
96 };
97
98 static inline u32 media_entity_type(struct media_entity *entity)
99 {
100         return entity->type & MEDIA_ENT_TYPE_MASK;
101 }
102
103 static inline u32 media_entity_subtype(struct media_entity *entity)
104 {
105         return entity->type & MEDIA_ENT_SUBTYPE_MASK;
106 }
107
108 #define MEDIA_ENTITY_ENUM_MAX_DEPTH     16
109
110 struct media_entity_graph {
111         struct {
112                 struct media_entity *entity;
113                 int link;
114         } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
115         int top;
116 };
117
118 int media_entity_init(struct media_entity *entity, u16 num_pads,
119                 struct media_pad *pads, u16 extra_links);
120 void media_entity_cleanup(struct media_entity *entity);
121 int media_entity_create_link(struct media_entity *source, u16 source_pad,
122                 struct media_entity *sink, u16 sink_pad, u32 flags);
123 int __media_entity_setup_link(struct media_link *link, u32 flags);
124 int media_entity_setup_link(struct media_link *link, u32 flags);
125 struct media_link *media_entity_find_link(struct media_pad *source,
126                 struct media_pad *sink);
127 struct media_pad *media_entity_remote_source(struct media_pad *pad);
128
129 struct media_entity *media_entity_get(struct media_entity *entity);
130 void media_entity_put(struct media_entity *entity);
131
132 void media_entity_graph_walk_start(struct media_entity_graph *graph,
133                 struct media_entity *entity);
134 struct media_entity *
135 media_entity_graph_walk_next(struct media_entity_graph *graph);
136
137 #define media_entity_call(entity, operation, args...)                   \
138         (((entity)->ops && (entity)->ops->operation) ?                  \
139          (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
140
141 #endif