Helen Koike | f2fe890 | 2017-04-07 14:55:19 -0300 | [diff] [blame] | 1 | /* |
Helen Fornazier | 5ba0ae4 | 2017-06-19 14:00:11 -0300 | [diff] [blame] | 2 | * vimc-ccommon.h Virtual Media Controller Driver |
Helen Koike | f2fe890 | 2017-04-07 14:55:19 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2015-2017 Helen Koike <helen.fornazier@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
Helen Fornazier | 5ba0ae4 | 2017-06-19 14:00:11 -0300 | [diff] [blame] | 18 | #ifndef _VIMC_COMMON_H_ |
| 19 | #define _VIMC_COMMON_H_ |
Helen Koike | f2fe890 | 2017-04-07 14:55:19 -0300 | [diff] [blame] | 20 | |
| 21 | #include <linux/slab.h> |
Helen Fornazier | 5ba0ae4 | 2017-06-19 14:00:11 -0300 | [diff] [blame] | 22 | #include <media/media-device.h> |
Helen Koike | f2fe890 | 2017-04-07 14:55:19 -0300 | [diff] [blame] | 23 | #include <media/v4l2-device.h> |
| 24 | |
| 25 | /** |
| 26 | * struct vimc_pix_map - maps media bus code with v4l2 pixel format |
| 27 | * |
| 28 | * @code: media bus format code defined by MEDIA_BUS_FMT_* macros |
| 29 | * @bbp: number of bytes each pixel occupies |
| 30 | * @pixelformat: pixel format devined by V4L2_PIX_FMT_* macros |
| 31 | * |
| 32 | * Struct which matches the MEDIA_BUS_FMT_* codes with the corresponding |
| 33 | * V4L2_PIX_FMT_* fourcc pixelformat and its bytes per pixel (bpp) |
| 34 | */ |
| 35 | struct vimc_pix_map { |
| 36 | unsigned int code; |
| 37 | unsigned int bpp; |
| 38 | u32 pixelformat; |
| 39 | }; |
| 40 | |
| 41 | /** |
| 42 | * struct vimc_ent_device - core struct that represents a node in the topology |
| 43 | * |
| 44 | * @ent: the pointer to struct media_entity for the node |
| 45 | * @pads: the list of pads of the node |
| 46 | * @destroy: callback to destroy the node |
| 47 | * @process_frame: callback send a frame to that node |
| 48 | * |
| 49 | * Each node of the topology must create a vimc_ent_device struct. Depending on |
| 50 | * the node it will be of an instance of v4l2_subdev or video_device struct |
| 51 | * where both contains a struct media_entity. |
| 52 | * Those structures should embedded the vimc_ent_device struct through |
| 53 | * v4l2_set_subdevdata() and video_set_drvdata() respectivaly, allowing the |
| 54 | * vimc_ent_device struct to be retrieved from the corresponding struct |
| 55 | * media_entity |
| 56 | */ |
| 57 | struct vimc_ent_device { |
| 58 | struct media_entity *ent; |
| 59 | struct media_pad *pads; |
| 60 | void (*destroy)(struct vimc_ent_device *); |
| 61 | void (*process_frame)(struct vimc_ent_device *ved, |
| 62 | struct media_pad *sink, const void *frame); |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * vimc_propagate_frame - propagate a frame through the topology |
| 67 | * |
| 68 | * @src: the source pad where the frame is being originated |
| 69 | * @frame: the frame to be propagated |
| 70 | * |
| 71 | * This function will call the process_frame callback from the vimc_ent_device |
| 72 | * struct of the nodes directly connected to the @src pad |
| 73 | */ |
| 74 | int vimc_propagate_frame(struct media_pad *src, const void *frame); |
| 75 | |
| 76 | /** |
| 77 | * vimc_pads_init - initialize pads |
| 78 | * |
| 79 | * @num_pads: number of pads to initialize |
| 80 | * @pads_flags: flags to use in each pad |
| 81 | * |
| 82 | * Helper functions to allocate/initialize pads |
| 83 | */ |
| 84 | struct media_pad *vimc_pads_init(u16 num_pads, |
| 85 | const unsigned long *pads_flag); |
| 86 | |
| 87 | /** |
| 88 | * vimc_pads_cleanup - free pads |
| 89 | * |
| 90 | * @pads: pointer to the pads |
| 91 | * |
| 92 | * Helper function to free the pads initialized with vimc_pads_init |
| 93 | */ |
| 94 | static inline void vimc_pads_cleanup(struct media_pad *pads) |
| 95 | { |
| 96 | kfree(pads); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * vimc_pix_map_by_code - get vimc_pix_map struct by media bus code |
| 101 | * |
| 102 | * @code: media bus format code defined by MEDIA_BUS_FMT_* macros |
| 103 | */ |
| 104 | const struct vimc_pix_map *vimc_pix_map_by_code(u32 code); |
| 105 | |
| 106 | /** |
| 107 | * vimc_pix_map_by_pixelformat - get vimc_pix_map struct by v4l2 pixel format |
| 108 | * |
| 109 | * @pixelformat: pixel format devined by V4L2_PIX_FMT_* macros |
| 110 | */ |
| 111 | const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat); |
| 112 | |
Helen Fornazier | c149543 | 2017-06-19 14:00:12 -0300 | [diff] [blame^] | 113 | /** |
| 114 | * vimc_ent_sd_register - initialize and register a subdev node |
| 115 | * |
| 116 | * @ved: the vimc_ent_device struct to be initialize |
| 117 | * @sd: the v4l2_subdev struct to be initialize and registered |
| 118 | * @v4l2_dev: the v4l2 device to register the v4l2_subdev |
| 119 | * @name: name of the sub-device. Please notice that the name must be |
| 120 | * unique. |
| 121 | * @function: media entity function defined by MEDIA_ENT_F_* macros |
| 122 | * @num_pads: number of pads to initialize |
| 123 | * @pads_flag: flags to use in each pad |
| 124 | * @sd_ops: pointer to &struct v4l2_subdev_ops. |
| 125 | * @sd_destroy: callback to destroy the node |
| 126 | * |
| 127 | * Helper function initialize and register the struct vimc_ent_device and struct |
| 128 | * v4l2_subdev which represents a subdev node in the topology |
| 129 | */ |
| 130 | int vimc_ent_sd_register(struct vimc_ent_device *ved, |
| 131 | struct v4l2_subdev *sd, |
| 132 | struct v4l2_device *v4l2_dev, |
| 133 | const char *const name, |
| 134 | u32 function, |
| 135 | u16 num_pads, |
| 136 | const unsigned long *pads_flag, |
| 137 | const struct v4l2_subdev_ops *sd_ops, |
| 138 | void (*sd_destroy)(struct vimc_ent_device *)); |
| 139 | |
| 140 | /** |
| 141 | * vimc_ent_sd_register - initialize and register a subdev node |
| 142 | * |
| 143 | * @ved: the vimc_ent_device struct to be initialize |
| 144 | * @sd: the v4l2_subdev struct to be initialize and registered |
| 145 | * |
| 146 | * Helper function cleanup and unregister the struct vimc_ent_device and struct |
| 147 | * v4l2_subdev which represents a subdev node in the topology |
| 148 | */ |
| 149 | void vimc_ent_sd_unregister(struct vimc_ent_device *ved, |
| 150 | struct v4l2_subdev *sd); |
| 151 | |
Helen Koike | f2fe890 | 2017-04-07 14:55:19 -0300 | [diff] [blame] | 152 | #endif |