1
2
3
4
5
6
7
8
9
10
11
12#ifndef CAMIF_CORE_H_
13#define CAMIF_CORE_H_
14
15#include <linux/io.h>
16#include <linux/irq.h>
17#include <linux/platform_device.h>
18#include <linux/sched.h>
19#include <linux/spinlock.h>
20#include <linux/types.h>
21#include <linux/videodev2.h>
22
23#include <media/media-entity.h>
24#include <media/v4l2-ctrls.h>
25#include <media/v4l2-dev.h>
26#include <media/v4l2-device.h>
27#include <media/v4l2-mediabus.h>
28#include <media/videobuf2-v4l2.h>
29#include <media/drv-intf/s3c_camif.h>
30
31#define S3C_CAMIF_DRIVER_NAME "s3c-camif"
32#define CAMIF_REQ_BUFS_MIN 3
33#define CAMIF_MAX_OUT_BUFS 4
34#define CAMIF_MAX_PIX_WIDTH 4096
35#define CAMIF_MAX_PIX_HEIGHT 4096
36#define SCALER_MAX_RATIO 64
37#define CAMIF_DEF_WIDTH 640
38#define CAMIF_DEF_HEIGHT 480
39#define CAMIF_STOP_TIMEOUT 1500
40
41#define S3C244X_CAMIF_IP_REV 0x20
42#define S3C2450_CAMIF_IP_REV 0x30
43#define S3C6400_CAMIF_IP_REV 0x31
44#define S3C6410_CAMIF_IP_REV 0x32
45
46
47
48#define ST_VP_PENDING (1 << 0)
49#define ST_VP_RUNNING (1 << 1)
50#define ST_VP_STREAMING (1 << 2)
51#define ST_VP_SENSOR_STREAMING (1 << 3)
52
53#define ST_VP_ABORTING (1 << 4)
54#define ST_VP_OFF (1 << 5)
55#define ST_VP_LASTIRQ (1 << 6)
56
57#define ST_VP_CONFIG (1 << 8)
58
59#define CAMIF_SD_PAD_SINK 0
60#define CAMIF_SD_PAD_SOURCE_C 1
61#define CAMIF_SD_PAD_SOURCE_P 2
62#define CAMIF_SD_PADS_NUM 3
63
64enum img_fmt {
65 IMG_FMT_RGB565 = 0x0010,
66 IMG_FMT_RGB666,
67 IMG_FMT_XRGB8888,
68 IMG_FMT_YCBCR420 = 0x0020,
69 IMG_FMT_YCRCB420,
70 IMG_FMT_YCBCR422P,
71 IMG_FMT_YCBYCR422 = 0x0040,
72 IMG_FMT_YCRYCB422,
73 IMG_FMT_CBYCRY422,
74 IMG_FMT_CRYCBY422,
75};
76
77#define img_fmt_is_rgb(x) ((x) & 0x10)
78#define img_fmt_is_ycbcr(x) ((x) & 0x60)
79
80
81#define FMT_FL_S3C24XX_CODEC (1 << 0)
82#define FMT_FL_S3C24XX_PREVIEW (1 << 1)
83#define FMT_FL_S3C64XX (1 << 2)
84
85
86
87
88
89
90
91
92
93
94struct camif_fmt {
95 char *name;
96 u32 fourcc;
97 u32 color;
98 u16 colplanes;
99 u16 flags;
100 u8 depth;
101 u8 ybpp;
102};
103
104
105
106
107
108
109struct camif_dma_offset {
110 int initial;
111 int line;
112};
113
114
115
116
117
118
119
120
121struct camif_frame {
122 u16 f_width;
123 u16 f_height;
124 struct v4l2_rect rect;
125 struct camif_dma_offset dma_offset;
126};
127
128
129enum {
130 CLK_GATE,
131 CLK_CAM,
132 CLK_MAX_NUM,
133};
134
135struct vp_pix_limits {
136 u16 max_out_width;
137 u16 max_sc_out_width;
138 u16 out_width_align;
139 u16 max_height;
140 u8 min_out_width;
141 u16 out_hor_offset_align;
142};
143
144struct camif_pix_limits {
145 u16 win_hor_offset_align;
146};
147
148
149
150
151
152
153
154struct s3c_camif_variant {
155 struct vp_pix_limits vp_pix_limits[2];
156 struct camif_pix_limits pix_limits;
157 u8 ip_revision;
158 u8 has_img_effect;
159 unsigned int vp_offset;
160};
161
162struct s3c_camif_drvdata {
163 const struct s3c_camif_variant *variant;
164 unsigned long bus_clk_freq;
165};
166
167struct camif_scaler {
168 u8 scaleup_h;
169 u8 scaleup_v;
170 u8 copy;
171 u8 enable;
172 u32 h_shift;
173 u32 v_shift;
174 u32 pre_h_ratio;
175 u32 pre_v_ratio;
176 u32 pre_dst_width;
177 u32 pre_dst_height;
178 u32 main_h_ratio;
179 u32 main_v_ratio;
180};
181
182struct camif_dev;
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210struct camif_vp {
211 wait_queue_head_t irq_queue;
212 int irq;
213 struct camif_dev *camif;
214 struct media_pad pad;
215 struct video_device vdev;
216 struct v4l2_ctrl_handler ctrl_handler;
217 struct v4l2_fh *owner;
218 struct vb2_queue vb_queue;
219 struct list_head pending_buf_q;
220 struct list_head active_buf_q;
221 unsigned int active_buffers;
222 unsigned int buf_index;
223 unsigned int frame_sequence;
224 unsigned int reqbufs_count;
225 struct camif_scaler scaler;
226 const struct camif_fmt *out_fmt;
227 unsigned int payload;
228 struct camif_frame out_frame;
229 unsigned int state;
230 u16 fmt_flags;
231 u8 id;
232 u16 rotation;
233 u8 hflip;
234 u8 vflip;
235 unsigned int offset;
236};
237
238
239#define VP_CODEC 0
240#define VP_PREVIEW 1
241#define CAMIF_VP_NUM 2
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265struct camif_dev {
266 struct media_device media_dev;
267 struct v4l2_device v4l2_dev;
268 struct v4l2_subdev subdev;
269 struct v4l2_mbus_framefmt mbus_fmt;
270 struct v4l2_rect camif_crop;
271 struct media_pad pads[CAMIF_SD_PADS_NUM];
272 int stream_count;
273
274 struct cam_sensor {
275 struct v4l2_subdev *sd;
276 short power_count;
277 short stream_count;
278 } sensor;
279 struct media_pipeline *m_pipeline;
280
281 struct v4l2_ctrl_handler ctrl_handler;
282 struct v4l2_ctrl *ctrl_test_pattern;
283 struct {
284 struct v4l2_ctrl *ctrl_colorfx;
285 struct v4l2_ctrl *ctrl_colorfx_cbcr;
286 };
287 u8 test_pattern;
288 u8 colorfx;
289 u8 colorfx_cb;
290 u8 colorfx_cr;
291
292 struct camif_vp vp[CAMIF_VP_NUM];
293
294 const struct s3c_camif_variant *variant;
295 struct device *dev;
296 struct s3c_camif_plat_data pdata;
297 struct clk *clock[CLK_MAX_NUM];
298 struct mutex lock;
299 spinlock_t slock;
300 void __iomem *io_base;
301};
302
303
304
305
306
307
308
309struct camif_addr {
310 dma_addr_t y;
311 dma_addr_t cb;
312 dma_addr_t cr;
313};
314
315
316
317
318
319
320
321
322struct camif_buffer {
323 struct vb2_v4l2_buffer vb;
324 struct list_head list;
325 struct camif_addr paddr;
326 unsigned int index;
327};
328
329const struct camif_fmt *s3c_camif_find_format(struct camif_vp *vp,
330 const u32 *pixelformat, int index);
331int s3c_camif_register_video_node(struct camif_dev *camif, int idx);
332void s3c_camif_unregister_video_node(struct camif_dev *camif, int idx);
333irqreturn_t s3c_camif_irq_handler(int irq, void *priv);
334int s3c_camif_create_subdev(struct camif_dev *camif);
335void s3c_camif_unregister_subdev(struct camif_dev *camif);
336int s3c_camif_set_defaults(struct camif_dev *camif);
337int s3c_camif_get_scaler_config(struct camif_vp *vp,
338 struct camif_scaler *scaler);
339
340static inline void camif_active_queue_add(struct camif_vp *vp,
341 struct camif_buffer *buf)
342{
343 list_add_tail(&buf->list, &vp->active_buf_q);
344 vp->active_buffers++;
345}
346
347static inline struct camif_buffer *camif_active_queue_pop(
348 struct camif_vp *vp)
349{
350 struct camif_buffer *buf = list_first_entry(&vp->active_buf_q,
351 struct camif_buffer, list);
352 list_del(&buf->list);
353 vp->active_buffers--;
354 return buf;
355}
356
357static inline struct camif_buffer *camif_active_queue_peek(
358 struct camif_vp *vp, int index)
359{
360 struct camif_buffer *tmp, *buf;
361
362 if (WARN_ON(list_empty(&vp->active_buf_q)))
363 return NULL;
364
365 list_for_each_entry_safe(buf, tmp, &vp->active_buf_q, list) {
366 if (buf->index == index) {
367 list_del(&buf->list);
368 vp->active_buffers--;
369 return buf;
370 }
371 }
372
373 return NULL;
374}
375
376static inline void camif_pending_queue_add(struct camif_vp *vp,
377 struct camif_buffer *buf)
378{
379 list_add_tail(&buf->list, &vp->pending_buf_q);
380}
381
382static inline struct camif_buffer *camif_pending_queue_pop(
383 struct camif_vp *vp)
384{
385 struct camif_buffer *buf = list_first_entry(&vp->pending_buf_q,
386 struct camif_buffer, list);
387 list_del(&buf->list);
388 return buf;
389}
390
391#endif
392