xref: /linux/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.h (revision 9f2c9170934eace462499ba0bfe042cc72900173)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2011-2018 Magewell Electronics Co., Ltd. (Nanjing)
4  * Author: Yong Deng <yong.deng@magewell.com>
5  * Copyright 2021-2022 Bootlin
6  * Author: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
7  */
8 
9 #ifndef _SUN6I_CAPTURE_H_
10 #define _SUN6I_CAPTURE_H_
11 
12 #include <media/v4l2-device.h>
13 
14 #define SUN6I_CSI_CAPTURE_NAME	"sun6i-csi-capture"
15 
16 #define SUN6I_CSI_CAPTURE_WIDTH_MIN	32
17 #define SUN6I_CSI_CAPTURE_WIDTH_MAX	4800
18 #define SUN6I_CSI_CAPTURE_HEIGHT_MIN	32
19 #define SUN6I_CSI_CAPTURE_HEIGHT_MAX	4800
20 
21 struct sun6i_csi_device;
22 
23 struct sun6i_csi_capture_format {
24 	u32	pixelformat;
25 	u8	output_format_field;
26 	u8	output_format_frame;
27 	bool	input_yuv_seq_invert;
28 	bool	input_format_raw;
29 	u32	hsize_len_factor;
30 };
31 
32 struct sun6i_csi_capture_format_match {
33 	u32	pixelformat;
34 	u32	mbus_code;
35 };
36 
37 #undef current
38 struct sun6i_csi_capture_state {
39 	struct list_head		queue;
40 	spinlock_t			lock; /* Queue and buffers lock. */
41 
42 	struct sun6i_csi_buffer		*pending;
43 	struct sun6i_csi_buffer		*current;
44 	struct sun6i_csi_buffer		*complete;
45 
46 	unsigned int			sequence;
47 	bool				streaming;
48 	bool				setup;
49 };
50 
51 struct sun6i_csi_capture {
52 	struct sun6i_csi_capture_state	state;
53 
54 	struct video_device		video_dev;
55 	struct vb2_queue		queue;
56 	struct mutex			lock; /* Queue lock. */
57 	struct media_pad		pad;
58 
59 	struct v4l2_format		format;
60 };
61 
62 /* Helpers */
63 
64 void sun6i_csi_capture_dimensions(struct sun6i_csi_device *csi_dev,
65 				  unsigned int *width, unsigned int *height);
66 void sun6i_csi_capture_format(struct sun6i_csi_device *csi_dev,
67 			      u32 *pixelformat, u32 *field);
68 
69 /* Format */
70 
71 const
72 struct sun6i_csi_capture_format *sun6i_csi_capture_format_find(u32 pixelformat);
73 
74 /* Capture */
75 
76 void sun6i_csi_capture_configure(struct sun6i_csi_device *csi_dev);
77 void sun6i_csi_capture_state_update(struct sun6i_csi_device *csi_dev);
78 
79 /* State */
80 
81 void sun6i_csi_capture_sync(struct sun6i_csi_device *csi_dev);
82 void sun6i_csi_capture_frame_done(struct sun6i_csi_device *csi_dev);
83 
84 /* Capture */
85 
86 int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev);
87 void sun6i_csi_capture_cleanup(struct sun6i_csi_device *csi_dev);
88 
89 #endif
90