| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* stf_video.h |
| 4 |
* |
| 5 |
* StarFive Camera Subsystem - V4L2 device node |
| 6 |
* |
| 7 |
* Copyright (C) 2021-2023 StarFive Technology Co., Ltd. |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef STF_VIDEO_H |
| 11 |
#define STF_VIDEO_H |
| 12 |
|
| 13 |
#include <linux/list.h> |
| 14 |
#include <linux/mutex.h> |
| 15 |
#include <linux/videodev2.h> |
| 16 |
#include <media/v4l2-dev.h> |
| 17 |
#include <media/v4l2-fh.h> |
| 18 |
#include <media/v4l2-ioctl.h> |
| 19 |
#include <media/videobuf2-v4l2.h> |
| 20 |
|
| 21 |
#define STFCAMSS_FRAME_MIN_WIDTH 64 |
| 22 |
#define STFCAMSS_FRAME_MAX_WIDTH 1920 |
| 23 |
#define STFCAMSS_FRAME_MIN_HEIGHT 64 |
| 24 |
#define STFCAMSS_FRAME_MAX_HEIGHT 1080 |
| 25 |
#define STFCAMSS_FRAME_WIDTH_ALIGN_8 8 |
| 26 |
#define STFCAMSS_FRAME_WIDTH_ALIGN_128 128 |
| 27 |
#define STFCAMSS_MIN_BUFFERS 2 |
| 28 |
|
| 29 |
#define STFCAMSS_MAX_ENTITY_NAME_LEN 27 |
| 30 |
|
| 31 |
enum stf_v_line_id { |
| 32 |
STF_V_LINE_WR = 0, |
| 33 |
STF_V_LINE_ISP, |
| 34 |
STF_V_LINE_MAX, |
| 35 |
}; |
| 36 |
|
| 37 |
enum stf_capture_type { |
| 38 |
STF_CAPTURE_RAW = 0, |
| 39 |
STF_CAPTURE_YUV, |
| 40 |
STF_CAPTURE_NUM, |
| 41 |
}; |
| 42 |
|
| 43 |
struct stfcamss_buffer { |
| 44 |
struct vb2_v4l2_buffer vb; |
| 45 |
dma_addr_t addr[2]; |
| 46 |
struct list_head queue; |
| 47 |
}; |
| 48 |
|
| 49 |
struct fract { |
| 50 |
u8 numerator; |
| 51 |
u8 denominator; |
| 52 |
}; |
| 53 |
|
| 54 |
/* |
| 55 |
* struct stfcamss_format_info - ISP media bus format information |
| 56 |
* @code: V4L2 media bus format code |
| 57 |
* @pixelformat: V4L2 pixel format FCC identifier |
| 58 |
* @planes: Number of planes |
| 59 |
* @vsub: Vertical subsampling (for each plane) |
| 60 |
* @bpp: Bits per pixel when stored in memory (for each plane) |
| 61 |
*/ |
| 62 |
struct stfcamss_format_info { |
| 63 |
u32 code; |
| 64 |
u32 pixelformat; |
| 65 |
u8 planes; |
| 66 |
u8 vsub[3]; |
| 67 |
u8 bpp; |
| 68 |
}; |
| 69 |
|
| 70 |
struct stfcamss_video { |
| 71 |
struct stfcamss *stfcamss; |
| 72 |
struct vb2_queue vb2_q; |
| 73 |
struct video_device vdev; |
| 74 |
struct media_pad pad; |
| 75 |
struct v4l2_format active_fmt; |
| 76 |
enum v4l2_buf_type type; |
| 77 |
const struct stfcamss_video_ops *ops; |
| 78 |
struct mutex lock; /* serialize device access */ |
| 79 |
struct mutex q_lock; /* protects the queue */ |
| 80 |
unsigned int bpl_alignment; |
| 81 |
const struct stfcamss_format_info *formats; |
| 82 |
unsigned int nformats; |
| 83 |
struct v4l2_subdev *source_subdev; |
| 84 |
}; |
| 85 |
|
| 86 |
struct stfcamss_video_ops { |
| 87 |
int (*queue_buffer)(struct stfcamss_video *video, |
| 88 |
struct stfcamss_buffer *buf); |
| 89 |
int (*flush_buffers)(struct stfcamss_video *video, |
| 90 |
enum vb2_buffer_state state); |
| 91 |
void (*start_streaming)(struct stfcamss_video *video); |
| 92 |
void (*stop_streaming)(struct stfcamss_video *video); |
| 93 |
}; |
| 94 |
|
| 95 |
int stf_video_register(struct stfcamss_video *video, |
| 96 |
struct v4l2_device *v4l2_dev, const char *name); |
| 97 |
|
| 98 |
void stf_video_unregister(struct stfcamss_video *video); |
| 99 |
|
| 100 |
#endif /* STF_VIDEO_H */ |