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