0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _VIMC_COMMON_H_
0009 #define _VIMC_COMMON_H_
0010
0011 #include <linux/platform_device.h>
0012 #include <linux/slab.h>
0013 #include <media/media-device.h>
0014 #include <media/v4l2-device.h>
0015
0016 #define VIMC_PDEV_NAME "vimc"
0017
0018
0019 #define VIMC_CID_VIMC_BASE (0x00f00000 | 0xf000)
0020 #define VIMC_CID_VIMC_CLASS (0x00f00000 | 1)
0021 #define VIMC_CID_TEST_PATTERN (VIMC_CID_VIMC_BASE + 0)
0022 #define VIMC_CID_MEAN_WIN_SIZE (VIMC_CID_VIMC_BASE + 1)
0023 #define VIMC_CID_OSD_TEXT_MODE (VIMC_CID_VIMC_BASE + 2)
0024
0025 #define VIMC_FRAME_MAX_WIDTH 4096
0026 #define VIMC_FRAME_MAX_HEIGHT 2160
0027 #define VIMC_FRAME_MIN_WIDTH 16
0028 #define VIMC_FRAME_MIN_HEIGHT 16
0029
0030 #define VIMC_FRAME_INDEX(lin, col, width, bpp) ((lin * width + col) * bpp)
0031
0032
0033 #define VIMC_IS_SRC(pad) (pad)
0034 #define VIMC_IS_SINK(pad) (!(pad))
0035
0036 #define VIMC_PIX_FMT_MAX_CODES 8
0037
0038 extern unsigned int vimc_allocator;
0039
0040 enum vimc_allocator_type {
0041 VIMC_ALLOCATOR_VMALLOC = 0,
0042 VIMC_ALLOCATOR_DMA_CONTIG = 1,
0043 };
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 #define vimc_colorimetry_clamp(fmt) \
0055 do { \
0056 if ((fmt)->colorspace == V4L2_COLORSPACE_DEFAULT \
0057 || (fmt)->colorspace > V4L2_COLORSPACE_DCI_P3) { \
0058 (fmt)->colorspace = V4L2_COLORSPACE_DEFAULT; \
0059 (fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; \
0060 (fmt)->quantization = V4L2_QUANTIZATION_DEFAULT; \
0061 (fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT; \
0062 } \
0063 if ((fmt)->ycbcr_enc > V4L2_YCBCR_ENC_SMPTE240M) \
0064 (fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; \
0065 if ((fmt)->quantization > V4L2_QUANTIZATION_LIM_RANGE) \
0066 (fmt)->quantization = V4L2_QUANTIZATION_DEFAULT; \
0067 if ((fmt)->xfer_func > V4L2_XFER_FUNC_SMPTE2084) \
0068 (fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT; \
0069 } while (0)
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 struct vimc_pix_map {
0083 unsigned int code[VIMC_PIX_FMT_MAX_CODES];
0084 unsigned int bpp;
0085 u32 pixelformat;
0086 bool bayer;
0087 };
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 struct vimc_ent_device {
0109 struct device *dev;
0110 struct media_entity *ent;
0111 void * (*process_frame)(struct vimc_ent_device *ved,
0112 const void *frame);
0113 void (*vdev_get_format)(struct vimc_ent_device *ved,
0114 struct v4l2_pix_format *fmt);
0115 };
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 struct vimc_device {
0126 const struct vimc_pipeline_config *pipe_cfg;
0127 struct vimc_ent_device **ent_devs;
0128 struct media_device mdev;
0129 struct v4l2_device v4l2_dev;
0130 };
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 struct vimc_ent_type {
0143 struct vimc_ent_device *(*add)(struct vimc_device *vimc,
0144 const char *vcfg_name);
0145 void (*unregister)(struct vimc_ent_device *ved);
0146 void (*release)(struct vimc_ent_device *ved);
0147 };
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 struct vimc_ent_config {
0158 const char *name;
0159 struct vimc_ent_type *type;
0160 };
0161
0162
0163
0164
0165
0166
0167
0168 bool vimc_is_source(struct media_entity *ent);
0169
0170 extern struct vimc_ent_type vimc_sensor_type;
0171 extern struct vimc_ent_type vimc_debayer_type;
0172 extern struct vimc_ent_type vimc_scaler_type;
0173 extern struct vimc_ent_type vimc_capture_type;
0174 extern struct vimc_ent_type vimc_lens_type;
0175
0176
0177
0178
0179
0180
0181 const struct vimc_pix_map *vimc_pix_map_by_index(unsigned int i);
0182
0183
0184
0185
0186
0187
0188
0189
0190 u32 vimc_mbus_code_by_index(unsigned int index);
0191
0192
0193
0194
0195
0196
0197 const struct vimc_pix_map *vimc_pix_map_by_code(u32 code);
0198
0199
0200
0201
0202
0203
0204 const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat);
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 int vimc_ent_sd_register(struct vimc_ent_device *ved,
0224 struct v4l2_subdev *sd,
0225 struct v4l2_device *v4l2_dev,
0226 const char *const name,
0227 u32 function,
0228 u16 num_pads,
0229 struct media_pad *pads,
0230 const struct v4l2_subdev_ops *sd_ops);
0231
0232
0233
0234
0235
0236
0237
0238
0239 int vimc_vdev_link_validate(struct media_link *link);
0240
0241 #endif