codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Media controller interface library |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Ideas on board SPRL |
| 5 | * |
| 6 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Lesser General Public License as published |
| 10 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 11 | * (at your option) any later version. |
| 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 Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef __MEDIA_H__ |
| 23 | #define __MEDIA_H__ |
| 24 | |
| 25 | #include <media.h> |
| 26 | |
| 27 | #define GAIA_FW_BETA 1 |
| 28 | |
| 29 | #ifndef GAIA_FW_BETA |
| 30 | #define MEDIA_DEV "/dev/media1" //M5MO : External ISP |
| 31 | #else |
| 32 | #define MEDIA_DEV "/dev/media2" //4E5 : Internal ISP |
| 33 | #endif |
| 34 | |
| 35 | #define MEDIA_MINOR 0 |
| 36 | |
| 37 | #define KF_MSG 0x1 |
| 38 | #define KF_ANY 0x2 |
| 39 | |
| 40 | struct media_link { |
| 41 | struct media_pad *source; |
| 42 | struct media_pad *sink; |
| 43 | struct media_link *twin; |
| 44 | __u32 flags; |
| 45 | __u32 padding[3]; |
| 46 | }; |
| 47 | |
| 48 | struct media_pad { |
| 49 | struct media_entity *entity; |
| 50 | __u32 index; |
| 51 | __u32 flags; |
| 52 | __u32 padding[3]; |
| 53 | }; |
| 54 | |
| 55 | struct media_entity { |
| 56 | struct media_device *media; |
| 57 | struct media_entity_desc info; |
| 58 | struct media_pad *pads; |
| 59 | struct media_link *links; |
| 60 | unsigned int max_links; |
| 61 | unsigned int num_links; |
| 62 | |
| 63 | char devname[32]; |
| 64 | int fd; |
| 65 | __u32 padding[6]; |
| 66 | }; |
| 67 | |
| 68 | struct media_device { |
| 69 | int fd; |
| 70 | struct media_entity *entities; |
| 71 | unsigned int entities_count; |
| 72 | void (*debug_handler)(void *, ...); |
| 73 | void *debug_priv; |
| 74 | __u32 padding[6]; |
| 75 | }; |
| 76 | |
| 77 | #define media_dbg(media, ...) \ |
| 78 | (media)->debug_handler((media)->debug_priv, __VA_ARGS__) |
| 79 | |
| 80 | /** |
| 81 | * @brief Set a handler for debug messages. |
| 82 | * @param media - device instance. |
| 83 | * @param debug_handler - debug message handler |
| 84 | * @param debug_priv - first argument to debug message handler |
| 85 | * |
| 86 | * Set a handler for debug messages that will be called whenever |
| 87 | * debugging information is to be printed. The handler expects an |
| 88 | * fprintf-like function. |
| 89 | */ |
| 90 | void media_debug_set_handler( |
| 91 | struct media_device *media, void (*debug_handler)(void *, ...), |
| 92 | void *debug_priv); |
| 93 | |
| 94 | /** |
| 95 | * @brief Open a media device with debugging enabled. |
| 96 | * @param name - name (including path) of the device node. |
| 97 | * @param debug_handler - debug message handler |
| 98 | * @param debug_priv - first argument to debug message handler |
| 99 | * |
| 100 | * Open the media device referenced by @a name and enumerate entities, pads and |
| 101 | * links. |
| 102 | * |
| 103 | * Calling media_open_debug() instead of media_open() is equivalent to |
| 104 | * media_open() and media_debug_set_handler() except that debugging is |
| 105 | * also enabled during media_open(). |
| 106 | * |
| 107 | * @return A pointer to a newly allocated media_device structure instance on |
| 108 | * success and NULL on failure. The returned pointer must be freed with |
| 109 | * media_close when the device isn't needed anymore. |
| 110 | */ |
| 111 | struct media_device *media_open_debug( |
| 112 | const char *name, void (*debug_handler)(void *, ...), |
| 113 | void *debug_priv); |
| 114 | |
| 115 | /** |
| 116 | * @brief Open a media device. |
| 117 | * @param name - name (including path) of the device node. |
| 118 | * |
| 119 | * Open the media device referenced by @a name and enumerate entities, pads and |
| 120 | * links. |
| 121 | * |
| 122 | * @return A pointer to a newly allocated media_device structure instance on |
| 123 | * success and NULL on failure. The returned pointer must be freed with |
| 124 | * media_close when the device isn't needed anymore. |
| 125 | */ |
| 126 | struct media_device *media_open(void); |
| 127 | |
| 128 | /** |
| 129 | * @brief Close a media device. |
| 130 | * @param media - device instance. |
| 131 | * |
| 132 | * Close the @a media device instance and free allocated resources. Access to the |
| 133 | * device instance is forbidden after this function returns. |
| 134 | */ |
| 135 | void media_close(struct media_device *media); |
| 136 | |
| 137 | /** |
| 138 | * @brief Locate the pad at the other end of a link. |
| 139 | * @param pad - sink pad at one end of the link. |
| 140 | * |
| 141 | * Locate the source pad connected to @a pad through an enabled link. As only one |
| 142 | * link connected to a sink pad can be enabled at a time, the connected source |
| 143 | * pad is guaranteed to be unique. |
| 144 | * |
| 145 | * @return A pointer to the connected source pad, or NULL if all links connected |
| 146 | * to @a pad are disabled. Return NULL also if @a pad is not a sink pad. |
| 147 | */ |
| 148 | struct media_pad *media_entity_remote_source(struct media_pad *pad); |
| 149 | |
| 150 | /** |
| 151 | * @brief Get the type of an entity. |
| 152 | * @param entity - the entity. |
| 153 | * |
| 154 | * @return The type of @a entity. |
| 155 | */ |
| 156 | static inline unsigned int media_entity_type(struct media_entity *entity) |
| 157 | { |
| 158 | return entity->info.type & MEDIA_ENT_TYPE_MASK; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @brief Find an entity by its name. |
| 163 | * @param media - media device. |
| 164 | * @param name - entity name. |
| 165 | * @param length - size of @a name. |
| 166 | * |
| 167 | * Search for an entity with a name equal to @a name. |
| 168 | * |
| 169 | * @return A pointer to the entity if found, or NULL otherwise. |
| 170 | */ |
| 171 | struct media_entity *media_get_entity_by_name(struct media_device *media, |
| 172 | const char *name, size_t length); |
| 173 | |
| 174 | /** |
| 175 | * @brief Find an entity by its ID. |
| 176 | * @param media - media device. |
| 177 | * @param id - entity ID. |
| 178 | * |
| 179 | * Search for an entity with an ID equal to @a id. |
| 180 | * |
| 181 | * @return A pointer to the entity if found, or NULL otherwise. |
| 182 | */ |
| 183 | struct media_entity *media_get_entity_by_id(struct media_device *media, |
| 184 | __u32 id); |
| 185 | |
| 186 | /** |
| 187 | * @brief Configure a link. |
| 188 | * @param media - media device. |
| 189 | * @param source - source pad at the link origin. |
| 190 | * @param sink - sink pad at the link target. |
| 191 | * @param flags - configuration flags. |
| 192 | * |
| 193 | * Locate the link between @a source and @a sink, and configure it by applying |
| 194 | * the new @a flags. |
| 195 | * |
| 196 | * Only the MEDIA_LINK_FLAG_ENABLED flag is writable. |
| 197 | * |
| 198 | * @return 0 on success, -1 on failure: |
| 199 | * -ENOENT: link not found |
| 200 | * - other error codes returned by MEDIA_IOC_SETUP_LINK |
| 201 | */ |
| 202 | int media_setup_link(struct media_device *media, |
| 203 | struct media_pad *source, struct media_pad *sink, |
| 204 | __u32 flags); |
| 205 | |
| 206 | /** |
| 207 | * @brief Reset all links to the disabled state. |
| 208 | * @param media - media device. |
| 209 | * |
| 210 | * Disable all links in the media device. This function is usually used after |
| 211 | * opening a media device to reset all links to a known state. |
| 212 | * |
| 213 | * @return 0 on success, or a negative error code on failure. |
| 214 | */ |
| 215 | int media_reset_links(struct media_device *media); |
| 216 | |
| 217 | /** |
| 218 | * @brief Parse string to a pad on the media device. |
| 219 | * @param media - media device. |
| 220 | * @param p - input string |
| 221 | * @param endp - pointer to string where parsing ended |
| 222 | * |
| 223 | * Parse NULL terminated string describing a pad and return its struct |
| 224 | * media_pad instance. |
| 225 | * |
| 226 | * @return Pointer to struct media_pad on success, NULL on failure. |
| 227 | */ |
| 228 | struct media_pad *media_parse_pad(struct media_device *media, |
| 229 | const char *p, char **endp); |
| 230 | |
| 231 | /** |
| 232 | * @brief Parse string to a link on the media device. |
| 233 | * @param media - media device. |
| 234 | * @param p - input string |
| 235 | * @param endp - pointer to p where parsing ended |
| 236 | * |
| 237 | * Parse NULL terminated string p describing a link and return its struct |
| 238 | * media_link instance. |
| 239 | * |
| 240 | * @return Pointer to struct media_link on success, NULL on failure. |
| 241 | */ |
| 242 | struct media_link *media_parse_link(struct media_device *media, |
| 243 | const char *p, char **endp); |
| 244 | |
| 245 | /** |
| 246 | * @brief Parse string to a link on the media device and set it up. |
| 247 | * @param media - media device. |
| 248 | * @param p - input string |
| 249 | * |
| 250 | * Parse NULL terminated string p describing a link and its configuration |
| 251 | * and configure the link. |
| 252 | * |
| 253 | * @return 0 on success, or a negative error code on failure. |
| 254 | */ |
| 255 | int media_parse_setup_link(struct media_device *media, |
| 256 | const char *p, char **endp); |
| 257 | |
| 258 | /** |
| 259 | * @brief Parse string to link(s) on the media device and set it up. |
| 260 | * @param media - media device. |
| 261 | * @param p - input string |
| 262 | * |
| 263 | * Parse NULL terminated string p describing link(s) separated by |
| 264 | * commas (,) and configure the link(s). |
| 265 | * |
| 266 | * @return 0 on success, or a negative error code on failure. |
| 267 | */ |
| 268 | int media_parse_setup_links(struct media_device *media, const char *p); |
| 269 | |
| 270 | #endif |