blob: 51bdafce72c775998060f983411d7f92a100e34c [file] [log] [blame]
Laurent Pinchart53e269c2009-12-09 08:40:00 -03001/*
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>
Laurent Pinchart16513332009-12-09 08:40:01 -030027#include <linux/media.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030028
29struct 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
36struct 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
42struct media_entity {
43 struct list_head list;
44 struct media_device *parent; /* Media device this entity belongs to*/
45 u32 id; /* Entity ID, unique in the parent media
46 * device context */
47 const char *name; /* Entity name */
48 u32 type; /* Entity type (MEDIA_ENT_T_*) */
49 u32 revision; /* Entity revision, driver specific */
50 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
51 u32 group_id; /* Entity group ID */
52
53 u16 num_pads; /* Number of sink and source pads */
54 u16 num_links; /* Number of existing links, both
55 * enabled and disabled */
56 u16 num_backlinks; /* Number of backlinks */
57 u16 max_links; /* Maximum number of links */
58
59 struct media_pad *pads; /* Pads array (num_pads elements) */
60 struct media_link *links; /* Links array (max_links elements)*/
61
Laurent Pinchart503c3d822010-03-07 15:04:59 -030062 /* Reference counts must never be negative, but are signed integers on
63 * purpose: a simple WARN_ON(<0) check can be used to detect reference
64 * count bugs that would make them negative.
65 */
66 int use_count; /* Use count for the entity. */
67
Laurent Pinchart53e269c2009-12-09 08:40:00 -030068 union {
69 /* Node specifications */
70 struct {
71 u32 major;
72 u32 minor;
73 } v4l;
74 struct {
75 u32 major;
76 u32 minor;
77 } fb;
78 struct {
79 u32 card;
80 u32 device;
81 u32 subdevice;
82 } alsa;
83 int dvb;
84
85 /* Sub-device specifications */
86 /* Nothing needed yet */
87 };
88};
89
90static inline u32 media_entity_type(struct media_entity *entity)
91{
92 return entity->type & MEDIA_ENT_TYPE_MASK;
93}
94
95static inline u32 media_entity_subtype(struct media_entity *entity)
96{
97 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
98}
99
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300100#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
101
102struct media_entity_graph {
103 struct {
104 struct media_entity *entity;
105 int link;
106 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
107 int top;
108};
109
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300110int media_entity_init(struct media_entity *entity, u16 num_pads,
111 struct media_pad *pads, u16 extra_links);
112void media_entity_cleanup(struct media_entity *entity);
113int media_entity_create_link(struct media_entity *source, u16 source_pad,
114 struct media_entity *sink, u16 sink_pad, u32 flags);
115
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300116struct media_entity *media_entity_get(struct media_entity *entity);
117void media_entity_put(struct media_entity *entity);
118
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300119void media_entity_graph_walk_start(struct media_entity_graph *graph,
120 struct media_entity *entity);
121struct media_entity *
122media_entity_graph_walk_next(struct media_entity_graph *graph);
123
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300124#endif