Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v5.2-rc3 199 lines 6.4 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * vimc-common.h Virtual Media Controller Driver 4 * 5 * Copyright (C) 2015-2017 Helen Koike <helen.fornazier@gmail.com> 6 */ 7 8#ifndef _VIMC_COMMON_H_ 9#define _VIMC_COMMON_H_ 10 11#include <linux/slab.h> 12#include <media/media-device.h> 13#include <media/v4l2-device.h> 14 15#include "vimc-streamer.h" 16 17#define VIMC_PDEV_NAME "vimc" 18 19/* VIMC-specific controls */ 20#define VIMC_CID_VIMC_BASE (0x00f00000 | 0xf000) 21#define VIMC_CID_VIMC_CLASS (0x00f00000 | 1) 22#define VIMC_CID_TEST_PATTERN (VIMC_CID_VIMC_BASE + 0) 23 24#define VIMC_FRAME_MAX_WIDTH 4096 25#define VIMC_FRAME_MAX_HEIGHT 2160 26#define VIMC_FRAME_MIN_WIDTH 16 27#define VIMC_FRAME_MIN_HEIGHT 16 28 29#define VIMC_FRAME_INDEX(lin, col, width, bpp) ((lin * width + col) * bpp) 30 31/** 32 * struct vimc_colorimetry_clamp - Adjust colorimetry parameters 33 * 34 * @fmt: the pointer to struct v4l2_pix_format or 35 * struct v4l2_mbus_framefmt 36 * 37 * Entities must check if colorimetry given by the userspace is valid, if not 38 * then set them as DEFAULT 39 */ 40#define vimc_colorimetry_clamp(fmt) \ 41do { \ 42 if ((fmt)->colorspace == V4L2_COLORSPACE_DEFAULT \ 43 || (fmt)->colorspace > V4L2_COLORSPACE_DCI_P3) { \ 44 (fmt)->colorspace = V4L2_COLORSPACE_DEFAULT; \ 45 (fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; \ 46 (fmt)->quantization = V4L2_QUANTIZATION_DEFAULT; \ 47 (fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT; \ 48 } \ 49 if ((fmt)->ycbcr_enc > V4L2_YCBCR_ENC_SMPTE240M) \ 50 (fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; \ 51 if ((fmt)->quantization > V4L2_QUANTIZATION_LIM_RANGE) \ 52 (fmt)->quantization = V4L2_QUANTIZATION_DEFAULT; \ 53 if ((fmt)->xfer_func > V4L2_XFER_FUNC_SMPTE2084) \ 54 (fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT; \ 55} while (0) 56 57/** 58 * struct vimc_platform_data - platform data to components 59 * 60 * @entity_name: The name of the entity to be created 61 * 62 * Board setup code will often provide additional information using the device's 63 * platform_data field to hold additional information. 64 * When injecting a new platform_device in the component system the core needs 65 * to provide to the corresponding submodules the name of the entity that should 66 * be used when registering the subdevice in the Media Controller system. 67 */ 68struct vimc_platform_data { 69 char entity_name[32]; 70}; 71 72/** 73 * struct vimc_ent_device - core struct that represents a node in the topology 74 * 75 * @ent: the pointer to struct media_entity for the node 76 * @pads: the list of pads of the node 77 * @process_frame: callback send a frame to that node 78 * @vdev_get_format: callback that returns the current format a pad, used 79 * only when is_media_entity_v4l2_video_device(ent) returns 80 * true 81 * 82 * Each node of the topology must create a vimc_ent_device struct. Depending on 83 * the node it will be of an instance of v4l2_subdev or video_device struct 84 * where both contains a struct media_entity. 85 * Those structures should embedded the vimc_ent_device struct through 86 * v4l2_set_subdevdata() and video_set_drvdata() respectivaly, allowing the 87 * vimc_ent_device struct to be retrieved from the corresponding struct 88 * media_entity 89 */ 90struct vimc_ent_device { 91 struct media_entity *ent; 92 struct media_pad *pads; 93 struct vimc_stream *stream; 94 void * (*process_frame)(struct vimc_ent_device *ved, 95 const void *frame); 96 void (*vdev_get_format)(struct vimc_ent_device *ved, 97 struct v4l2_pix_format *fmt); 98}; 99 100/** 101 * vimc_mbus_code_supported - helper to check supported mbus codes 102 * 103 * Helper function to check if mbus code is enumerated by vimc_enum_mbus_code() 104 */ 105bool vimc_mbus_code_supported(__u32 code); 106 107/** 108 * vimc_enum_mbus_code - enumerate mbus codes 109 * 110 * Helper function to be pluged in .enum_mbus_code from 111 * struct v4l2_subdev_pad_ops. 112 */ 113int vimc_enum_mbus_code(struct v4l2_subdev *sd, 114 struct v4l2_subdev_pad_config *cfg, 115 struct v4l2_subdev_mbus_code_enum *code); 116 117/** 118 * vimc_pads_init - initialize pads 119 * 120 * @num_pads: number of pads to initialize 121 * @pads_flags: flags to use in each pad 122 * 123 * Helper functions to allocate/initialize pads 124 */ 125struct media_pad *vimc_pads_init(u16 num_pads, 126 const unsigned long *pads_flag); 127 128/** 129 * vimc_pads_cleanup - free pads 130 * 131 * @pads: pointer to the pads 132 * 133 * Helper function to free the pads initialized with vimc_pads_init 134 */ 135static inline void vimc_pads_cleanup(struct media_pad *pads) 136{ 137 kfree(pads); 138} 139 140/** 141 * vimc_pipeline_s_stream - start stream through the pipeline 142 * 143 * @ent: the pointer to struct media_entity for the node 144 * @enable: 1 to start the stream and 0 to stop 145 * 146 * Helper function to call the s_stream of the subdevices connected 147 * in all the sink pads of the entity 148 */ 149int vimc_pipeline_s_stream(struct media_entity *ent, int enable); 150 151/** 152 * vimc_ent_sd_register - initialize and register a subdev node 153 * 154 * @ved: the vimc_ent_device struct to be initialize 155 * @sd: the v4l2_subdev struct to be initialize and registered 156 * @v4l2_dev: the v4l2 device to register the v4l2_subdev 157 * @name: name of the sub-device. Please notice that the name must be 158 * unique. 159 * @function: media entity function defined by MEDIA_ENT_F_* macros 160 * @num_pads: number of pads to initialize 161 * @pads_flag: flags to use in each pad 162 * @sd_int_ops: pointer to &struct v4l2_subdev_internal_ops 163 * @sd_ops: pointer to &struct v4l2_subdev_ops. 164 * 165 * Helper function initialize and register the struct vimc_ent_device and struct 166 * v4l2_subdev which represents a subdev node in the topology 167 */ 168int vimc_ent_sd_register(struct vimc_ent_device *ved, 169 struct v4l2_subdev *sd, 170 struct v4l2_device *v4l2_dev, 171 const char *const name, 172 u32 function, 173 u16 num_pads, 174 const unsigned long *pads_flag, 175 const struct v4l2_subdev_internal_ops *sd_int_ops, 176 const struct v4l2_subdev_ops *sd_ops); 177 178/** 179 * vimc_ent_sd_unregister - cleanup and unregister a subdev node 180 * 181 * @ved: the vimc_ent_device struct to be cleaned up 182 * @sd: the v4l2_subdev struct to be unregistered 183 * 184 * Helper function cleanup and unregister the struct vimc_ent_device and struct 185 * v4l2_subdev which represents a subdev node in the topology 186 */ 187void vimc_ent_sd_unregister(struct vimc_ent_device *ved, 188 struct v4l2_subdev *sd); 189 190/** 191 * vimc_link_validate - validates a media link 192 * 193 * @link: pointer to &struct media_link 194 * 195 * This function calls validates if a media link is valid for streaming. 196 */ 197int vimc_link_validate(struct media_link *link); 198 199#endif