• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _RKISP_COMMON_H
36 #define _RKISP_COMMON_H
37 
38 #include <linux/clk.h>
39 #include <linux/mutex.h>
40 #include <linux/media.h>
41 #include <linux/rk-video-format.h>
42 #include <media/media-device.h>
43 #include <media/media-entity.h>
44 #include <media/v4l2-ctrls.h>
45 #include <media/v4l2-device.h>
46 #include <media/videobuf2-dma-contig.h>
47 #include <media/videobuf2-v4l2.h>
48 #include <media/v4l2-mc.h>
49 
50 #define RKISP_DEFAULT_WIDTH		800
51 #define RKISP_DEFAULT_HEIGHT		600
52 
53 #define RKISP_PLANE_Y			0
54 #define RKISP_PLANE_CB			1
55 #define RKISP_PLANE_CR			2
56 
57 #define RKISP_EMDDATA_FIFO_MAX		4
58 #define RKISP_DMATX_CHECK              0xA5A5A5A5
59 
60 #define RKISP_MOTION_DECT_TS_SIZE	16
61 
62 struct rkisp_device;
63 
64 /* ISP_V10_1 for only support MP */
65 enum rkisp_isp_ver {
66 	ISP_V10 = 0x00,
67 	ISP_V10_1 = 0x01,
68 	ISP_V11 = 0x10,
69 	ISP_V12 = 0x20,
70 	ISP_V13 = 0x30,
71 	ISP_V20 = 0x40,
72 	ISP_V21 = 0x50,
73 	ISP_V30 = 0x60,
74 };
75 
76 enum rkisp_sd_type {
77 	RKISP_SD_SENSOR,
78 	RKISP_SD_PHY_CSI,
79 	RKISP_SD_VCM,
80 	RKISP_SD_FLASH,
81 	RKISP_SD_MAX,
82 };
83 
84 /* One structure per video node */
85 struct rkisp_vdev_node {
86 	struct vb2_queue buf_queue;
87 	struct video_device vdev;
88 	struct media_pad pad;
89 };
90 
91 enum rkisp_fmt_pix_type {
92 	FMT_YUV,
93 	FMT_RGB,
94 	FMT_BAYER,
95 	FMT_JPEG,
96 	FMT_FBCGAIN,
97 	FMT_EBD,
98 	FMT_SPD,
99 	FMT_FBC,
100 	FMT_MAX
101 };
102 
103 enum rkisp_fmt_raw_pat_type {
104 	RAW_RGGB = 0,
105 	RAW_GRBG,
106 	RAW_GBRG,
107 	RAW_BGGR,
108 };
109 
110 struct rkisp_buffer {
111 	struct vb2_v4l2_buffer vb;
112 	struct list_head queue;
113 	int dev_id;
114 	union {
115 		u32 buff_addr[VIDEO_MAX_PLANES];
116 		void *vaddr[VIDEO_MAX_PLANES];
117 	};
118 };
119 
120 struct rkisp_dummy_buffer {
121 	struct list_head queue;
122 	struct dma_buf *dbuf;
123 	dma_addr_t dma_addr;
124 	struct page **pages;
125 	void *mem_priv;
126 	void *vaddr;
127 	u32 size;
128 	int dma_fd;
129 	bool is_need_vaddr;
130 	bool is_need_dbuf;
131 	bool is_need_dmafd;
132 };
133 
134 extern int rkisp_debug;
135 extern bool rkisp_monitor;
136 extern u64 rkisp_debug_reg;
137 extern struct platform_driver rkisp_plat_drv;
138 
139 static inline
vdev_to_node(struct video_device * vdev)140 struct rkisp_vdev_node *vdev_to_node(struct video_device *vdev)
141 {
142 	return container_of(vdev, struct rkisp_vdev_node, vdev);
143 }
144 
queue_to_node(struct vb2_queue * q)145 static inline struct rkisp_vdev_node *queue_to_node(struct vb2_queue *q)
146 {
147 	return container_of(q, struct rkisp_vdev_node, buf_queue);
148 }
149 
to_rkisp_buffer(struct vb2_v4l2_buffer * vb)150 static inline struct rkisp_buffer *to_rkisp_buffer(struct vb2_v4l2_buffer *vb)
151 {
152 	return container_of(vb, struct rkisp_buffer, vb);
153 }
154 
to_vb2_queue(struct file * file)155 static inline struct vb2_queue *to_vb2_queue(struct file *file)
156 {
157 	struct rkisp_vdev_node *vnode = video_drvdata(file);
158 
159 	return &vnode->buf_queue;
160 }
161 
162 void rkisp_write(struct rkisp_device *dev, u32 reg, u32 val, bool is_direct);
163 u32 rkisp_read(struct rkisp_device *dev, u32 reg, bool is_direct);
164 u32 rkisp_read_reg_cache(struct rkisp_device *dev, u32 reg);
165 void rkisp_set_bits(struct rkisp_device *dev, u32 reg, u32 mask, u32 val, bool is_direct);
166 void rkisp_clear_bits(struct rkisp_device *dev, u32 reg, u32 mask, bool is_direct);
167 /* for dual isp, config for next isp reg */
168 void rkisp_next_write(struct rkisp_device *dev, u32 reg, u32 val, bool is_direct);
169 u32 rkisp_next_read(struct rkisp_device *dev, u32 reg, bool is_direct);
170 u32 rkisp_next_read_reg_cache(struct rkisp_device *dev, u32 reg);
171 void rkisp_next_set_bits(struct rkisp_device *dev, u32 reg, u32 mask, u32 val, bool is_direct);
172 void rkisp_next_clear_bits(struct rkisp_device *dev, u32 reg, u32 mask, bool is_direct);
173 
174 static inline void
rkisp_unite_write(struct rkisp_device * dev,u32 reg,u32 val,bool is_direct,bool is_unite)175 rkisp_unite_write(struct rkisp_device *dev, u32 reg, u32 val, bool is_direct, bool is_unite)
176 {
177 	rkisp_write(dev, reg, val, is_direct);
178 	if (is_unite)
179 		rkisp_next_write(dev, reg, val, is_direct);
180 }
181 
182 static inline void
rkisp_unite_set_bits(struct rkisp_device * dev,u32 reg,u32 mask,u32 val,bool is_direct,bool is_unite)183 rkisp_unite_set_bits(struct rkisp_device *dev, u32 reg, u32 mask,
184 		     u32 val, bool is_direct, bool is_unite)
185 {
186 	rkisp_set_bits(dev, reg, mask, val, is_direct);
187 	if (is_unite)
188 		rkisp_next_set_bits(dev, reg, mask, val, is_direct);
189 }
190 
191 static inline void
rkisp_unite_clear_bits(struct rkisp_device * dev,u32 reg,u32 mask,bool is_direct,bool is_unite)192 rkisp_unite_clear_bits(struct rkisp_device *dev, u32 reg, u32 mask,
193 		       bool is_direct, bool is_unite)
194 {
195 	rkisp_clear_bits(dev, reg, mask, is_direct);
196 	if (is_unite)
197 		rkisp_next_clear_bits(dev, reg, mask, is_direct);
198 }
199 
200 void rkisp_update_regs(struct rkisp_device *dev, u32 start, u32 end);
201 
202 int rkisp_alloc_buffer(struct rkisp_device *dev, struct rkisp_dummy_buffer *buf);
203 void rkisp_free_buffer(struct rkisp_device *dev, struct rkisp_dummy_buffer *buf);
204 void rkisp_prepare_buffer(struct rkisp_device *dev, struct rkisp_dummy_buffer *buf);
205 void rkisp_finish_buffer(struct rkisp_device *dev, struct rkisp_dummy_buffer *buf);
206 
207 int rkisp_attach_hw(struct rkisp_device *isp);
208 int rkisp_alloc_common_dummy_buf(struct rkisp_device *dev);
209 void rkisp_free_common_dummy_buf(struct rkisp_device *dev);
210 
211 void rkisp_set_clk_rate(struct clk *clk, unsigned long rate);
212 #endif /* _RKISP_COMMON_H */
213