123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
#ifndef _VIMC_COMMON_H_
#define _VIMC_COMMON_H_
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <media/media-device.h>
#include <media/v4l2-device.h>
#include <media/tpg/v4l2-tpg.h>
#include <media/v4l2-ctrls.h>
#define VIMC_PDEV_NAME "vimc"
#define VIMC_CID_VIMC_BASE (0x00f00000 | 0xf000)
#define VIMC_CID_VIMC_CLASS (0x00f00000 | 1)
#define VIMC_CID_TEST_PATTERN (VIMC_CID_VIMC_BASE + 0)
#define VIMC_CID_MEAN_WIN_SIZE (VIMC_CID_VIMC_BASE + 1)
#define VIMC_CID_OSD_TEXT_MODE (VIMC_CID_VIMC_BASE + 2)
#define VIMC_FRAME_MAX_WIDTH 4096
#define VIMC_FRAME_MAX_HEIGHT 2160
#define VIMC_FRAME_MIN_WIDTH 16
#define VIMC_FRAME_MIN_HEIGHT 16
#define VIMC_PIXEL_RATE_FIXED 160000000 /* 160 MHz */
#define VIMC_HBLANK_FIXED 800
#define VIMC_VBLANK_MIN 4
#define VIMC_VBLANK_MAX 65535
#define VIMC_VBLANK_STEP 1
#define VIMC_VBLANK_DEFAULT 3223 /* 30fps vga */
#define VIMC_PIXELS_THRESHOLD_30FPS (1920 * 1080) /* 2073600 pixels */
#define VIMC_FRAME_INDEX(lin, col, width, bpp) ((lin * width + col) * bpp)
#define VIMC_IS_SRC(pad) (pad)
#define VIMC_IS_SINK(pad) (!(pad))
#define VIMC_PIX_FMT_MAX_CODES 8
extern unsigned int vimc_allocator;
enum vimc_allocator_type {
VIMC_ALLOCATOR_VMALLOC = 0,
VIMC_ALLOCATOR_DMA_CONTIG = 1,
};
#define vimc_colorimetry_clamp(fmt) \
do { \
if ((fmt)->colorspace == V4L2_COLORSPACE_DEFAULT \
|| (fmt)->colorspace > V4L2_COLORSPACE_DCI_P3) { \
(fmt)->colorspace = V4L2_COLORSPACE_DEFAULT; \
(fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; \
(fmt)->quantization = V4L2_QUANTIZATION_DEFAULT; \
(fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT; \
} \
if ((fmt)->ycbcr_enc > V4L2_YCBCR_ENC_SMPTE240M) \
(fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; \
if ((fmt)->quantization > V4L2_QUANTIZATION_LIM_RANGE) \
(fmt)->quantization = V4L2_QUANTIZATION_DEFAULT; \
if ((fmt)->xfer_func > V4L2_XFER_FUNC_SMPTE2084) \
(fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT; \
} while (0)
struct vimc_pix_map {
unsigned int code[VIMC_PIX_FMT_MAX_CODES];
unsigned int bpp;
u32 pixelformat;
bool bayer;
};
struct vimc_ent_device {
struct device *dev;
struct media_entity *ent;
void * (*process_frame)(struct vimc_ent_device *ved,
const void *frame);
void (*vdev_get_format)(struct vimc_ent_device *ved,
struct v4l2_pix_format *fmt);
};
struct vimc_device {
const struct vimc_pipeline_config *pipe_cfg;
struct vimc_ent_device **ent_devs;
struct media_device mdev;
struct v4l2_device v4l2_dev;
};
struct vimc_ent_type {
struct vimc_ent_device *(*add)(struct vimc_device *vimc,
const char *vcfg_name);
void (*unregister)(struct vimc_ent_device *ved);
void (*release)(struct vimc_ent_device *ved);
};
struct vimc_ent_config {
const char *name;
const struct vimc_ent_type *type;
};
enum vimc_sensor_osd_mode {
VIMC_SENSOR_OSD_SHOW_ALL = 0,
VIMC_SENSOR_OSD_SHOW_COUNTERS = 1,
VIMC_SENSOR_OSD_SHOW_NONE = 2
};
struct vimc_sensor_device {
struct vimc_ent_device ved;
struct v4l2_subdev sd;
struct tpg_data tpg;
struct v4l2_ctrl_handler hdl;
struct media_pad pad;
struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *hblank;
struct v4l2_ctrl *vblank;
u8 *frame;
struct {
struct v4l2_area size;
enum vimc_sensor_osd_mode osd_value;
u64 start_stream_ts;
unsigned long fps_jiffies;
} hw;
};
bool vimc_is_source(struct media_entity *ent);
extern const struct vimc_ent_type vimc_sensor_type;
extern const struct vimc_ent_type vimc_debayer_type;
extern const struct vimc_ent_type vimc_scaler_type;
extern const struct vimc_ent_type vimc_capture_type;
extern const struct vimc_ent_type vimc_lens_type;
const struct vimc_pix_map *vimc_pix_map_by_index(unsigned int i);
u32 vimc_mbus_code_by_index(unsigned int index);
const struct vimc_pix_map *vimc_pix_map_by_code(u32 code);
const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat);
int vimc_ent_sd_register(struct vimc_ent_device *ved,
struct v4l2_subdev *sd,
struct v4l2_device *v4l2_dev,
const char *const name,
u32 function,
u16 num_pads,
struct media_pad *pads,
const struct v4l2_subdev_internal_ops *int_ops,
const struct v4l2_subdev_ops *sd_ops);
int vimc_vdev_link_validate(struct media_link *link);
#endif