1
2
3
4
5
6
7
8
9#ifndef AM437X_VPFE_H
10#define AM437X_VPFE_H
11
12#include <linux/am437x-vpfe.h>
13#include <linux/clk.h>
14#include <linux/completion.h>
15#include <linux/device.h>
16#include <linux/io.h>
17#include <linux/i2c.h>
18#include <linux/videodev2.h>
19
20#include <media/v4l2-dev.h>
21#include <media/v4l2-device.h>
22#include <media/v4l2-ioctl.h>
23#include <media/videobuf2-v4l2.h>
24#include <media/videobuf2-dma-contig.h>
25
26#include "am437x-vpfe_regs.h"
27
28enum vpfe_pin_pol {
29 VPFE_PINPOL_POSITIVE = 0,
30 VPFE_PINPOL_NEGATIVE,
31};
32
33enum vpfe_hw_if_type {
34
35 VPFE_RAW_BAYER = 0,
36
37 VPFE_BT656,
38
39 VPFE_BT656_10BIT,
40
41 VPFE_YCBCR_SYNC_8,
42
43 VPFE_YCBCR_SYNC_16,
44};
45
46
47struct vpfe_hw_if_param {
48 enum vpfe_hw_if_type if_type;
49 enum vpfe_pin_pol hdpol;
50 enum vpfe_pin_pol vdpol;
51 unsigned int bus_width;
52};
53
54#define VPFE_MAX_SUBDEV 1
55#define VPFE_MAX_INPUTS 1
56
57struct vpfe_std_info {
58 int active_pixels;
59 int active_lines;
60
61 int frame_format;
62};
63
64struct vpfe_route {
65 u32 input;
66 u32 output;
67};
68
69struct vpfe_subdev_info {
70
71 int grp_id;
72
73 struct v4l2_input inputs[VPFE_MAX_INPUTS];
74
75 struct vpfe_route *routes;
76
77 int can_route;
78
79 struct vpfe_hw_if_param vpfe_param;
80 struct v4l2_subdev *sd;
81};
82
83struct vpfe_config {
84
85 struct vpfe_subdev_info sub_devs[VPFE_MAX_SUBDEV];
86
87 struct v4l2_async_subdev *asd[VPFE_MAX_SUBDEV];
88};
89
90struct vpfe_cap_buffer {
91 struct vb2_v4l2_buffer vb;
92 struct list_head list;
93};
94
95enum ccdc_pixfmt {
96 CCDC_PIXFMT_RAW = 0,
97 CCDC_PIXFMT_YCBCR_16BIT,
98 CCDC_PIXFMT_YCBCR_8BIT,
99};
100
101enum ccdc_frmfmt {
102 CCDC_FRMFMT_PROGRESSIVE = 0,
103 CCDC_FRMFMT_INTERLACED,
104};
105
106
107
108enum ccdc_pixorder {
109 CCDC_PIXORDER_YCBYCR,
110 CCDC_PIXORDER_CBYCRY,
111};
112
113enum ccdc_buftype {
114 CCDC_BUFTYPE_FLD_INTERLEAVED,
115 CCDC_BUFTYPE_FLD_SEPARATED
116};
117
118
119
120static inline u8 ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width)
121{
122 return 15 - width;
123}
124
125
126static inline u8 ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz)
127{
128 return sz == VPFE_CCDC_DATA_8BITS ? 7 : 15 - sz;
129}
130
131
132struct ccdc_params_raw {
133
134 enum ccdc_pixfmt pix_fmt;
135
136 enum ccdc_frmfmt frm_fmt;
137 struct v4l2_rect win;
138
139 unsigned int bytesperpixel;
140
141
142
143 unsigned int bytesperline;
144
145 enum vpfe_pin_pol fid_pol;
146
147 enum vpfe_pin_pol vd_pol;
148
149 enum vpfe_pin_pol hd_pol;
150
151 enum ccdc_buftype buf_type;
152
153
154
155
156 unsigned char image_invert_enable;
157
158 struct vpfe_ccdc_config_params_raw config_params;
159};
160
161struct ccdc_params_ycbcr {
162
163 enum ccdc_pixfmt pix_fmt;
164
165 enum ccdc_frmfmt frm_fmt;
166 struct v4l2_rect win;
167
168 unsigned int bytesperpixel;
169
170
171
172 unsigned int bytesperline;
173
174 enum vpfe_pin_pol fid_pol;
175
176 enum vpfe_pin_pol vd_pol;
177
178 enum vpfe_pin_pol hd_pol;
179
180 int bt656_enable;
181
182 enum ccdc_pixorder pix_order;
183
184 enum ccdc_buftype buf_type;
185};
186
187
188
189
190struct ccdc_config {
191
192 enum vpfe_hw_if_type if_type;
193
194 struct ccdc_params_raw bayer;
195
196 struct ccdc_params_ycbcr ycbcr;
197
198 void __iomem *base_addr;
199};
200
201struct vpfe_ccdc {
202 struct ccdc_config ccdc_cfg;
203 u32 ccdc_ctx[VPFE_REG_END / sizeof(u32)];
204};
205
206
207
208
209
210
211
212struct vpfe_fmt {
213 u32 fourcc;
214 u32 code;
215 u32 bitsperpixel;
216};
217
218
219
220
221
222
223#define VPFE_NUM_FORMATS 10
224
225struct vpfe_device {
226
227
228 struct video_device video_dev;
229
230 struct v4l2_subdev **sd;
231
232 struct vpfe_config *cfg;
233
234 struct v4l2_device v4l2_dev;
235
236 struct device *pdev;
237
238 struct v4l2_async_notifier notifier;
239
240 unsigned field;
241 unsigned sequence;
242
243 struct vpfe_hw_if_param vpfe_if_params;
244
245 struct vpfe_subdev_info *current_subdev;
246
247 int current_input;
248
249 struct vpfe_std_info std_info;
250
251 int std_index;
252
253 unsigned int irq;
254
255 struct vpfe_cap_buffer *cur_frm;
256
257 struct vpfe_cap_buffer *next_frm;
258
259 struct v4l2_format fmt;
260
261 struct vpfe_fmt *current_vpfe_fmt;
262 struct vpfe_fmt *active_fmt[VPFE_NUM_FORMATS];
263 unsigned int num_active_fmt;
264
265
266
267
268
269 struct v4l2_rect crop;
270
271 struct vb2_queue buffer_queue;
272
273 struct list_head dma_queue;
274
275 spinlock_t dma_queue_lock;
276
277 struct mutex lock;
278
279
280
281
282 u32 field_off;
283 struct vpfe_ccdc ccdc;
284 int stopping;
285 struct completion capture_stop;
286};
287
288#endif
289