Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 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 | |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 26 | #include <linux/bitops.h> |
Sakari Ailus | 0149a2e | 2013-12-13 08:58:37 -0300 | [diff] [blame] | 27 | #include <linux/kernel.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 28 | #include <linux/list.h> |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 29 | #include <linux/media.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 30 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 31 | struct media_pipeline { |
| 32 | }; |
| 33 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 34 | struct media_link { |
| 35 | struct media_pad *source; /* Source pad */ |
| 36 | struct media_pad *sink; /* Sink pad */ |
| 37 | struct media_link *reverse; /* Link in the reverse direction */ |
| 38 | unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */ |
| 39 | }; |
| 40 | |
| 41 | struct media_pad { |
| 42 | struct media_entity *entity; /* Entity this pad belongs to */ |
| 43 | u16 index; /* Pad index in the entity pads array */ |
| 44 | unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */ |
| 45 | }; |
| 46 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 47 | struct media_entity_operations { |
| 48 | int (*link_setup)(struct media_entity *entity, |
| 49 | const struct media_pad *local, |
| 50 | const struct media_pad *remote, u32 flags); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 51 | int (*link_validate)(struct media_link *link); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 52 | }; |
| 53 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 54 | struct media_entity { |
| 55 | struct list_head list; |
| 56 | struct media_device *parent; /* Media device this entity belongs to*/ |
| 57 | u32 id; /* Entity ID, unique in the parent media |
| 58 | * device context */ |
| 59 | const char *name; /* Entity name */ |
| 60 | u32 type; /* Entity type (MEDIA_ENT_T_*) */ |
| 61 | u32 revision; /* Entity revision, driver specific */ |
| 62 | unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */ |
| 63 | u32 group_id; /* Entity group ID */ |
| 64 | |
| 65 | u16 num_pads; /* Number of sink and source pads */ |
| 66 | u16 num_links; /* Number of existing links, both |
| 67 | * enabled and disabled */ |
| 68 | u16 num_backlinks; /* Number of backlinks */ |
| 69 | u16 max_links; /* Maximum number of links */ |
| 70 | |
| 71 | struct media_pad *pads; /* Pads array (num_pads elements) */ |
| 72 | struct media_link *links; /* Links array (max_links elements)*/ |
| 73 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 74 | const struct media_entity_operations *ops; /* Entity operations */ |
| 75 | |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 76 | /* Reference counts must never be negative, but are signed integers on |
| 77 | * purpose: a simple WARN_ON(<0) check can be used to detect reference |
| 78 | * count bugs that would make them negative. |
| 79 | */ |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 80 | int stream_count; /* Stream count for the entity. */ |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 81 | int use_count; /* Use count for the entity. */ |
| 82 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 83 | struct media_pipeline *pipe; /* Pipeline this entity belongs to. */ |
| 84 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 85 | union { |
| 86 | /* Node specifications */ |
| 87 | struct { |
| 88 | u32 major; |
| 89 | u32 minor; |
| 90 | } v4l; |
| 91 | struct { |
| 92 | u32 major; |
| 93 | u32 minor; |
| 94 | } fb; |
| 95 | struct { |
| 96 | u32 card; |
| 97 | u32 device; |
| 98 | u32 subdevice; |
| 99 | } alsa; |
| 100 | int dvb; |
| 101 | |
| 102 | /* Sub-device specifications */ |
| 103 | /* Nothing needed yet */ |
Clemens Ladisch | fa5034c | 2011-11-05 18:42:01 -0300 | [diff] [blame] | 104 | } info; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static inline u32 media_entity_type(struct media_entity *entity) |
| 108 | { |
| 109 | return entity->type & MEDIA_ENT_TYPE_MASK; |
| 110 | } |
| 111 | |
| 112 | static inline u32 media_entity_subtype(struct media_entity *entity) |
| 113 | { |
| 114 | return entity->type & MEDIA_ENT_SUBTYPE_MASK; |
| 115 | } |
| 116 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 117 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 118 | #define MEDIA_ENTITY_ENUM_MAX_ID 64 |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 119 | |
| 120 | struct media_entity_graph { |
| 121 | struct { |
| 122 | struct media_entity *entity; |
| 123 | int link; |
| 124 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 125 | |
| 126 | DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID); |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 127 | int top; |
| 128 | }; |
| 129 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 130 | int media_entity_init(struct media_entity *entity, u16 num_pads, |
| 131 | struct media_pad *pads, u16 extra_links); |
| 132 | void media_entity_cleanup(struct media_entity *entity); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 133 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 134 | int media_entity_create_link(struct media_entity *source, u16 source_pad, |
| 135 | struct media_entity *sink, u16 sink_pad, u32 flags); |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 136 | void __media_entity_remove_links(struct media_entity *entity); |
| 137 | void media_entity_remove_links(struct media_entity *entity); |
| 138 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 139 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
| 140 | int media_entity_setup_link(struct media_link *link, u32 flags); |
| 141 | struct media_link *media_entity_find_link(struct media_pad *source, |
| 142 | struct media_pad *sink); |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 143 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 144 | |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 145 | struct media_entity *media_entity_get(struct media_entity *entity); |
| 146 | void media_entity_put(struct media_entity *entity); |
| 147 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 148 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
| 149 | struct media_entity *entity); |
| 150 | struct media_entity * |
| 151 | media_entity_graph_walk_next(struct media_entity_graph *graph); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 152 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
| 153 | struct media_pipeline *pipe); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 154 | void media_entity_pipeline_stop(struct media_entity *entity); |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 155 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 156 | #define media_entity_call(entity, operation, args...) \ |
| 157 | (((entity)->ops && (entity)->ops->operation) ? \ |
| 158 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) |
| 159 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 160 | #endif |