xref: /OK3568_Linux_fs/kernel/drivers/media/platform/rockchip/isp1/common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Rockchip isp1 driver
3  *
4  * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  */
34 
35 #ifndef _RKISP1_COMMON_H
36 #define _RKISP1_COMMON_H
37 
38 #include <linux/mutex.h>
39 #include <linux/media.h>
40 #include <linux/rk-video-format.h>
41 #include <media/media-device.h>
42 #include <media/media-entity.h>
43 #include <media/v4l2-ctrls.h>
44 #include <media/v4l2-device.h>
45 #include <media/videobuf2-v4l2.h>
46 #include <media/v4l2-mc.h>
47 
48 #define RKISP1_DEFAULT_WIDTH		800
49 #define RKISP1_DEFAULT_HEIGHT		600
50 
51 #define RKISP1_MAX_STREAM		3
52 #define RKISP1_STREAM_MP		0
53 #define RKISP1_STREAM_SP		1
54 #define RKISP1_STREAM_RAW		2
55 
56 #define RKISP1_PLANE_Y			0
57 #define RKISP1_PLANE_CB			1
58 #define RKISP1_PLANE_CR			2
59 
60 #define RKISP1_EMDDATA_FIFO_MAX		4
61 #define RKISP1_DMATX_CHECK              0xA5A5A5A5
62 #define RKISP1_RK3326_USE_OLDMIPI	0
63 
64 enum rkisp1_sd_type {
65 	RKISP1_SD_SENSOR,
66 	RKISP1_SD_PHY_CSI,
67 	RKISP1_SD_VCM,
68 	RKISP1_SD_FLASH,
69 	RKISP1_SD_MAX,
70 };
71 
72 /* One structure per video node */
73 struct rkisp1_vdev_node {
74 	struct vb2_queue buf_queue;
75 	struct video_device vdev;
76 	struct media_pad pad;
77 };
78 
79 enum rkisp1_fmt_pix_type {
80 	FMT_YUV,
81 	FMT_RGB,
82 	FMT_BAYER,
83 	FMT_JPEG,
84 	FMT_MAX
85 };
86 
87 enum rkisp1_fmt_raw_pat_type {
88 	RAW_RGGB = 0,
89 	RAW_GRBG,
90 	RAW_GBRG,
91 	RAW_BGGR,
92 };
93 
94 struct rkisp1_buffer {
95 	struct vb2_v4l2_buffer vb;
96 	struct list_head queue;
97 	union {
98 		u32 buff_addr[VIDEO_MAX_PLANES];
99 		void *vaddr[VIDEO_MAX_PLANES];
100 	};
101 };
102 
103 struct rkisp1_dummy_buffer {
104 	void *vaddr;
105 	dma_addr_t dma_addr;
106 	u32 size;
107 };
108 
109 extern int rkisp1_debug;
110 
111 static inline
vdev_to_node(struct video_device * vdev)112 struct rkisp1_vdev_node *vdev_to_node(struct video_device *vdev)
113 {
114 	return container_of(vdev, struct rkisp1_vdev_node, vdev);
115 }
116 
queue_to_node(struct vb2_queue * q)117 static inline struct rkisp1_vdev_node *queue_to_node(struct vb2_queue *q)
118 {
119 	return container_of(q, struct rkisp1_vdev_node, buf_queue);
120 }
121 
to_rkisp1_buffer(struct vb2_v4l2_buffer * vb)122 static inline struct rkisp1_buffer *to_rkisp1_buffer(struct vb2_v4l2_buffer *vb)
123 {
124 	return container_of(vb, struct rkisp1_buffer, vb);
125 }
126 
to_vb2_queue(struct file * file)127 static inline struct vb2_queue *to_vb2_queue(struct file *file)
128 {
129 	struct rkisp1_vdev_node *vnode = video_drvdata(file);
130 
131 	return &vnode->buf_queue;
132 }
133 
134 #endif /* _RKISP1_COMMON_H */
135