aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorSylwester Nawrocki <s.nawrocki@samsung.com>2010-08-03 08:50:29 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-08 22:43:01 -0400
commit5fd8f7388c9a8601c2dbe0da458df602fe427e83 (patch)
treeea4e3a6b6ea3639370d0e2905cdd76412c0b08c5 /drivers/media/video
parent70092c26dcfcdcc463e157c103ec4c9d2d49de67 (diff)
V4L/DVB: v4l: Add driver for Samsung S5P SoC video postprocessor
This driver exports a video device node per each camera interface/ video postprocessor (FIMC) device contained in Samsung S5P SoC series. The driver is based on v4l2-mem2mem framework. Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Pawel Osciak <p.osciak@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/Kconfig9
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/s5p-fimc/Makefile3
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c1570
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.h465
-rw-r--r--drivers/media/video/s5p-fimc/fimc-reg.c527
-rw-r--r--drivers/media/video/s5p-fimc/regs-fimc.h293
7 files changed, 2868 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 2e15903b976d..c70b67deb9b2 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -1016,4 +1016,13 @@ config VIDEO_MEM2MEM_TESTDEV
1016 This is a virtual test device for the memory-to-memory driver 1016 This is a virtual test device for the memory-to-memory driver
1017 framework. 1017 framework.
1018 1018
1019config VIDEO_SAMSUNG_S5P_FIMC
1020 tristate "Samsung S5P FIMC (video postprocessor) driver"
1021 depends on VIDEO_DEV && VIDEO_V4L2 && PLAT_S5P
1022 select VIDEOBUF_DMA_CONTIG
1023 select V4L2_MEM2MEM_DEV
1024 help
1025 This is a v4l2 driver for the S5P camera interface
1026 (video postprocessor)
1027
1019endif # V4L_MEM2MEM_DRIVERS 1028endif # V4L_MEM2MEM_DRIVERS
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 1051ecc602e7..c76fef390797 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -163,6 +163,7 @@ obj-$(CONFIG_VIDEO_MX3) += mx3_camera.o
163obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o 163obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
164obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o 164obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o
165obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o 165obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
166obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) += s5p-fimc/
166 167
167obj-$(CONFIG_ARCH_DAVINCI) += davinci/ 168obj-$(CONFIG_ARCH_DAVINCI) += davinci/
168 169
diff --git a/drivers/media/video/s5p-fimc/Makefile b/drivers/media/video/s5p-fimc/Makefile
new file mode 100644
index 000000000000..0d9d54132ecc
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/Makefile
@@ -0,0 +1,3 @@
1
2obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) := s5p-fimc.o
3s5p-fimc-y := fimc-core.o fimc-reg.o
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
new file mode 100644
index 000000000000..6558a2ea9ffd
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -0,0 +1,1570 @@
1/*
2 * S5P camera interface (video postprocessor) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics
5 *
6 * Sylwester Nawrocki, <s.nawrocki@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation, either version 2 of the License,
11 * or (at your option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/version.h>
17#include <linux/types.h>
18#include <linux/errno.h>
19#include <linux/bug.h>
20#include <linux/interrupt.h>
21#include <linux/device.h>
22#include <linux/platform_device.h>
23#include <linux/list.h>
24#include <linux/io.h>
25#include <linux/slab.h>
26#include <linux/clk.h>
27#include <media/v4l2-ioctl.h>
28#include <media/videobuf-dma-contig.h>
29
30#include "fimc-core.h"
31
32static char *fimc_clock_name[NUM_FIMC_CLOCKS] = { "sclk_fimc", "fimc" };
33
34static struct fimc_fmt fimc_formats[] = {
35 {
36 .name = "RGB565",
37 .fourcc = V4L2_PIX_FMT_RGB565X,
38 .depth = 16,
39 .color = S5P_FIMC_RGB565,
40 .buff_cnt = 1,
41 .planes_cnt = 1
42 }, {
43 .name = "BGR666",
44 .fourcc = V4L2_PIX_FMT_BGR666,
45 .depth = 32,
46 .color = S5P_FIMC_RGB666,
47 .buff_cnt = 1,
48 .planes_cnt = 1
49 }, {
50 .name = "XRGB-8-8-8-8, 24 bpp",
51 .fourcc = V4L2_PIX_FMT_RGB24,
52 .depth = 32,
53 .color = S5P_FIMC_RGB888,
54 .buff_cnt = 1,
55 .planes_cnt = 1
56 }, {
57 .name = "YUV 4:2:2 packed, YCbYCr",
58 .fourcc = V4L2_PIX_FMT_YUYV,
59 .depth = 16,
60 .color = S5P_FIMC_YCBYCR422,
61 .buff_cnt = 1,
62 .planes_cnt = 1
63 }, {
64 .name = "YUV 4:2:2 packed, CbYCrY",
65 .fourcc = V4L2_PIX_FMT_UYVY,
66 .depth = 16,
67 .color = S5P_FIMC_CBYCRY422,
68 .buff_cnt = 1,
69 .planes_cnt = 1
70 }, {
71 .name = "YUV 4:2:2 packed, CrYCbY",
72 .fourcc = V4L2_PIX_FMT_VYUY,
73 .depth = 16,
74 .color = S5P_FIMC_CRYCBY422,
75 .buff_cnt = 1,
76 .planes_cnt = 1
77 }, {
78 .name = "YUV 4:2:2 packed, YCrYCb",
79 .fourcc = V4L2_PIX_FMT_YVYU,
80 .depth = 16,
81 .color = S5P_FIMC_YCRYCB422,
82 .buff_cnt = 1,
83 .planes_cnt = 1
84 }, {
85 .name = "YUV 4:2:2 planar, Y/Cb/Cr",
86 .fourcc = V4L2_PIX_FMT_YUV422P,
87 .depth = 12,
88 .color = S5P_FIMC_YCBCR422,
89 .buff_cnt = 1,
90 .planes_cnt = 3
91 }, {
92 .name = "YUV 4:2:2 planar, Y/CbCr",
93 .fourcc = V4L2_PIX_FMT_NV16,
94 .depth = 16,
95 .color = S5P_FIMC_YCBCR422,
96 .buff_cnt = 1,
97 .planes_cnt = 2
98 }, {
99 .name = "YUV 4:2:2 planar, Y/CrCb",
100 .fourcc = V4L2_PIX_FMT_NV61,
101 .depth = 16,
102 .color = S5P_FIMC_RGB565,
103 .buff_cnt = 1,
104 .planes_cnt = 2
105 }, {
106 .name = "YUV 4:2:0 planar, YCbCr",
107 .fourcc = V4L2_PIX_FMT_YUV420,
108 .depth = 12,
109 .color = S5P_FIMC_YCBCR420,
110 .buff_cnt = 1,
111 .planes_cnt = 3
112 }, {
113 .name = "YUV 4:2:0 planar, Y/CbCr",
114 .fourcc = V4L2_PIX_FMT_NV12,
115 .depth = 12,
116 .color = S5P_FIMC_YCBCR420,
117 .buff_cnt = 1,
118 .planes_cnt = 2
119 }
120 };
121
122static struct v4l2_queryctrl fimc_ctrls[] = {
123 {
124 .id = V4L2_CID_HFLIP,
125 .type = V4L2_CTRL_TYPE_BOOLEAN,
126 .name = "Horizontal flip",
127 .minimum = 0,
128 .maximum = 1,
129 .default_value = 0,
130 },
131 {
132 .id = V4L2_CID_VFLIP,
133 .type = V4L2_CTRL_TYPE_BOOLEAN,
134 .name = "Vertical flip",
135 .minimum = 0,
136 .maximum = 1,
137 .default_value = 0,
138 },
139 {
140 .id = V4L2_CID_ROTATE,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Rotation (CCW)",
143 .minimum = 0,
144 .maximum = 270,
145 .step = 90,
146 .default_value = 0,
147 },
148};
149
150
151static struct v4l2_queryctrl *get_ctrl(int id)
152{
153 int i;
154
155 for (i = 0; i < ARRAY_SIZE(fimc_ctrls); ++i)
156 if (id == fimc_ctrls[i].id)
157 return &fimc_ctrls[i];
158 return NULL;
159}
160
161static int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f)
162{
163 if (r->width > f->width) {
164 if (f->width > (r->width * SCALER_MAX_HRATIO))
165 return -EINVAL;
166 } else {
167 if ((f->width * SCALER_MAX_HRATIO) < r->width)
168 return -EINVAL;
169 }
170
171 if (r->height > f->height) {
172 if (f->height > (r->height * SCALER_MAX_VRATIO))
173 return -EINVAL;
174 } else {
175 if ((f->height * SCALER_MAX_VRATIO) < r->height)
176 return -EINVAL;
177 }
178
179 return 0;
180}
181
182static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
183{
184 if (src >= tar * 64) {
185 return -EINVAL;
186 } else if (src >= tar * 32) {
187 *ratio = 32;
188 *shift = 5;
189 } else if (src >= tar * 16) {
190 *ratio = 16;
191 *shift = 4;
192 } else if (src >= tar * 8) {
193 *ratio = 8;
194 *shift = 3;
195 } else if (src >= tar * 4) {
196 *ratio = 4;
197 *shift = 2;
198 } else if (src >= tar * 2) {
199 *ratio = 2;
200 *shift = 1;
201 } else {
202 *ratio = 1;
203 *shift = 0;
204 }
205
206 return 0;
207}
208
209static int fimc_set_scaler_info(struct fimc_ctx *ctx)
210{
211 struct fimc_scaler *sc = &ctx->scaler;
212 struct fimc_frame *s_frame = &ctx->s_frame;
213 struct fimc_frame *d_frame = &ctx->d_frame;
214 int tx, ty, sx, sy;
215 int ret;
216
217 tx = d_frame->width;
218 ty = d_frame->height;
219 if (tx <= 0 || ty <= 0) {
220 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
221 "invalid target size: %d x %d", tx, ty);
222 return -EINVAL;
223 }
224
225 sx = s_frame->width;
226 sy = s_frame->height;
227 if (sx <= 0 || sy <= 0) {
228 err("invalid source size: %d x %d", sx, sy);
229 return -EINVAL;
230 }
231
232 sc->real_width = sx;
233 sc->real_height = sy;
234 dbg("sx= %d, sy= %d, tx= %d, ty= %d", sx, sy, tx, ty);
235
236 ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
237 if (ret)
238 return ret;
239
240 ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
241 if (ret)
242 return ret;
243
244 sc->pre_dst_width = sx / sc->pre_hratio;
245 sc->pre_dst_height = sy / sc->pre_vratio;
246
247 sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
248 sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
249
250 sc->scaleup_h = (tx >= sx) ? 1 : 0;
251 sc->scaleup_v = (ty >= sy) ? 1 : 0;
252
253 /* check to see if input and output size/format differ */
254 if (s_frame->fmt->color == d_frame->fmt->color
255 && s_frame->width == d_frame->width
256 && s_frame->height == d_frame->height)
257 sc->copy_mode = 1;
258 else
259 sc->copy_mode = 0;
260
261 return 0;
262}
263
264
265static irqreturn_t fimc_isr(int irq, void *priv)
266{
267 struct fimc_vid_buffer *src_buf, *dst_buf;
268 struct fimc_dev *fimc = (struct fimc_dev *)priv;
269 struct fimc_ctx *ctx;
270
271 BUG_ON(!fimc);
272 fimc_hw_clear_irq(fimc);
273
274 spin_lock(&fimc->slock);
275
276 if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
277 ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
278 if (!ctx || !ctx->m2m_ctx)
279 goto isr_unlock;
280 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
281 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
282 if (src_buf && dst_buf) {
283 spin_lock(&fimc->irqlock);
284 src_buf->vb.state = dst_buf->vb.state = VIDEOBUF_DONE;
285 wake_up(&src_buf->vb.done);
286 wake_up(&dst_buf->vb.done);
287 spin_unlock(&fimc->irqlock);
288 v4l2_m2m_job_finish(fimc->m2m.m2m_dev, ctx->m2m_ctx);
289 }
290 }
291
292isr_unlock:
293 spin_unlock(&fimc->slock);
294 return IRQ_HANDLED;
295}
296
297/* The color format (planes_cnt, buff_cnt) must be already configured. */
298static int fimc_prepare_addr(struct fimc_ctx *ctx,
299 struct fimc_vid_buffer *buf, enum v4l2_buf_type type)
300{
301 struct fimc_frame *frame;
302 struct fimc_addr *paddr;
303 u32 pix_size;
304 int ret = 0;
305
306 ctx_m2m_get_frame(frame, ctx, type);
307 paddr = &frame->paddr;
308
309 if (!buf)
310 return -EINVAL;
311
312 pix_size = frame->width * frame->height;
313
314 dbg("buff_cnt= %d, planes_cnt= %d, frame->size= %d, pix_size= %d",
315 frame->fmt->buff_cnt, frame->fmt->planes_cnt,
316 frame->size, pix_size);
317
318 if (frame->fmt->buff_cnt == 1) {
319 paddr->y = videobuf_to_dma_contig(&buf->vb);
320 switch (frame->fmt->planes_cnt) {
321 case 1:
322 paddr->cb = 0;
323 paddr->cr = 0;
324 break;
325 case 2:
326 /* decompose Y into Y/Cb */
327 paddr->cb = (u32)(paddr->y + pix_size);
328 paddr->cr = 0;
329 break;
330 case 3:
331 paddr->cb = (u32)(paddr->y + pix_size);
332 /* decompose Y into Y/Cb/Cr */
333 if (S5P_FIMC_YCBCR420 == frame->fmt->color)
334 paddr->cr = (u32)(paddr->cb
335 + (pix_size >> 2));
336 else /* 422 */
337 paddr->cr = (u32)(paddr->cb
338 + (pix_size >> 1));
339 break;
340 default:
341 return -EINVAL;
342 }
343 }
344
345 dbg("PHYS_ADDR: type= %d, y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
346 type, paddr->y, paddr->cb, paddr->cr, ret);
347
348 return ret;
349}
350
351/* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
352static void fimc_set_yuv_order(struct fimc_ctx *ctx)
353{
354 /* The one only mode supported in SoC. */
355 ctx->in_order_2p = S5P_FIMC_LSB_CRCB;
356 ctx->out_order_2p = S5P_FIMC_LSB_CRCB;
357
358 /* Set order for 1 plane input formats. */
359 switch (ctx->s_frame.fmt->color) {
360 case S5P_FIMC_YCRYCB422:
361 ctx->in_order_1p = S5P_FIMC_IN_YCRYCB;
362 break;
363 case S5P_FIMC_CBYCRY422:
364 ctx->in_order_1p = S5P_FIMC_IN_CBYCRY;
365 break;
366 case S5P_FIMC_CRYCBY422:
367 ctx->in_order_1p = S5P_FIMC_IN_CRYCBY;
368 break;
369 case S5P_FIMC_YCBYCR422:
370 default:
371 ctx->in_order_1p = S5P_FIMC_IN_YCBYCR;
372 break;
373 }
374 dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
375
376 switch (ctx->d_frame.fmt->color) {
377 case S5P_FIMC_YCRYCB422:
378 ctx->out_order_1p = S5P_FIMC_OUT_YCRYCB;
379 break;
380 case S5P_FIMC_CBYCRY422:
381 ctx->out_order_1p = S5P_FIMC_OUT_CBYCRY;
382 break;
383 case S5P_FIMC_CRYCBY422:
384 ctx->out_order_1p = S5P_FIMC_OUT_CRYCBY;
385 break;
386 case S5P_FIMC_YCBYCR422:
387 default:
388 ctx->out_order_1p = S5P_FIMC_OUT_YCBYCR;
389 break;
390 }
391 dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
392}
393
394/**
395 * fimc_prepare_config - check dimensions, operation and color mode
396 * and pre-calculate offset and the scaling coefficients.
397 *
398 * @ctx: hardware context information
399 * @flags: flags indicating which parameters to check/update
400 *
401 * Return: 0 if dimensions are valid or non zero otherwise.
402 */
403static int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
404{
405 struct fimc_frame *s_frame, *d_frame;
406 struct fimc_vid_buffer *buf = NULL;
407 struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
408 int ret = 0;
409
410 s_frame = &ctx->s_frame;
411 d_frame = &ctx->d_frame;
412
413 if (flags & FIMC_PARAMS) {
414 if ((ctx->out_path == FIMC_DMA) &&
415 (ctx->rotation == 90 || ctx->rotation == 270)) {
416 swap(d_frame->f_width, d_frame->f_height);
417 swap(d_frame->width, d_frame->height);
418 }
419
420 /* Prepare the output offset ratios for scaler. */
421 d_frame->dma_offset.y_h = d_frame->offs_h;
422 if (!variant->pix_hoff)
423 d_frame->dma_offset.y_h *= (d_frame->fmt->depth >> 3);
424
425 d_frame->dma_offset.y_v = d_frame->offs_v;
426
427 d_frame->dma_offset.cb_h = d_frame->offs_h;
428 d_frame->dma_offset.cb_v = d_frame->offs_v;
429
430 d_frame->dma_offset.cr_h = d_frame->offs_h;
431 d_frame->dma_offset.cr_v = d_frame->offs_v;
432
433 if (!variant->pix_hoff && d_frame->fmt->planes_cnt == 3) {
434 d_frame->dma_offset.cb_h >>= 1;
435 d_frame->dma_offset.cb_v >>= 1;
436 d_frame->dma_offset.cr_h >>= 1;
437 d_frame->dma_offset.cr_v >>= 1;
438 }
439
440 dbg("out offset: color= %d, y_h= %d, y_v= %d",
441 d_frame->fmt->color,
442 d_frame->dma_offset.y_h, d_frame->dma_offset.y_v);
443
444 /* Prepare the input offset ratios for scaler. */
445 s_frame->dma_offset.y_h = s_frame->offs_h;
446 if (!variant->pix_hoff)
447 s_frame->dma_offset.y_h *= (s_frame->fmt->depth >> 3);
448 s_frame->dma_offset.y_v = s_frame->offs_v;
449
450 s_frame->dma_offset.cb_h = s_frame->offs_h;
451 s_frame->dma_offset.cb_v = s_frame->offs_v;
452
453 s_frame->dma_offset.cr_h = s_frame->offs_h;
454 s_frame->dma_offset.cr_v = s_frame->offs_v;
455
456 if (!variant->pix_hoff && s_frame->fmt->planes_cnt == 3) {
457 s_frame->dma_offset.cb_h >>= 1;
458 s_frame->dma_offset.cb_v >>= 1;
459 s_frame->dma_offset.cr_h >>= 1;
460 s_frame->dma_offset.cr_v >>= 1;
461 }
462
463 dbg("in offset: color= %d, y_h= %d, y_v= %d",
464 s_frame->fmt->color, s_frame->dma_offset.y_h,
465 s_frame->dma_offset.y_v);
466
467 fimc_set_yuv_order(ctx);
468
469 /* Check against the scaler ratio. */
470 if (s_frame->height > (SCALER_MAX_VRATIO * d_frame->height) ||
471 s_frame->width > (SCALER_MAX_HRATIO * d_frame->width)) {
472 err("out of scaler range");
473 return -EINVAL;
474 }
475 }
476
477 /* Input DMA mode is not allowed when the scaler is disabled. */
478 ctx->scaler.enabled = 1;
479
480 if (flags & FIMC_SRC_ADDR) {
481 buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
482 ret = fimc_prepare_addr(ctx, buf,
483 V4L2_BUF_TYPE_VIDEO_OUTPUT);
484 if (ret)
485 return ret;
486 }
487
488 if (flags & FIMC_DST_ADDR) {
489 buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
490 ret = fimc_prepare_addr(ctx, buf,
491 V4L2_BUF_TYPE_VIDEO_CAPTURE);
492 }
493
494 return ret;
495}
496
497static void fimc_dma_run(void *priv)
498{
499 struct fimc_ctx *ctx = priv;
500 struct fimc_dev *fimc;
501 unsigned long flags;
502 u32 ret;
503
504 if (WARN(!ctx, "null hardware context"))
505 return;
506
507 fimc = ctx->fimc_dev;
508
509 spin_lock_irqsave(&ctx->slock, flags);
510 set_bit(ST_M2M_PEND, &fimc->state);
511
512 ctx->state |= (FIMC_SRC_ADDR | FIMC_DST_ADDR);
513 ret = fimc_prepare_config(ctx, ctx->state);
514 if (ret) {
515 err("general configuration error");
516 goto dma_unlock;
517 }
518
519 if (fimc->m2m.ctx != ctx)
520 ctx->state |= FIMC_PARAMS;
521
522 fimc_hw_set_input_addr(fimc, &ctx->s_frame.paddr);
523
524 if (ctx->state & FIMC_PARAMS) {
525 fimc_hw_set_input_path(ctx);
526 fimc_hw_set_in_dma(ctx);
527 if (fimc_set_scaler_info(ctx)) {
528 err("scaler configuration error");
529 goto dma_unlock;
530 }
531 fimc_hw_set_prescaler(ctx);
532 fimc_hw_set_scaler(ctx);
533 fimc_hw_set_target_format(ctx);
534 fimc_hw_set_rotation(ctx);
535 fimc_hw_set_effect(ctx);
536 }
537
538 fimc_hw_set_output_path(ctx);
539 if (ctx->state & (FIMC_DST_ADDR | FIMC_PARAMS))
540 fimc_hw_set_output_addr(fimc, &ctx->d_frame.paddr);
541
542 if (ctx->state & FIMC_PARAMS)
543 fimc_hw_set_out_dma(ctx);
544
545 if (ctx->scaler.enabled)
546 fimc_hw_start_scaler(fimc);
547 fimc_hw_en_capture(ctx);
548
549 ctx->state = 0;
550 fimc_hw_start_in_dma(fimc);
551
552 fimc->m2m.ctx = ctx;
553
554dma_unlock:
555 spin_unlock_irqrestore(&ctx->slock, flags);
556}
557
558/* Nothing done in job_abort. */
559static void fimc_job_abort(void *priv) {}
560
561static void fimc_buf_release(struct videobuf_queue *vq,
562 struct videobuf_buffer *vb)
563{
564 videobuf_dma_contig_free(vq, vb);
565 vb->state = VIDEOBUF_NEEDS_INIT;
566}
567
568static int fimc_buf_setup(struct videobuf_queue *vq, unsigned int *count,
569 unsigned int *size)
570{
571 struct fimc_ctx *ctx = vq->priv_data;
572 struct fimc_frame *frame;
573
574 ctx_m2m_get_frame(frame, ctx, vq->type);
575
576 *size = (frame->width * frame->height * frame->fmt->depth) >> 3;
577 if (0 == *count)
578 *count = 1;
579 return 0;
580}
581
582static int fimc_buf_prepare(struct videobuf_queue *vq,
583 struct videobuf_buffer *vb, enum v4l2_field field)
584{
585 struct fimc_ctx *ctx = vq->priv_data;
586 struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
587 struct fimc_frame *frame;
588 int ret;
589
590 ctx_m2m_get_frame(frame, ctx, vq->type);
591
592 if (vb->baddr) {
593 if (vb->bsize < frame->size) {
594 v4l2_err(v4l2_dev,
595 "User-provided buffer too small (%d < %d)\n",
596 vb->bsize, frame->size);
597 WARN_ON(1);
598 return -EINVAL;
599 }
600 } else if (vb->state != VIDEOBUF_NEEDS_INIT
601 && vb->bsize < frame->size) {
602 return -EINVAL;
603 }
604
605 vb->width = frame->width;
606 vb->height = frame->height;
607 vb->bytesperline = (frame->width * frame->fmt->depth) >> 3;
608 vb->size = frame->size;
609 vb->field = field;
610
611 if (VIDEOBUF_NEEDS_INIT == vb->state) {
612 ret = videobuf_iolock(vq, vb, NULL);
613 if (ret) {
614 v4l2_err(v4l2_dev, "Iolock failed\n");
615 fimc_buf_release(vq, vb);
616 return ret;
617 }
618 }
619 vb->state = VIDEOBUF_PREPARED;
620
621 return 0;
622}
623
624static void fimc_buf_queue(struct videobuf_queue *vq,
625 struct videobuf_buffer *vb)
626{
627 struct fimc_ctx *ctx = vq->priv_data;
628 v4l2_m2m_buf_queue(ctx->m2m_ctx, vq, vb);
629}
630
631struct videobuf_queue_ops fimc_qops = {
632 .buf_setup = fimc_buf_setup,
633 .buf_prepare = fimc_buf_prepare,
634 .buf_queue = fimc_buf_queue,
635 .buf_release = fimc_buf_release,
636};
637
638static int fimc_m2m_querycap(struct file *file, void *priv,
639 struct v4l2_capability *cap)
640{
641 struct fimc_ctx *ctx = file->private_data;
642 struct fimc_dev *fimc = ctx->fimc_dev;
643
644 strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
645 strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
646 cap->bus_info[0] = 0;
647 cap->version = KERNEL_VERSION(1, 0, 0);
648 cap->capabilities = V4L2_CAP_STREAMING |
649 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT;
650
651 return 0;
652}
653
654static int fimc_m2m_enum_fmt(struct file *file, void *priv,
655 struct v4l2_fmtdesc *f)
656{
657 struct fimc_fmt *fmt;
658
659 if (f->index >= ARRAY_SIZE(fimc_formats))
660 return -EINVAL;
661
662 fmt = &fimc_formats[f->index];
663 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
664 f->pixelformat = fmt->fourcc;
665 return 0;
666}
667
668static int fimc_m2m_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
669{
670 struct fimc_ctx *ctx = priv;
671 struct fimc_frame *frame;
672
673 ctx_m2m_get_frame(frame, ctx, f->type);
674
675 f->fmt.pix.width = frame->width;
676 f->fmt.pix.height = frame->height;
677 f->fmt.pix.field = V4L2_FIELD_NONE;
678 f->fmt.pix.pixelformat = frame->fmt->fourcc;
679
680 return 0;
681}
682
683static struct fimc_fmt *find_format(struct v4l2_format *f)
684{
685 struct fimc_fmt *fmt;
686 unsigned int i;
687
688 for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
689 fmt = &fimc_formats[i];
690 if (fmt->fourcc == f->fmt.pix.pixelformat)
691 break;
692 }
693 if (i == ARRAY_SIZE(fimc_formats))
694 return NULL;
695
696 return fmt;
697}
698
699static int fimc_m2m_try_fmt(struct file *file, void *priv,
700 struct v4l2_format *f)
701{
702 struct fimc_fmt *fmt;
703 u32 max_width, max_height, mod_x, mod_y;
704 struct fimc_ctx *ctx = priv;
705 struct fimc_dev *fimc = ctx->fimc_dev;
706 struct v4l2_pix_format *pix = &f->fmt.pix;
707 struct samsung_fimc_variant *variant = fimc->variant;
708
709 fmt = find_format(f);
710 if (!fmt) {
711 v4l2_err(&fimc->m2m.v4l2_dev,
712 "Fourcc format (0x%X) invalid.\n", pix->pixelformat);
713 return -EINVAL;
714 }
715
716 if (pix->field == V4L2_FIELD_ANY)
717 pix->field = V4L2_FIELD_NONE;
718 else if (V4L2_FIELD_NONE != pix->field)
719 return -EINVAL;
720
721 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
722 max_width = variant->scaler_dis_w;
723 max_height = variant->scaler_dis_w;
724 mod_x = variant->min_inp_pixsize;
725 mod_y = variant->min_inp_pixsize;
726 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
727 max_width = variant->out_rot_dis_w;
728 max_height = variant->out_rot_dis_w;
729 mod_x = variant->min_out_pixsize;
730 mod_y = variant->min_out_pixsize;
731 } else {
732 err("Wrong stream type (%d)", f->type);
733 return -EINVAL;
734 }
735
736 dbg("max_w= %d, max_h= %d", max_width, max_height);
737
738 if (pix->height > max_height)
739 pix->height = max_height;
740 if (pix->width > max_width)
741 pix->width = max_width;
742
743 if (tiled_fmt(fmt)) {
744 mod_x = 64; /* 64x32 tile */
745 mod_y = 32;
746 }
747
748 dbg("mod_x= 0x%X, mod_y= 0x%X", mod_x, mod_y);
749
750 pix->width = (pix->width == 0) ? mod_x : ALIGN(pix->width, mod_x);
751 pix->height = (pix->height == 0) ? mod_y : ALIGN(pix->height, mod_y);
752
753 if (pix->bytesperline == 0 ||
754 pix->bytesperline * 8 / fmt->depth > pix->width)
755 pix->bytesperline = (pix->width * fmt->depth) >> 3;
756
757 if (pix->sizeimage == 0)
758 pix->sizeimage = pix->height * pix->bytesperline;
759
760 dbg("pix->bytesperline= %d, fmt->depth= %d",
761 pix->bytesperline, fmt->depth);
762
763 return 0;
764}
765
766
767static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
768{
769 struct fimc_ctx *ctx = priv;
770 struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
771 struct videobuf_queue *src_vq, *dst_vq;
772 struct fimc_frame *frame;
773 struct v4l2_pix_format *pix;
774 unsigned long flags;
775 int ret = 0;
776
777 BUG_ON(!ctx);
778
779 ret = fimc_m2m_try_fmt(file, priv, f);
780 if (ret)
781 return ret;
782
783 mutex_lock(&ctx->fimc_dev->lock);
784
785 src_vq = v4l2_m2m_get_src_vq(ctx->m2m_ctx);
786 dst_vq = v4l2_m2m_get_dst_vq(ctx->m2m_ctx);
787
788 mutex_lock(&src_vq->vb_lock);
789 mutex_lock(&dst_vq->vb_lock);
790
791 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
792 if (videobuf_queue_is_busy(src_vq)) {
793 v4l2_err(v4l2_dev, "%s queue busy\n", __func__);
794 ret = -EBUSY;
795 goto s_fmt_out;
796 }
797 frame = &ctx->s_frame;
798 spin_lock_irqsave(&ctx->slock, flags);
799 ctx->state |= FIMC_SRC_FMT;
800 spin_unlock_irqrestore(&ctx->slock, flags);
801
802 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
803 if (videobuf_queue_is_busy(dst_vq)) {
804 v4l2_err(v4l2_dev, "%s queue busy\n", __func__);
805 ret = -EBUSY;
806 goto s_fmt_out;
807 }
808 frame = &ctx->d_frame;
809 spin_lock_irqsave(&ctx->slock, flags);
810 ctx->state |= FIMC_DST_FMT;
811 spin_unlock_irqrestore(&ctx->slock, flags);
812 } else {
813 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
814 "Wrong buffer/video queue type (%d)\n", f->type);
815 return -EINVAL;
816 }
817
818 pix = &f->fmt.pix;
819 frame->fmt = find_format(f);
820 if (!frame->fmt) {
821 ret = -EINVAL;
822 goto s_fmt_out;
823 }
824
825 frame->f_width = pix->bytesperline * 8 / frame->fmt->depth;
826 frame->f_height = pix->sizeimage/pix->bytesperline;
827 frame->width = pix->width;
828 frame->height = pix->height;
829 frame->o_width = pix->width;
830 frame->o_height = pix->height;
831 frame->offs_h = 0;
832 frame->offs_v = 0;
833 frame->size = (pix->width * pix->height * frame->fmt->depth) >> 3;
834 src_vq->field = dst_vq->field = pix->field;
835 spin_lock_irqsave(&ctx->slock, flags);
836 ctx->state |= FIMC_PARAMS;
837 spin_unlock_irqrestore(&ctx->slock, flags);
838
839 dbg("f_width= %d, f_height= %d", frame->f_width, frame->f_height);
840
841s_fmt_out:
842 mutex_unlock(&dst_vq->vb_lock);
843 mutex_unlock(&src_vq->vb_lock);
844 mutex_unlock(&ctx->fimc_dev->lock);
845 return ret;
846}
847
848static int fimc_m2m_reqbufs(struct file *file, void *priv,
849 struct v4l2_requestbuffers *reqbufs)
850{
851 struct fimc_ctx *ctx = priv;
852 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
853}
854
855static int fimc_m2m_querybuf(struct file *file, void *priv,
856 struct v4l2_buffer *buf)
857{
858 struct fimc_ctx *ctx = priv;
859 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
860}
861
862static int fimc_m2m_qbuf(struct file *file, void *priv,
863 struct v4l2_buffer *buf)
864{
865 struct fimc_ctx *ctx = priv;
866
867 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
868}
869
870static int fimc_m2m_dqbuf(struct file *file, void *priv,
871 struct v4l2_buffer *buf)
872{
873 struct fimc_ctx *ctx = priv;
874 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
875}
876
877static int fimc_m2m_streamon(struct file *file, void *priv,
878 enum v4l2_buf_type type)
879{
880 struct fimc_ctx *ctx = priv;
881 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
882}
883
884static int fimc_m2m_streamoff(struct file *file, void *priv,
885 enum v4l2_buf_type type)
886{
887 struct fimc_ctx *ctx = priv;
888 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
889}
890
891int fimc_m2m_queryctrl(struct file *file, void *priv,
892 struct v4l2_queryctrl *qc)
893{
894 struct v4l2_queryctrl *c;
895 c = get_ctrl(qc->id);
896 if (!c)
897 return -EINVAL;
898 *qc = *c;
899 return 0;
900}
901
902int fimc_m2m_g_ctrl(struct file *file, void *priv,
903 struct v4l2_control *ctrl)
904{
905 struct fimc_ctx *ctx = priv;
906
907 switch (ctrl->id) {
908 case V4L2_CID_HFLIP:
909 ctrl->value = (FLIP_X_AXIS & ctx->flip) ? 1 : 0;
910 break;
911 case V4L2_CID_VFLIP:
912 ctrl->value = (FLIP_Y_AXIS & ctx->flip) ? 1 : 0;
913 break;
914 case V4L2_CID_ROTATE:
915 ctrl->value = ctx->rotation;
916 break;
917 default:
918 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, "Invalid control\n");
919 return -EINVAL;
920 }
921 dbg("ctrl->value= %d", ctrl->value);
922 return 0;
923}
924
925static int check_ctrl_val(struct fimc_ctx *ctx,
926 struct v4l2_control *ctrl)
927{
928 struct v4l2_queryctrl *c;
929 c = get_ctrl(ctrl->id);
930 if (!c)
931 return -EINVAL;
932
933 if (ctrl->value < c->minimum || ctrl->value > c->maximum
934 || (c->step != 0 && ctrl->value % c->step != 0)) {
935 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
936 "Invalid control value\n");
937 return -ERANGE;
938 }
939
940 return 0;
941}
942
943int fimc_m2m_s_ctrl(struct file *file, void *priv,
944 struct v4l2_control *ctrl)
945{
946 struct fimc_ctx *ctx = priv;
947 struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
948 unsigned long flags;
949 int ret = 0;
950
951 ret = check_ctrl_val(ctx, ctrl);
952 if (ret)
953 return ret;
954
955 switch (ctrl->id) {
956 case V4L2_CID_HFLIP:
957 if (ctx->rotation != 0)
958 return 0;
959 if (ctrl->value)
960 ctx->flip |= FLIP_X_AXIS;
961 else
962 ctx->flip &= ~FLIP_X_AXIS;
963 break;
964
965 case V4L2_CID_VFLIP:
966 if (ctx->rotation != 0)
967 return 0;
968 if (ctrl->value)
969 ctx->flip |= FLIP_Y_AXIS;
970 else
971 ctx->flip &= ~FLIP_Y_AXIS;
972 break;
973
974 case V4L2_CID_ROTATE:
975 if (ctrl->value == 90 || ctrl->value == 270) {
976 if (ctx->out_path == FIMC_LCDFIFO &&
977 !variant->has_inp_rot) {
978 return -EINVAL;
979 } else if (ctx->in_path == FIMC_DMA &&
980 !variant->has_out_rot) {
981 return -EINVAL;
982 }
983 }
984 ctx->rotation = ctrl->value;
985 if (ctrl->value == 180)
986 ctx->flip = FLIP_XY_AXIS;
987 break;
988
989 default:
990 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, "Invalid control\n");
991 return -EINVAL;
992 }
993 spin_lock_irqsave(&ctx->slock, flags);
994 ctx->state |= FIMC_PARAMS;
995 spin_unlock_irqrestore(&ctx->slock, flags);
996 return 0;
997}
998
999
1000static int fimc_m2m_cropcap(struct file *file, void *fh,
1001 struct v4l2_cropcap *cr)
1002{
1003 struct fimc_frame *frame;
1004 struct fimc_ctx *ctx = fh;
1005
1006 ctx_m2m_get_frame(frame, ctx, cr->type);
1007
1008 cr->bounds.left = 0;
1009 cr->bounds.top = 0;
1010 cr->bounds.width = frame->f_width;
1011 cr->bounds.height = frame->f_height;
1012 cr->defrect.left = frame->offs_h;
1013 cr->defrect.top = frame->offs_v;
1014 cr->defrect.width = frame->o_width;
1015 cr->defrect.height = frame->o_height;
1016 return 0;
1017}
1018
1019static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1020{
1021 struct fimc_frame *frame;
1022 struct fimc_ctx *ctx = file->private_data;
1023
1024 ctx_m2m_get_frame(frame, ctx, cr->type);
1025
1026 cr->c.left = frame->offs_h;
1027 cr->c.top = frame->offs_v;
1028 cr->c.width = frame->width;
1029 cr->c.height = frame->height;
1030
1031 return 0;
1032}
1033
1034static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1035{
1036 struct fimc_ctx *ctx = file->private_data;
1037 struct fimc_dev *fimc = ctx->fimc_dev;
1038 unsigned long flags;
1039 struct fimc_frame *f;
1040 u32 min_size;
1041 int ret = 0;
1042
1043 if (cr->c.top < 0 || cr->c.left < 0) {
1044 v4l2_err(&fimc->m2m.v4l2_dev,
1045 "doesn't support negative values for top & left\n");
1046 return -EINVAL;
1047 }
1048
1049 if (cr->c.width <= 0 || cr->c.height <= 0) {
1050 v4l2_err(&fimc->m2m.v4l2_dev,
1051 "crop width and height must be greater than 0\n");
1052 return -EINVAL;
1053 }
1054
1055 ctx_m2m_get_frame(f, ctx, cr->type);
1056
1057 /* Adjust to required pixel boundary. */
1058 min_size = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
1059 fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
1060
1061 cr->c.width = round_down(cr->c.width, min_size);
1062 cr->c.height = round_down(cr->c.height, min_size);
1063 cr->c.left = round_down(cr->c.left + 1, min_size);
1064 cr->c.top = round_down(cr->c.top + 1, min_size);
1065
1066 if ((cr->c.left + cr->c.width > f->o_width)
1067 || (cr->c.top + cr->c.height > f->o_height)) {
1068 v4l2_err(&fimc->m2m.v4l2_dev, "Error in S_CROP params\n");
1069 return -EINVAL;
1070 }
1071
1072 spin_lock_irqsave(&ctx->slock, flags);
1073 if ((ctx->state & FIMC_SRC_FMT) && (ctx->state & FIMC_DST_FMT)) {
1074 /* Check for the pixel scaling ratio when cropping input img. */
1075 if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1076 ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame);
1077 else if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1078 ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
1079
1080 if (ret) {
1081 spin_unlock_irqrestore(&ctx->slock, flags);
1082 v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
1083 return -EINVAL;
1084 }
1085 }
1086 ctx->state |= FIMC_PARAMS;
1087 spin_unlock_irqrestore(&ctx->slock, flags);
1088
1089 f->offs_h = cr->c.left;
1090 f->offs_v = cr->c.top;
1091 f->width = cr->c.width;
1092 f->height = cr->c.height;
1093 return 0;
1094}
1095
1096static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
1097 .vidioc_querycap = fimc_m2m_querycap,
1098
1099 .vidioc_enum_fmt_vid_cap = fimc_m2m_enum_fmt,
1100 .vidioc_enum_fmt_vid_out = fimc_m2m_enum_fmt,
1101
1102 .vidioc_g_fmt_vid_cap = fimc_m2m_g_fmt,
1103 .vidioc_g_fmt_vid_out = fimc_m2m_g_fmt,
1104
1105 .vidioc_try_fmt_vid_cap = fimc_m2m_try_fmt,
1106 .vidioc_try_fmt_vid_out = fimc_m2m_try_fmt,
1107
1108 .vidioc_s_fmt_vid_cap = fimc_m2m_s_fmt,
1109 .vidioc_s_fmt_vid_out = fimc_m2m_s_fmt,
1110
1111 .vidioc_reqbufs = fimc_m2m_reqbufs,
1112 .vidioc_querybuf = fimc_m2m_querybuf,
1113
1114 .vidioc_qbuf = fimc_m2m_qbuf,
1115 .vidioc_dqbuf = fimc_m2m_dqbuf,
1116
1117 .vidioc_streamon = fimc_m2m_streamon,
1118 .vidioc_streamoff = fimc_m2m_streamoff,
1119
1120 .vidioc_queryctrl = fimc_m2m_queryctrl,
1121 .vidioc_g_ctrl = fimc_m2m_g_ctrl,
1122 .vidioc_s_ctrl = fimc_m2m_s_ctrl,
1123
1124 .vidioc_g_crop = fimc_m2m_g_crop,
1125 .vidioc_s_crop = fimc_m2m_s_crop,
1126 .vidioc_cropcap = fimc_m2m_cropcap
1127
1128};
1129
1130static void queue_init(void *priv, struct videobuf_queue *vq,
1131 enum v4l2_buf_type type)
1132{
1133 struct fimc_ctx *ctx = priv;
1134 struct fimc_dev *fimc = ctx->fimc_dev;
1135
1136 videobuf_queue_dma_contig_init(vq, &fimc_qops,
1137 fimc->m2m.v4l2_dev.dev,
1138 &fimc->irqlock, type, V4L2_FIELD_NONE,
1139 sizeof(struct fimc_vid_buffer), priv);
1140}
1141
1142static int fimc_m2m_open(struct file *file)
1143{
1144 struct fimc_dev *fimc = video_drvdata(file);
1145 struct fimc_ctx *ctx = NULL;
1146 int err = 0;
1147
1148 mutex_lock(&fimc->lock);
1149 fimc->m2m.refcnt++;
1150 set_bit(ST_OUTDMA_RUN, &fimc->state);
1151 mutex_unlock(&fimc->lock);
1152
1153
1154 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
1155 if (!ctx)
1156 return -ENOMEM;
1157
1158 file->private_data = ctx;
1159 ctx->fimc_dev = fimc;
1160 /* default format */
1161 ctx->s_frame.fmt = &fimc_formats[0];
1162 ctx->d_frame.fmt = &fimc_formats[0];
1163 /* per user process device context initialization */
1164 ctx->state = 0;
1165 ctx->flags = 0;
1166 ctx->effect.type = S5P_FIMC_EFFECT_ORIGINAL;
1167 ctx->in_path = FIMC_DMA;
1168 ctx->out_path = FIMC_DMA;
1169 spin_lock_init(&ctx->slock);
1170
1171 ctx->m2m_ctx = v4l2_m2m_ctx_init(ctx, fimc->m2m.m2m_dev, queue_init);
1172 if (IS_ERR(ctx->m2m_ctx)) {
1173 err = PTR_ERR(ctx->m2m_ctx);
1174 kfree(ctx);
1175 }
1176 return err;
1177}
1178
1179static int fimc_m2m_release(struct file *file)
1180{
1181 struct fimc_ctx *ctx = file->private_data;
1182 struct fimc_dev *fimc = ctx->fimc_dev;
1183
1184 v4l2_m2m_ctx_release(ctx->m2m_ctx);
1185 kfree(ctx);
1186 mutex_lock(&fimc->lock);
1187 if (--fimc->m2m.refcnt <= 0)
1188 clear_bit(ST_OUTDMA_RUN, &fimc->state);
1189 mutex_unlock(&fimc->lock);
1190 return 0;
1191}
1192
1193static unsigned int fimc_m2m_poll(struct file *file,
1194 struct poll_table_struct *wait)
1195{
1196 struct fimc_ctx *ctx = file->private_data;
1197 return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
1198}
1199
1200
1201static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
1202{
1203 struct fimc_ctx *ctx = file->private_data;
1204 return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
1205}
1206
1207static const struct v4l2_file_operations fimc_m2m_fops = {
1208 .owner = THIS_MODULE,
1209 .open = fimc_m2m_open,
1210 .release = fimc_m2m_release,
1211 .poll = fimc_m2m_poll,
1212 .ioctl = video_ioctl2,
1213 .mmap = fimc_m2m_mmap,
1214};
1215
1216static struct v4l2_m2m_ops m2m_ops = {
1217 .device_run = fimc_dma_run,
1218 .job_abort = fimc_job_abort,
1219};
1220
1221
1222static int fimc_register_m2m_device(struct fimc_dev *fimc)
1223{
1224 struct video_device *vfd;
1225 struct platform_device *pdev;
1226 struct v4l2_device *v4l2_dev;
1227 int ret = 0;
1228
1229 if (!fimc)
1230 return -ENODEV;
1231
1232 pdev = fimc->pdev;
1233 v4l2_dev = &fimc->m2m.v4l2_dev;
1234
1235 /* set name if it is empty */
1236 if (!v4l2_dev->name[0])
1237 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
1238 "%s.m2m", dev_name(&pdev->dev));
1239
1240 ret = v4l2_device_register(&pdev->dev, v4l2_dev);
1241 if (ret)
1242 return ret;;
1243
1244 vfd = video_device_alloc();
1245 if (!vfd) {
1246 v4l2_err(v4l2_dev, "Failed to allocate video device\n");
1247 goto err_m2m_r1;
1248 }
1249
1250 vfd->fops = &fimc_m2m_fops;
1251 vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
1252 vfd->minor = -1;
1253 vfd->release = video_device_release;
1254
1255 snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
1256
1257 video_set_drvdata(vfd, fimc);
1258 platform_set_drvdata(pdev, fimc);
1259
1260 fimc->m2m.vfd = vfd;
1261 fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
1262 if (IS_ERR(fimc->m2m.m2m_dev)) {
1263 v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
1264 ret = PTR_ERR(fimc->m2m.m2m_dev);
1265 goto err_m2m_r2;
1266 }
1267
1268 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1269 if (ret) {
1270 v4l2_err(v4l2_dev,
1271 "%s(): failed to register video device\n", __func__);
1272 goto err_m2m_r3;
1273 }
1274 v4l2_info(v4l2_dev,
1275 "FIMC m2m driver registered as /dev/video%d\n", vfd->num);
1276
1277 return 0;
1278
1279err_m2m_r3:
1280 v4l2_m2m_release(fimc->m2m.m2m_dev);
1281err_m2m_r2:
1282 video_device_release(fimc->m2m.vfd);
1283err_m2m_r1:
1284 v4l2_device_unregister(v4l2_dev);
1285
1286 return ret;
1287}
1288
1289static void fimc_unregister_m2m_device(struct fimc_dev *fimc)
1290{
1291 if (fimc) {
1292 v4l2_m2m_release(fimc->m2m.m2m_dev);
1293 video_unregister_device(fimc->m2m.vfd);
1294 video_device_release(fimc->m2m.vfd);
1295 v4l2_device_unregister(&fimc->m2m.v4l2_dev);
1296 }
1297}
1298
1299static void fimc_clk_release(struct fimc_dev *fimc)
1300{
1301 int i;
1302 for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
1303 if (fimc->clock[i]) {
1304 clk_disable(fimc->clock[i]);
1305 clk_put(fimc->clock[i]);
1306 }
1307 }
1308}
1309
1310static int fimc_clk_get(struct fimc_dev *fimc)
1311{
1312 int i;
1313 for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
1314 fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clock_name[i]);
1315 if (IS_ERR(fimc->clock[i])) {
1316 dev_err(&fimc->pdev->dev,
1317 "failed to get fimc clock: %s\n",
1318 fimc_clock_name[i]);
1319 return -ENXIO;
1320 }
1321 clk_enable(fimc->clock[i]);
1322 }
1323 return 0;
1324}
1325
1326static int fimc_probe(struct platform_device *pdev)
1327{
1328 struct fimc_dev *fimc;
1329 struct resource *res;
1330 struct samsung_fimc_driverdata *drv_data;
1331 int ret = 0;
1332
1333 dev_dbg(&pdev->dev, "%s():\n", __func__);
1334
1335 drv_data = (struct samsung_fimc_driverdata *)
1336 platform_get_device_id(pdev)->driver_data;
1337
1338 if (pdev->id >= drv_data->devs_cnt) {
1339 dev_err(&pdev->dev, "Invalid platform device id: %d\n",
1340 pdev->id);
1341 return -EINVAL;
1342 }
1343
1344 fimc = kzalloc(sizeof(struct fimc_dev), GFP_KERNEL);
1345 if (!fimc)
1346 return -ENOMEM;
1347
1348 fimc->id = pdev->id;
1349 fimc->variant = drv_data->variant[fimc->id];
1350 fimc->pdev = pdev;
1351 fimc->state = ST_IDLE;
1352
1353 spin_lock_init(&fimc->irqlock);
1354 spin_lock_init(&fimc->slock);
1355
1356 mutex_init(&fimc->lock);
1357
1358 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1359 if (!res) {
1360 dev_err(&pdev->dev, "failed to find the registers\n");
1361 ret = -ENOENT;
1362 goto err_info;
1363 }
1364
1365 fimc->regs_res = request_mem_region(res->start, resource_size(res),
1366 dev_name(&pdev->dev));
1367 if (!fimc->regs_res) {
1368 dev_err(&pdev->dev, "failed to obtain register region\n");
1369 ret = -ENOENT;
1370 goto err_info;
1371 }
1372
1373 fimc->regs = ioremap(res->start, resource_size(res));
1374 if (!fimc->regs) {
1375 dev_err(&pdev->dev, "failed to map registers\n");
1376 ret = -ENXIO;
1377 goto err_req_region;
1378 }
1379
1380 ret = fimc_clk_get(fimc);
1381 if (ret)
1382 goto err_regs_unmap;
1383
1384 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1385 if (!res) {
1386 dev_err(&pdev->dev, "failed to get IRQ resource\n");
1387 ret = -ENXIO;
1388 goto err_clk;
1389 }
1390 fimc->irq = res->start;
1391
1392 fimc_hw_reset(fimc);
1393
1394 ret = request_irq(fimc->irq, fimc_isr, 0, pdev->name, fimc);
1395 if (ret) {
1396 dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
1397 goto err_clk;
1398 }
1399
1400 fimc->work_queue = create_workqueue(dev_name(&fimc->pdev->dev));
1401 if (!fimc->work_queue)
1402 goto err_irq;
1403
1404 ret = fimc_register_m2m_device(fimc);
1405 if (ret)
1406 goto err_wq;
1407
1408 fimc_hw_en_lastirq(fimc, true);
1409
1410 dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n",
1411 __func__, fimc->id);
1412
1413 return 0;
1414
1415err_wq:
1416 destroy_workqueue(fimc->work_queue);
1417err_irq:
1418 free_irq(fimc->irq, fimc);
1419err_clk:
1420 fimc_clk_release(fimc);
1421err_regs_unmap:
1422 iounmap(fimc->regs);
1423err_req_region:
1424 release_resource(fimc->regs_res);
1425 kfree(fimc->regs_res);
1426err_info:
1427 kfree(fimc);
1428 dev_err(&pdev->dev, "failed to install\n");
1429 return ret;
1430}
1431
1432static int __devexit fimc_remove(struct platform_device *pdev)
1433{
1434 struct fimc_dev *fimc =
1435 (struct fimc_dev *)platform_get_drvdata(pdev);
1436
1437 v4l2_info(&fimc->m2m.v4l2_dev, "Removing %s\n", pdev->name);
1438
1439 free_irq(fimc->irq, fimc);
1440
1441 fimc_hw_reset(fimc);
1442
1443 fimc_unregister_m2m_device(fimc);
1444 fimc_clk_release(fimc);
1445 iounmap(fimc->regs);
1446 release_resource(fimc->regs_res);
1447 kfree(fimc->regs_res);
1448 kfree(fimc);
1449 return 0;
1450}
1451
1452static struct samsung_fimc_variant fimc01_variant_s5p = {
1453 .has_inp_rot = 1,
1454 .has_out_rot = 1,
1455 .min_inp_pixsize = 16,
1456 .min_out_pixsize = 16,
1457
1458 .scaler_en_w = 3264,
1459 .scaler_dis_w = 8192,
1460 .in_rot_en_h = 1920,
1461 .in_rot_dis_w = 8192,
1462 .out_rot_en_w = 1920,
1463 .out_rot_dis_w = 4224,
1464};
1465
1466static struct samsung_fimc_variant fimc2_variant_s5p = {
1467 .min_inp_pixsize = 16,
1468 .min_out_pixsize = 16,
1469
1470 .scaler_en_w = 4224,
1471 .scaler_dis_w = 8192,
1472 .in_rot_en_h = 1920,
1473 .in_rot_dis_w = 8192,
1474 .out_rot_en_w = 1920,
1475 .out_rot_dis_w = 4224,
1476};
1477
1478static struct samsung_fimc_variant fimc01_variant_s5pv210 = {
1479 .has_inp_rot = 1,
1480 .has_out_rot = 1,
1481 .min_inp_pixsize = 16,
1482 .min_out_pixsize = 32,
1483
1484 .scaler_en_w = 4224,
1485 .scaler_dis_w = 8192,
1486 .in_rot_en_h = 1920,
1487 .in_rot_dis_w = 8192,
1488 .out_rot_en_w = 1920,
1489 .out_rot_dis_w = 4224,
1490};
1491
1492static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
1493 .min_inp_pixsize = 16,
1494 .min_out_pixsize = 32,
1495
1496 .scaler_en_w = 1920,
1497 .scaler_dis_w = 8192,
1498 .in_rot_en_h = 1280,
1499 .in_rot_dis_w = 8192,
1500 .out_rot_en_w = 1280,
1501 .out_rot_dis_w = 1920,
1502};
1503
1504static struct samsung_fimc_driverdata fimc_drvdata_s5p = {
1505 .variant = {
1506 [0] = &fimc01_variant_s5p,
1507 [1] = &fimc01_variant_s5p,
1508 [2] = &fimc2_variant_s5p,
1509 },
1510 .devs_cnt = 3
1511};
1512
1513static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = {
1514 .variant = {
1515 [0] = &fimc01_variant_s5pv210,
1516 [1] = &fimc01_variant_s5pv210,
1517 [2] = &fimc2_variant_s5pv210,
1518 },
1519 .devs_cnt = 3
1520};
1521
1522static struct platform_device_id fimc_driver_ids[] = {
1523 {
1524 .name = "s5p-fimc",
1525 .driver_data = (unsigned long)&fimc_drvdata_s5p,
1526 }, {
1527 .name = "s5pv210-fimc",
1528 .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
1529 },
1530 {},
1531};
1532MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
1533
1534static struct platform_driver fimc_driver = {
1535 .probe = fimc_probe,
1536 .remove = __devexit_p(fimc_remove),
1537 .id_table = fimc_driver_ids,
1538 .driver = {
1539 .name = MODULE_NAME,
1540 .owner = THIS_MODULE,
1541 }
1542};
1543
1544static char banner[] __initdata = KERN_INFO
1545 "S5PC Camera Interface V4L2 Driver, (c) 2010 Samsung Electronics\n";
1546
1547static int __init fimc_init(void)
1548{
1549 u32 ret;
1550 printk(banner);
1551
1552 ret = platform_driver_register(&fimc_driver);
1553 if (ret) {
1554 printk(KERN_ERR "FIMC platform driver register failed\n");
1555 return -1;
1556 }
1557 return 0;
1558}
1559
1560static void __exit fimc_exit(void)
1561{
1562 platform_driver_unregister(&fimc_driver);
1563}
1564
1565module_init(fimc_init);
1566module_exit(fimc_exit);
1567
1568MODULE_AUTHOR("Sylwester Nawrocki, s.nawrocki@samsung.com");
1569MODULE_DESCRIPTION("S3C/S5P FIMC (video postprocessor) driver");
1570MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/s5p-fimc/fimc-core.h b/drivers/media/video/s5p-fimc/fimc-core.h
new file mode 100644
index 000000000000..f121b939626a
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/fimc-core.h
@@ -0,0 +1,465 @@
1/*
2 * Copyright (c) 2010 Samsung Electronics
3 *
4 * Sylwester Nawrocki, <s.nawrocki@samsung.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef FIMC_CORE_H_
12#define FIMC_CORE_H_
13
14#include <linux/types.h>
15#include <media/videobuf-core.h>
16#include <media/v4l2-device.h>
17#include <media/v4l2-mem2mem.h>
18#include <linux/videodev2.h>
19#include "regs-fimc.h"
20
21#define err(fmt, args...) \
22 printk(KERN_ERR "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
23
24#ifdef DEBUG
25#define dbg(fmt, args...) \
26 printk(KERN_DEBUG "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
27#else
28#define dbg(fmt, args...)
29#endif
30
31#define ctx_m2m_get_frame(frame, ctx, type) do { \
32 if (V4L2_BUF_TYPE_VIDEO_OUTPUT == (type)) { \
33 frame = &(ctx)->s_frame; \
34 } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE == (type)) { \
35 frame = &(ctx)->d_frame; \
36 } else { \
37 v4l2_err(&(ctx)->fimc_dev->m2m.v4l2_dev,\
38 "Wrong buffer/video queue type (%d)\n", type); \
39 return -EINVAL; \
40 } \
41} while (0)
42
43#define NUM_FIMC_CLOCKS 2
44#define MODULE_NAME "s5p-fimc"
45#define FIMC_MAX_DEVS 3
46#define FIMC_MAX_OUT_BUFS 4
47#define SCALER_MAX_HRATIO 64
48#define SCALER_MAX_VRATIO 64
49
50enum {
51 ST_IDLE,
52 ST_OUTDMA_RUN,
53 ST_M2M_PEND,
54};
55
56#define fimc_m2m_active(dev) test_bit(ST_OUTDMA_RUN, &(dev)->state)
57#define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
58
59enum fimc_datapath {
60 FIMC_ITU_CAM_A,
61 FIMC_ITU_CAM_B,
62 FIMC_MIPI_CAM,
63 FIMC_DMA,
64 FIMC_LCDFIFO,
65 FIMC_WRITEBACK
66};
67
68enum fimc_color_fmt {
69 S5P_FIMC_RGB565,
70 S5P_FIMC_RGB666,
71 S5P_FIMC_RGB888,
72 S5P_FIMC_YCBCR420,
73 S5P_FIMC_YCBCR422,
74 S5P_FIMC_YCBYCR422,
75 S5P_FIMC_YCRYCB422,
76 S5P_FIMC_CBYCRY422,
77 S5P_FIMC_CRYCBY422,
78 S5P_FIMC_RGB30_LOCAL,
79 S5P_FIMC_YCBCR444_LOCAL,
80 S5P_FIMC_MAX_COLOR = S5P_FIMC_YCBCR444_LOCAL,
81 S5P_FIMC_COLOR_MASK = 0x0F,
82};
83
84/* Y/Cb/Cr components order at DMA output for 1 plane YCbCr 4:2:2 formats. */
85#define S5P_FIMC_OUT_CRYCBY S5P_CIOCTRL_ORDER422_CRYCBY
86#define S5P_FIMC_OUT_CBYCRY S5P_CIOCTRL_ORDER422_YCRYCB
87#define S5P_FIMC_OUT_YCRYCB S5P_CIOCTRL_ORDER422_CBYCRY
88#define S5P_FIMC_OUT_YCBYCR S5P_CIOCTRL_ORDER422_YCBYCR
89
90/* Input Y/Cb/Cr components order for 1 plane YCbCr 4:2:2 color formats. */
91#define S5P_FIMC_IN_CRYCBY S5P_MSCTRL_ORDER422_CRYCBY
92#define S5P_FIMC_IN_CBYCRY S5P_MSCTRL_ORDER422_YCRYCB
93#define S5P_FIMC_IN_YCRYCB S5P_MSCTRL_ORDER422_CBYCRY
94#define S5P_FIMC_IN_YCBYCR S5P_MSCTRL_ORDER422_YCBYCR
95
96/* Cb/Cr chrominance components order for 2 plane Y/CbCr 4:2:2 formats. */
97#define S5P_FIMC_LSB_CRCB S5P_CIOCTRL_ORDER422_2P_LSB_CRCB
98
99/* The embedded image effect selection */
100#define S5P_FIMC_EFFECT_ORIGINAL S5P_CIIMGEFF_FIN_BYPASS
101#define S5P_FIMC_EFFECT_ARBITRARY S5P_CIIMGEFF_FIN_ARBITRARY
102#define S5P_FIMC_EFFECT_NEGATIVE S5P_CIIMGEFF_FIN_NEGATIVE
103#define S5P_FIMC_EFFECT_ARTFREEZE S5P_CIIMGEFF_FIN_ARTFREEZE
104#define S5P_FIMC_EFFECT_EMBOSSING S5P_CIIMGEFF_FIN_EMBOSSING
105#define S5P_FIMC_EFFECT_SIKHOUETTE S5P_CIIMGEFF_FIN_SILHOUETTE
106
107/* The hardware context state. */
108#define FIMC_PARAMS (1 << 0)
109#define FIMC_SRC_ADDR (1 << 1)
110#define FIMC_DST_ADDR (1 << 2)
111#define FIMC_SRC_FMT (1 << 3)
112#define FIMC_DST_FMT (1 << 4)
113
114/* Image conversion flags */
115#define FIMC_IN_DMA_ACCESS_TILED (1 << 0)
116#define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0)
117#define FIMC_OUT_DMA_ACCESS_TILED (1 << 1)
118#define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1)
119#define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2)
120#define FIMC_SCAN_MODE_INTERLACED (1 << 2)
121/* YCbCr data dynamic range for RGB-YUV color conversion. Y/Cb/Cr: (0 ~ 255) */
122#define FIMC_COLOR_RANGE_WIDE (0 << 3)
123/* Y (16 ~ 235), Cb/Cr (16 ~ 240) */
124#define FIMC_COLOR_RANGE_NARROW (1 << 3)
125
126#define FLIP_NONE 0
127#define FLIP_X_AXIS 1
128#define FLIP_Y_AXIS 2
129#define FLIP_XY_AXIS (FLIP_X_AXIS | FLIP_Y_AXIS)
130
131/**
132 * struct fimc_fmt - the driver's internal color format data
133 * @name: format description
134 * @fourcc: the fourcc code for this format
135 * @color: the corresponding fimc_color_fmt
136 * @depth: number of bits per pixel
137 * @buff_cnt: number of physically non-contiguous data planes
138 * @planes_cnt: number of physically contiguous data planes
139 */
140struct fimc_fmt {
141 char *name;
142 u32 fourcc;
143 u32 color;
144 u32 depth;
145 u16 buff_cnt;
146 u16 planes_cnt;
147};
148
149/**
150 * struct fimc_dma_offset - pixel offset information for DMA
151 * @y_h: y value horizontal offset
152 * @y_v: y value vertical offset
153 * @cb_h: cb value horizontal offset
154 * @cb_v: cb value vertical offset
155 * @cr_h: cr value horizontal offset
156 * @cr_v: cr value vertical offset
157 */
158struct fimc_dma_offset {
159 int y_h;
160 int y_v;
161 int cb_h;
162 int cb_v;
163 int cr_h;
164 int cr_v;
165};
166
167/**
168 * struct fimc_effect - the configuration data for the "Arbitrary" image effect
169 * @type: effect type
170 * @pat_cb: cr value when type is "arbitrary"
171 * @pat_cr: cr value when type is "arbitrary"
172 */
173struct fimc_effect {
174 u32 type;
175 u8 pat_cb;
176 u8 pat_cr;
177};
178
179/**
180 * struct fimc_scaler - the configuration data for FIMC inetrnal scaler
181 *
182 * @enabled: the flag set when the scaler is used
183 * @hfactor: horizontal shift factor
184 * @vfactor: vertical shift factor
185 * @pre_hratio: horizontal ratio of the prescaler
186 * @pre_vratio: vertical ratio of the prescaler
187 * @pre_dst_width: the prescaler's destination width
188 * @pre_dst_height: the prescaler's destination height
189 * @scaleup_h: flag indicating scaling up horizontally
190 * @scaleup_v: flag indicating scaling up vertically
191 * @main_hratio: the main scaler's horizontal ratio
192 * @main_vratio: the main scaler's vertical ratio
193 * @real_width: source width - offset
194 * @real_height: source height - offset
195 * @copy_mode: flag set if one-to-one mode is used, i.e. no scaling
196 * and color format conversion
197 */
198struct fimc_scaler {
199 u32 enabled;
200 u32 hfactor;
201 u32 vfactor;
202 u32 pre_hratio;
203 u32 pre_vratio;
204 u32 pre_dst_width;
205 u32 pre_dst_height;
206 u32 scaleup_h;
207 u32 scaleup_v;
208 u32 main_hratio;
209 u32 main_vratio;
210 u32 real_width;
211 u32 real_height;
212 u32 copy_mode;
213};
214
215/**
216 * struct fimc_addr - the FIMC physical address set for DMA
217 *
218 * @y: luminance plane physical address
219 * @cb: Cb plane physical address
220 * @cr: Cr plane physical address
221 */
222struct fimc_addr {
223 u32 y;
224 u32 cb;
225 u32 cr;
226};
227
228/**
229 * struct fimc_vid_buffer - the driver's video buffer
230 * @vb: v4l videobuf buffer
231 */
232struct fimc_vid_buffer {
233 struct videobuf_buffer vb;
234};
235
236/**
237 * struct fimc_frame - input/output frame format properties
238 *
239 * @f_width: image full width (virtual screen size)
240 * @f_height: image full height (virtual screen size)
241 * @o_width: original image width as set by S_FMT
242 * @o_height: original image height as set by S_FMT
243 * @offs_h: image horizontal pixel offset
244 * @offs_v: image vertical pixel offset
245 * @width: image pixel width
246 * @height: image pixel weight
247 * @paddr: image frame buffer physical addresses
248 * @buf_cnt: number of buffers depending on a color format
249 * @size: image size in bytes
250 * @color: color format
251 * @dma_offset: DMA offset in bytes
252 */
253struct fimc_frame {
254 u32 f_width;
255 u32 f_height;
256 u32 o_width;
257 u32 o_height;
258 u32 offs_h;
259 u32 offs_v;
260 u32 width;
261 u32 height;
262 u32 size;
263 struct fimc_addr paddr;
264 struct fimc_dma_offset dma_offset;
265 struct fimc_fmt *fmt;
266};
267
268/**
269 * struct fimc_m2m_device - v4l2 memory-to-memory device data
270 * @vfd: the video device node for v4l2 m2m mode
271 * @v4l2_dev: v4l2 device for m2m mode
272 * @m2m_dev: v4l2 memory-to-memory device data
273 * @ctx: hardware context data
274 * @refcnt: the reference counter
275 */
276struct fimc_m2m_device {
277 struct video_device *vfd;
278 struct v4l2_device v4l2_dev;
279 struct v4l2_m2m_dev *m2m_dev;
280 struct fimc_ctx *ctx;
281 int refcnt;
282};
283
284/**
285 * struct samsung_fimc_variant - camera interface variant information
286 *
287 * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
288 * @has_inp_rot: set if has input rotator
289 * @has_out_rot: set if has output rotator
290 * @min_inp_pixsize: minimum input pixel size
291 * @min_out_pixsize: minimum output pixel size
292 * @scaler_en_w: maximum input pixel width when the scaler is enabled
293 * @scaler_dis_w: maximum input pixel width when the scaler is disabled
294 * @in_rot_en_h: maximum input width when the input rotator is used
295 * @in_rot_dis_w: maximum input width when the input rotator is used
296 * @out_rot_en_w: maximum output width for the output rotator enabled
297 * @out_rot_dis_w: maximum output width for the output rotator enabled
298 */
299struct samsung_fimc_variant {
300 unsigned int pix_hoff:1;
301 unsigned int has_inp_rot:1;
302 unsigned int has_out_rot:1;
303
304 u16 min_inp_pixsize;
305 u16 min_out_pixsize;
306 u16 scaler_en_w;
307 u16 scaler_dis_w;
308 u16 in_rot_en_h;
309 u16 in_rot_dis_w;
310 u16 out_rot_en_w;
311 u16 out_rot_dis_w;
312};
313
314/**
315 * struct samsung_fimc_driverdata - per-device type driver data for init time.
316 *
317 * @variant: the variant information for this driver.
318 * @dev_cnt: number of fimc sub-devices available in SoC
319 */
320struct samsung_fimc_driverdata {
321 struct samsung_fimc_variant *variant[FIMC_MAX_DEVS];
322 int devs_cnt;
323};
324
325struct fimc_ctx;
326
327/**
328 * struct fimc_subdev - abstraction for a FIMC entity
329 *
330 * @slock: the spinlock protecting this data structure
331 * @lock: the mutex protecting this data structure
332 * @pdev: pointer to the FIMC platform device
333 * @id: FIMC device index (0..2)
334 * @clock[]: the clocks required for FIMC operation
335 * @regs: the mapped hardware registers
336 * @regs_res: the resource claimed for IO registers
337 * @irq: interrupt number of the FIMC subdevice
338 * @irqlock: spinlock protecting videbuffer queue
339 * @m2m: memory-to-memory V4L2 device information
340 * @state: the FIMC device state flags
341 */
342struct fimc_dev {
343 spinlock_t slock;
344 struct mutex lock;
345 struct platform_device *pdev;
346 struct samsung_fimc_variant *variant;
347 int id;
348 struct clk *clock[NUM_FIMC_CLOCKS];
349 void __iomem *regs;
350 struct resource *regs_res;
351 int irq;
352 spinlock_t irqlock;
353 struct workqueue_struct *work_queue;
354 struct fimc_m2m_device m2m;
355 unsigned long state;
356};
357
358/**
359 * fimc_ctx - the device context data
360 *
361 * @lock: mutex protecting this data structure
362 * @s_frame: source frame properties
363 * @d_frame: destination frame properties
364 * @out_order_1p: output 1-plane YCBCR order
365 * @out_order_2p: output 2-plane YCBCR order
366 * @in_order_1p input 1-plane YCBCR order
367 * @in_order_2p: input 2-plane YCBCR order
368 * @in_path: input mode (DMA or camera)
369 * @out_path: output mode (DMA or FIFO)
370 * @scaler: image scaler properties
371 * @effect: image effect
372 * @rotation: image clockwise rotation in degrees
373 * @flip: image flip mode
374 * @flags: an additional flags for image conversion
375 * @state: flags to keep track of user configuration
376 * @fimc_dev: the FIMC device this context applies to
377 * @m2m_ctx: memory-to-memory device context
378 */
379struct fimc_ctx {
380 spinlock_t slock;
381 struct fimc_frame s_frame;
382 struct fimc_frame d_frame;
383 u32 out_order_1p;
384 u32 out_order_2p;
385 u32 in_order_1p;
386 u32 in_order_2p;
387 enum fimc_datapath in_path;
388 enum fimc_datapath out_path;
389 struct fimc_scaler scaler;
390 struct fimc_effect effect;
391 int rotation;
392 u32 flip;
393 u32 flags;
394 u32 state;
395 struct fimc_dev *fimc_dev;
396 struct v4l2_m2m_ctx *m2m_ctx;
397};
398
399
400static inline int tiled_fmt(struct fimc_fmt *fmt)
401{
402 return 0;
403}
404
405static inline void fimc_hw_clear_irq(struct fimc_dev *dev)
406{
407 u32 cfg = readl(dev->regs + S5P_CIGCTRL);
408 cfg |= S5P_CIGCTRL_IRQ_CLR;
409 writel(cfg, dev->regs + S5P_CIGCTRL);
410}
411
412static inline void fimc_hw_start_scaler(struct fimc_dev *dev)
413{
414 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
415 cfg |= S5P_CISCCTRL_SCALERSTART;
416 writel(cfg, dev->regs + S5P_CISCCTRL);
417}
418
419static inline void fimc_hw_stop_scaler(struct fimc_dev *dev)
420{
421 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
422 cfg &= ~S5P_CISCCTRL_SCALERSTART;
423 writel(cfg, dev->regs + S5P_CISCCTRL);
424}
425
426static inline void fimc_hw_dis_capture(struct fimc_dev *dev)
427{
428 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
429 cfg &= ~(S5P_CIIMGCPT_IMGCPTEN | S5P_CIIMGCPT_IMGCPTEN_SC);
430 writel(cfg, dev->regs + S5P_CIIMGCPT);
431}
432
433static inline void fimc_hw_start_in_dma(struct fimc_dev *dev)
434{
435 u32 cfg = readl(dev->regs + S5P_MSCTRL);
436 cfg |= S5P_MSCTRL_ENVID;
437 writel(cfg, dev->regs + S5P_MSCTRL);
438}
439
440static inline void fimc_hw_stop_in_dma(struct fimc_dev *dev)
441{
442 u32 cfg = readl(dev->regs + S5P_MSCTRL);
443 cfg &= ~S5P_MSCTRL_ENVID;
444 writel(cfg, dev->regs + S5P_MSCTRL);
445}
446
447/* -----------------------------------------------------*/
448/* fimc-reg.c */
449void fimc_hw_reset(struct fimc_dev *dev);
450void fimc_hw_set_rotation(struct fimc_ctx *ctx);
451void fimc_hw_set_target_format(struct fimc_ctx *ctx);
452void fimc_hw_set_out_dma(struct fimc_ctx *ctx);
453void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable);
454void fimc_hw_en_irq(struct fimc_dev *dev, int enable);
455void fimc_hw_set_prescaler(struct fimc_ctx *ctx);
456void fimc_hw_set_scaler(struct fimc_ctx *ctx);
457void fimc_hw_en_capture(struct fimc_ctx *ctx);
458void fimc_hw_set_effect(struct fimc_ctx *ctx);
459void fimc_hw_set_in_dma(struct fimc_ctx *ctx);
460void fimc_hw_set_input_path(struct fimc_ctx *ctx);
461void fimc_hw_set_output_path(struct fimc_ctx *ctx);
462void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr);
463void fimc_hw_set_output_addr(struct fimc_dev *dev, struct fimc_addr *paddr);
464
465#endif /* FIMC_CORE_H_ */
diff --git a/drivers/media/video/s5p-fimc/fimc-reg.c b/drivers/media/video/s5p-fimc/fimc-reg.c
new file mode 100644
index 000000000000..5570f1ce0c9c
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/fimc-reg.c
@@ -0,0 +1,527 @@
1/*
2 * Register interface file for Samsung Camera Interface (FIMC) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics
5 *
6 * Sylwester Nawrocki, s.nawrocki@samsung.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11*/
12
13#include <linux/io.h>
14#include <linux/delay.h>
15#include <mach/map.h>
16
17#include "fimc-core.h"
18
19
20void fimc_hw_reset(struct fimc_dev *dev)
21{
22 u32 cfg;
23
24 cfg = readl(dev->regs + S5P_CISRCFMT);
25 cfg |= S5P_CISRCFMT_ITU601_8BIT;
26 writel(cfg, dev->regs + S5P_CISRCFMT);
27
28 /* Software reset. */
29 cfg = readl(dev->regs + S5P_CIGCTRL);
30 cfg |= (S5P_CIGCTRL_SWRST | S5P_CIGCTRL_IRQ_LEVEL);
31 writel(cfg, dev->regs + S5P_CIGCTRL);
32 msleep(1);
33
34 cfg = readl(dev->regs + S5P_CIGCTRL);
35 cfg &= ~S5P_CIGCTRL_SWRST;
36 writel(cfg, dev->regs + S5P_CIGCTRL);
37
38}
39
40void fimc_hw_set_rotation(struct fimc_ctx *ctx)
41{
42 u32 cfg, flip;
43 struct fimc_dev *dev = ctx->fimc_dev;
44
45 cfg = readl(dev->regs + S5P_CITRGFMT);
46 cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90);
47
48 flip = readl(dev->regs + S5P_MSCTRL);
49 flip &= ~S5P_MSCTRL_FLIP_MASK;
50
51 /*
52 * The input and output rotator cannot work simultaneously.
53 * Use the output rotator in output DMA mode or the input rotator
54 * in direct fifo output mode.
55 */
56 if (ctx->rotation == 90 || ctx->rotation == 270) {
57 if (ctx->out_path == FIMC_LCDFIFO) {
58 cfg |= S5P_CITRGFMT_INROT90;
59 if (ctx->rotation == 270)
60 flip |= S5P_MSCTRL_FLIP_180;
61 } else {
62 cfg |= S5P_CITRGFMT_OUTROT90;
63 if (ctx->rotation == 270)
64 cfg |= S5P_CITRGFMT_FLIP_180;
65 }
66 } else if (ctx->rotation == 180) {
67 if (ctx->out_path == FIMC_LCDFIFO)
68 flip |= S5P_MSCTRL_FLIP_180;
69 else
70 cfg |= S5P_CITRGFMT_FLIP_180;
71 }
72 if (ctx->rotation == 180 || ctx->rotation == 270)
73 writel(flip, dev->regs + S5P_MSCTRL);
74 writel(cfg, dev->regs + S5P_CITRGFMT);
75}
76
77static u32 fimc_hw_get_in_flip(u32 ctx_flip)
78{
79 u32 flip = S5P_MSCTRL_FLIP_NORMAL;
80
81 switch (ctx_flip) {
82 case FLIP_X_AXIS:
83 flip = S5P_MSCTRL_FLIP_X_MIRROR;
84 break;
85 case FLIP_Y_AXIS:
86 flip = S5P_MSCTRL_FLIP_Y_MIRROR;
87 break;
88 case FLIP_XY_AXIS:
89 flip = S5P_MSCTRL_FLIP_180;
90 break;
91 }
92
93 return flip;
94}
95
96static u32 fimc_hw_get_target_flip(u32 ctx_flip)
97{
98 u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
99
100 switch (ctx_flip) {
101 case FLIP_X_AXIS:
102 flip = S5P_CITRGFMT_FLIP_X_MIRROR;
103 break;
104 case FLIP_Y_AXIS:
105 flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
106 break;
107 case FLIP_XY_AXIS:
108 flip = S5P_CITRGFMT_FLIP_180;
109 break;
110 case FLIP_NONE:
111 break;
112
113 }
114 return flip;
115}
116
117void fimc_hw_set_target_format(struct fimc_ctx *ctx)
118{
119 u32 cfg;
120 struct fimc_dev *dev = ctx->fimc_dev;
121 struct fimc_frame *frame = &ctx->d_frame;
122
123 dbg("w= %d, h= %d color: %d", frame->width,
124 frame->height, frame->fmt->color);
125
126 cfg = readl(dev->regs + S5P_CITRGFMT);
127 cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
128 S5P_CITRGFMT_VSIZE_MASK);
129
130 switch (frame->fmt->color) {
131 case S5P_FIMC_RGB565:
132 case S5P_FIMC_RGB666:
133 case S5P_FIMC_RGB888:
134 cfg |= S5P_CITRGFMT_RGB;
135 break;
136 case S5P_FIMC_YCBCR420:
137 cfg |= S5P_CITRGFMT_YCBCR420;
138 break;
139 case S5P_FIMC_YCBYCR422:
140 case S5P_FIMC_YCRYCB422:
141 case S5P_FIMC_CBYCRY422:
142 case S5P_FIMC_CRYCBY422:
143 if (frame->fmt->planes_cnt == 1)
144 cfg |= S5P_CITRGFMT_YCBCR422_1P;
145 else
146 cfg |= S5P_CITRGFMT_YCBCR422;
147 break;
148 default:
149 break;
150 }
151
152 cfg |= S5P_CITRGFMT_HSIZE(frame->width);
153 cfg |= S5P_CITRGFMT_VSIZE(frame->height);
154
155 if (ctx->rotation == 0) {
156 cfg &= ~S5P_CITRGFMT_FLIP_MASK;
157 cfg |= fimc_hw_get_target_flip(ctx->flip);
158 }
159 writel(cfg, dev->regs + S5P_CITRGFMT);
160
161 cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
162 cfg |= (frame->width * frame->height);
163 writel(cfg, dev->regs + S5P_CITAREA);
164}
165
166static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
167{
168 struct fimc_dev *dev = ctx->fimc_dev;
169 struct fimc_frame *frame = &ctx->d_frame;
170 u32 cfg = 0;
171
172 if (ctx->rotation == 90 || ctx->rotation == 270) {
173 cfg |= S5P_ORIG_SIZE_HOR(frame->f_height);
174 cfg |= S5P_ORIG_SIZE_VER(frame->f_width);
175 } else {
176 cfg |= S5P_ORIG_SIZE_HOR(frame->f_width);
177 cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
178 }
179 writel(cfg, dev->regs + S5P_ORGOSIZE);
180}
181
182void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
183{
184 u32 cfg;
185 struct fimc_dev *dev = ctx->fimc_dev;
186 struct fimc_frame *frame = &ctx->d_frame;
187 struct fimc_dma_offset *offset = &frame->dma_offset;
188
189 /* Set the input dma offsets. */
190 cfg = 0;
191 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
192 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
193 writel(cfg, dev->regs + S5P_CIOYOFF);
194
195 cfg = 0;
196 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
197 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
198 writel(cfg, dev->regs + S5P_CIOCBOFF);
199
200 cfg = 0;
201 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
202 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
203 writel(cfg, dev->regs + S5P_CIOCROFF);
204
205 fimc_hw_set_out_dma_size(ctx);
206
207 /* Configure chroma components order. */
208 cfg = readl(dev->regs + S5P_CIOCTRL);
209
210 cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
211 S5P_CIOCTRL_YCBCR_PLANE_MASK);
212
213 if (frame->fmt->planes_cnt == 1)
214 cfg |= ctx->out_order_1p;
215 else if (frame->fmt->planes_cnt == 2)
216 cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
217 else if (frame->fmt->planes_cnt == 3)
218 cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
219
220 writel(cfg, dev->regs + S5P_CIOCTRL);
221}
222
223static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
224{
225 u32 cfg = readl(dev->regs + S5P_ORGISIZE);
226 if (enable)
227 cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
228 else
229 cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
230 writel(cfg, dev->regs + S5P_ORGISIZE);
231}
232
233void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
234{
235 unsigned long flags;
236 u32 cfg;
237
238 spin_lock_irqsave(&dev->slock, flags);
239
240 cfg = readl(dev->regs + S5P_CIOCTRL);
241 if (enable)
242 cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
243 else
244 cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
245 writel(cfg, dev->regs + S5P_CIOCTRL);
246
247 spin_unlock_irqrestore(&dev->slock, flags);
248}
249
250void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
251{
252 struct fimc_dev *dev = ctx->fimc_dev;
253 struct fimc_scaler *sc = &ctx->scaler;
254 u32 cfg = 0, shfactor;
255
256 shfactor = 10 - (sc->hfactor + sc->vfactor);
257
258 cfg |= S5P_CISCPRERATIO_SHFACTOR(shfactor);
259 cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
260 cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
261 writel(cfg, dev->regs + S5P_CISCPRERATIO);
262
263 cfg = 0;
264 cfg |= S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
265 cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
266 writel(cfg, dev->regs + S5P_CISCPREDST);
267}
268
269void fimc_hw_set_scaler(struct fimc_ctx *ctx)
270{
271 struct fimc_dev *dev = ctx->fimc_dev;
272 struct fimc_scaler *sc = &ctx->scaler;
273 struct fimc_frame *src_frame = &ctx->s_frame;
274 struct fimc_frame *dst_frame = &ctx->d_frame;
275 u32 cfg = 0;
276
277 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
278 cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
279
280 if (!sc->enabled)
281 cfg |= S5P_CISCCTRL_SCALERBYPASS;
282
283 if (sc->scaleup_h)
284 cfg |= S5P_CISCCTRL_SCALEUP_H;
285
286 if (sc->scaleup_v)
287 cfg |= S5P_CISCCTRL_SCALEUP_V;
288
289 if (sc->copy_mode)
290 cfg |= S5P_CISCCTRL_ONE2ONE;
291
292
293 if (ctx->in_path == FIMC_DMA) {
294 if (src_frame->fmt->color == S5P_FIMC_RGB565)
295 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
296 else if (src_frame->fmt->color == S5P_FIMC_RGB666)
297 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
298 else if (src_frame->fmt->color == S5P_FIMC_RGB888)
299 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
300 }
301
302 if (ctx->out_path == FIMC_DMA) {
303 if (dst_frame->fmt->color == S5P_FIMC_RGB565)
304 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
305 else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
306 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
307 else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
308 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
309 } else {
310 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
311
312 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
313 cfg |= S5P_CISCCTRL_INTERLACE;
314 }
315
316 dbg("main_hratio= 0x%X main_vratio= 0x%X",
317 sc->main_hratio, sc->main_vratio);
318
319 cfg |= S5P_CISCCTRL_SC_HORRATIO(sc->main_hratio);
320 cfg |= S5P_CISCCTRL_SC_VERRATIO(sc->main_vratio);
321
322 writel(cfg, dev->regs + S5P_CISCCTRL);
323}
324
325void fimc_hw_en_capture(struct fimc_ctx *ctx)
326{
327 struct fimc_dev *dev = ctx->fimc_dev;
328 u32 cfg;
329
330 cfg = readl(dev->regs + S5P_CIIMGCPT);
331 /* One shot mode for output DMA or freerun for FIFO. */
332 if (ctx->out_path == FIMC_DMA)
333 cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE;
334 else
335 cfg &= ~S5P_CIIMGCPT_CPT_FREN_ENABLE;
336
337 if (ctx->scaler.enabled)
338 cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
339
340 writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
341}
342
343void fimc_hw_set_effect(struct fimc_ctx *ctx)
344{
345 struct fimc_dev *dev = ctx->fimc_dev;
346 struct fimc_effect *effect = &ctx->effect;
347 u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
348
349 cfg |= effect->type;
350
351 if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
352 cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
353 cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
354 }
355
356 writel(cfg, dev->regs + S5P_CIIMGEFF);
357}
358
359static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
360{
361 struct fimc_dev *dev = ctx->fimc_dev;
362 struct fimc_frame *frame = &ctx->s_frame;
363 u32 cfg_o = 0;
364 u32 cfg_r = 0;
365
366 if (FIMC_LCDFIFO == ctx->out_path)
367 cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
368
369 cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
370 cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
371 cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
372 cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
373
374 writel(cfg_o, dev->regs + S5P_ORGISIZE);
375 writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
376}
377
378void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
379{
380 struct fimc_dev *dev = ctx->fimc_dev;
381 struct fimc_frame *frame = &ctx->s_frame;
382 struct fimc_dma_offset *offset = &frame->dma_offset;
383 u32 cfg = 0;
384
385 /* Set the pixel offsets. */
386 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
387 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
388 writel(cfg, dev->regs + S5P_CIIYOFF);
389
390 cfg = 0;
391 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
392 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
393 writel(cfg, dev->regs + S5P_CIICBOFF);
394
395 cfg = 0;
396 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
397 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
398 writel(cfg, dev->regs + S5P_CIICROFF);
399
400 /* Input original and real size. */
401 fimc_hw_set_in_dma_size(ctx);
402
403 /* Autoload is used currently only in FIFO mode. */
404 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
405
406 /* Set the input DMA to process single frame only. */
407 cfg = readl(dev->regs + S5P_MSCTRL);
408 cfg &= ~(S5P_MSCTRL_FLIP_MASK
409 | S5P_MSCTRL_INFORMAT_MASK
410 | S5P_MSCTRL_IN_BURST_COUNT_MASK
411 | S5P_MSCTRL_INPUT_MASK
412 | S5P_MSCTRL_C_INT_IN_MASK
413 | S5P_MSCTRL_2P_IN_ORDER_MASK);
414
415 cfg |= (S5P_MSCTRL_FRAME_COUNT(1) | S5P_MSCTRL_INPUT_MEMORY);
416
417 switch (frame->fmt->color) {
418 case S5P_FIMC_RGB565:
419 case S5P_FIMC_RGB666:
420 case S5P_FIMC_RGB888:
421 cfg |= S5P_MSCTRL_INFORMAT_RGB;
422 break;
423 case S5P_FIMC_YCBCR420:
424 cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
425
426 if (frame->fmt->planes_cnt == 2)
427 cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
428 else
429 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
430
431 break;
432 case S5P_FIMC_YCBYCR422:
433 case S5P_FIMC_YCRYCB422:
434 case S5P_FIMC_CBYCRY422:
435 case S5P_FIMC_CRYCBY422:
436 if (frame->fmt->planes_cnt == 1) {
437 cfg |= ctx->in_order_1p
438 | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
439 } else {
440 cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
441
442 if (frame->fmt->planes_cnt == 2)
443 cfg |= ctx->in_order_2p
444 | S5P_MSCTRL_C_INT_IN_2PLANE;
445 else
446 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
447 }
448 break;
449 default:
450 break;
451 }
452
453 /*
454 * Input DMA flip mode (and rotation).
455 * Do not allow simultaneous rotation and flipping.
456 */
457 if (!ctx->rotation && ctx->out_path == FIMC_LCDFIFO)
458 cfg |= fimc_hw_get_in_flip(ctx->flip);
459
460 writel(cfg, dev->regs + S5P_MSCTRL);
461
462 /* Input/output DMA linear/tiled mode. */
463 cfg = readl(dev->regs + S5P_CIDMAPARAM);
464 cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
465
466 if (tiled_fmt(ctx->s_frame.fmt))
467 cfg |= S5P_CIDMAPARAM_R_64X32;
468
469 if (tiled_fmt(ctx->d_frame.fmt))
470 cfg |= S5P_CIDMAPARAM_W_64X32;
471
472 writel(cfg, dev->regs + S5P_CIDMAPARAM);
473}
474
475
476void fimc_hw_set_input_path(struct fimc_ctx *ctx)
477{
478 struct fimc_dev *dev = ctx->fimc_dev;
479
480 u32 cfg = readl(dev->regs + S5P_MSCTRL);
481 cfg &= ~S5P_MSCTRL_INPUT_MASK;
482
483 if (ctx->in_path == FIMC_DMA)
484 cfg |= S5P_MSCTRL_INPUT_MEMORY;
485 else
486 cfg |= S5P_MSCTRL_INPUT_EXTCAM;
487
488 writel(cfg, dev->regs + S5P_MSCTRL);
489}
490
491void fimc_hw_set_output_path(struct fimc_ctx *ctx)
492{
493 struct fimc_dev *dev = ctx->fimc_dev;
494
495 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
496 cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
497 if (ctx->out_path == FIMC_LCDFIFO)
498 cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
499 writel(cfg, dev->regs + S5P_CISCCTRL);
500}
501
502void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
503{
504 u32 cfg = 0;
505
506 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
507 cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
508 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
509
510 writel(paddr->y, dev->regs + S5P_CIIYSA0);
511 writel(paddr->cb, dev->regs + S5P_CIICBSA0);
512 writel(paddr->cr, dev->regs + S5P_CIICRSA0);
513
514 cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
515 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
516}
517
518void fimc_hw_set_output_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
519{
520 int i;
521 /* Set all the output register sets to point to single video buffer. */
522 for (i = 0; i < FIMC_MAX_OUT_BUFS; i++) {
523 writel(paddr->y, dev->regs + S5P_CIOYSA(i));
524 writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
525 writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
526 }
527}
diff --git a/drivers/media/video/s5p-fimc/regs-fimc.h b/drivers/media/video/s5p-fimc/regs-fimc.h
new file mode 100644
index 000000000000..a3cfe824db00
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/regs-fimc.h
@@ -0,0 +1,293 @@
1/*
2 * Register definition file for Samsung Camera Interface (FIMC) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef REGS_FIMC_H_
12#define REGS_FIMC_H_
13
14#define S5P_CIOYSA(__x) (0x18 + (__x) * 4)
15#define S5P_CIOCBSA(__x) (0x28 + (__x) * 4)
16#define S5P_CIOCRSA(__x) (0x38 + (__x) * 4)
17
18/* Input source format */
19#define S5P_CISRCFMT 0x00
20#define S5P_CISRCFMT_ITU601_8BIT (1 << 31)
21#define S5P_CISRCFMT_ITU601_16BIT (1 << 29)
22#define S5P_CISRCFMT_ORDER422_YCBYCR (0 << 14)
23#define S5P_CISRCFMT_ORDER422_YCRYCB (1 << 14)
24#define S5P_CISRCFMT_ORDER422_CBYCRY (2 << 14)
25#define S5P_CISRCFMT_ORDER422_CRYCBY (3 << 14)
26#define S5P_CISRCFMT_HSIZE(x) ((x) << 16)
27#define S5P_CISRCFMT_VSIZE(x) ((x) << 0)
28
29/* Window offset */
30#define S5P_CIWDOFST 0x04
31#define S5P_CIWDOFST_WINOFSEN (1 << 31)
32#define S5P_CIWDOFST_CLROVFIY (1 << 30)
33#define S5P_CIWDOFST_CLROVRLB (1 << 29)
34#define S5P_CIWDOFST_WINHOROFST_MASK (0x7ff << 16)
35#define S5P_CIWDOFST_CLROVFICB (1 << 15)
36#define S5P_CIWDOFST_CLROVFICR (1 << 14)
37#define S5P_CIWDOFST_WINHOROFST(x) ((x) << 16)
38#define S5P_CIWDOFST_WINVEROFST(x) ((x) << 0)
39#define S5P_CIWDOFST_WINVEROFST_MASK (0xfff << 0)
40
41/* Global control */
42#define S5P_CIGCTRL 0x08
43#define S5P_CIGCTRL_SWRST (1 << 31)
44#define S5P_CIGCTRL_CAMRST_A (1 << 30)
45#define S5P_CIGCTRL_SELCAM_ITU_A (1 << 29)
46#define S5P_CIGCTRL_SELCAM_ITU_MASK (1 << 29)
47#define S5P_CIGCTRL_TESTPAT_NORMAL (0 << 27)
48#define S5P_CIGCTRL_TESTPAT_COLOR_BAR (1 << 27)
49#define S5P_CIGCTRL_TESTPAT_HOR_INC (2 << 27)
50#define S5P_CIGCTRL_TESTPAT_VER_INC (3 << 27)
51#define S5P_CIGCTRL_TESTPAT_MASK (3 << 27)
52#define S5P_CIGCTRL_TESTPAT_SHIFT (27)
53#define S5P_CIGCTRL_INVPOLPCLK (1 << 26)
54#define S5P_CIGCTRL_INVPOLVSYNC (1 << 25)
55#define S5P_CIGCTRL_INVPOLHREF (1 << 24)
56#define S5P_CIGCTRL_IRQ_OVFEN (1 << 22)
57#define S5P_CIGCTRL_HREF_MASK (1 << 21)
58#define S5P_CIGCTRL_IRQ_LEVEL (1 << 20)
59#define S5P_CIGCTRL_IRQ_CLR (1 << 19)
60#define S5P_CIGCTRL_IRQ_ENABLE (1 << 16)
61#define S5P_CIGCTRL_SHDW_DISABLE (1 << 12)
62#define S5P_CIGCTRL_SELCAM_MIPI_A (1 << 7)
63#define S5P_CIGCTRL_CAMIF_SELWB (1 << 6)
64#define S5P_CIGCTRL_INVPOLHSYNC (1 << 4)
65#define S5P_CIGCTRL_SELCAM_MIPI (1 << 3)
66#define S5P_CIGCTRL_INTERLACE (1 << 0)
67
68/* Window offset 2 */
69#define S5P_CIWDOFST2 0x14
70#define S5P_CIWDOFST2_HOROFF_MASK (0xfff << 16)
71#define S5P_CIWDOFST2_VEROFF_MASK (0xfff << 0)
72#define S5P_CIWDOFST2_HOROFF(x) ((x) << 16)
73#define S5P_CIWDOFST2_VEROFF(x) ((x) << 0)
74
75/* Output DMA Y plane start address */
76#define S5P_CIOYSA1 0x18
77#define S5P_CIOYSA2 0x1c
78#define S5P_CIOYSA3 0x20
79#define S5P_CIOYSA4 0x24
80
81/* Output DMA Cb plane start address */
82#define S5P_CIOCBSA1 0x28
83#define S5P_CIOCBSA2 0x2c
84#define S5P_CIOCBSA3 0x30
85#define S5P_CIOCBSA4 0x34
86
87/* Output DMA Cr plane start address */
88#define S5P_CIOCRSA1 0x38
89#define S5P_CIOCRSA2 0x3c
90#define S5P_CIOCRSA3 0x40
91#define S5P_CIOCRSA4 0x44
92
93/* Target image format */
94#define S5P_CITRGFMT 0x48
95#define S5P_CITRGFMT_INROT90 (1 << 31)
96#define S5P_CITRGFMT_YCBCR420 (0 << 29)
97#define S5P_CITRGFMT_YCBCR422 (1 << 29)
98#define S5P_CITRGFMT_YCBCR422_1P (2 << 29)
99#define S5P_CITRGFMT_RGB (3 << 29)
100#define S5P_CITRGFMT_FMT_MASK (3 << 29)
101#define S5P_CITRGFMT_HSIZE_MASK (0xfff << 16)
102#define S5P_CITRGFMT_FLIP_SHIFT (14)
103#define S5P_CITRGFMT_FLIP_NORMAL (0 << 14)
104#define S5P_CITRGFMT_FLIP_X_MIRROR (1 << 14)
105#define S5P_CITRGFMT_FLIP_Y_MIRROR (2 << 14)
106#define S5P_CITRGFMT_FLIP_180 (3 << 14)
107#define S5P_CITRGFMT_FLIP_MASK (3 << 14)
108#define S5P_CITRGFMT_OUTROT90 (1 << 13)
109#define S5P_CITRGFMT_VSIZE_MASK (0xfff << 0)
110#define S5P_CITRGFMT_HSIZE(x) ((x) << 16)
111#define S5P_CITRGFMT_VSIZE(x) ((x) << 0)
112
113/* Output DMA control */
114#define S5P_CIOCTRL 0x4c
115#define S5P_CIOCTRL_ORDER422_MASK (3 << 0)
116#define S5P_CIOCTRL_ORDER422_CRYCBY (0 << 0)
117#define S5P_CIOCTRL_ORDER422_YCRYCB (1 << 0)
118#define S5P_CIOCTRL_ORDER422_CBYCRY (2 << 0)
119#define S5P_CIOCTRL_ORDER422_YCBYCR (3 << 0)
120#define S5P_CIOCTRL_LASTIRQ_ENABLE (1 << 2)
121#define S5P_CIOCTRL_YCBCR_3PLANE (0 << 3)
122#define S5P_CIOCTRL_YCBCR_2PLANE (1 << 3)
123#define S5P_CIOCTRL_YCBCR_PLANE_MASK (1 << 3)
124#define S5P_CIOCTRL_ORDER2P_SHIFT (24)
125#define S5P_CIOCTRL_ORDER2P_MASK (3 << 24)
126#define S5P_CIOCTRL_ORDER422_2P_LSB_CRCB (0 << 24)
127
128/* Pre-scaler control 1 */
129#define S5P_CISCPRERATIO 0x50
130#define S5P_CISCPRERATIO_SHFACTOR(x) ((x) << 28)
131#define S5P_CISCPRERATIO_HOR(x) ((x) << 16)
132#define S5P_CISCPRERATIO_VER(x) ((x) << 0)
133
134#define S5P_CISCPREDST 0x54
135#define S5P_CISCPREDST_WIDTH(x) ((x) << 16)
136#define S5P_CISCPREDST_HEIGHT(x) ((x) << 0)
137
138/* Main scaler control */
139#define S5P_CISCCTRL 0x58
140#define S5P_CISCCTRL_SCALERBYPASS (1 << 31)
141#define S5P_CISCCTRL_SCALEUP_H (1 << 30)
142#define S5P_CISCCTRL_SCALEUP_V (1 << 29)
143#define S5P_CISCCTRL_CSCR2Y_WIDE (1 << 28)
144#define S5P_CISCCTRL_CSCY2R_WIDE (1 << 27)
145#define S5P_CISCCTRL_LCDPATHEN_FIFO (1 << 26)
146#define S5P_CISCCTRL_INTERLACE (1 << 25)
147#define S5P_CISCCTRL_SCALERSTART (1 << 15)
148#define S5P_CISCCTRL_INRGB_FMT_RGB565 (0 << 13)
149#define S5P_CISCCTRL_INRGB_FMT_RGB666 (1 << 13)
150#define S5P_CISCCTRL_INRGB_FMT_RGB888 (2 << 13)
151#define S5P_CISCCTRL_INRGB_FMT_MASK (3 << 13)
152#define S5P_CISCCTRL_OUTRGB_FMT_RGB565 (0 << 11)
153#define S5P_CISCCTRL_OUTRGB_FMT_RGB666 (1 << 11)
154#define S5P_CISCCTRL_OUTRGB_FMT_RGB888 (2 << 11)
155#define S5P_CISCCTRL_OUTRGB_FMT_MASK (3 << 11)
156#define S5P_CISCCTRL_RGB_EXT (1 << 10)
157#define S5P_CISCCTRL_ONE2ONE (1 << 9)
158#define S5P_CISCCTRL_SC_HORRATIO(x) ((x) << 16)
159#define S5P_CISCCTRL_SC_VERRATIO(x) ((x) << 0)
160
161/* Target area */
162#define S5P_CITAREA 0x5c
163#define S5P_CITAREA_MASK 0x0fffffff
164
165/* General status */
166#define S5P_CISTATUS 0x64
167#define S5P_CISTATUS_OVFIY (1 << 31)
168#define S5P_CISTATUS_OVFICB (1 << 30)
169#define S5P_CISTATUS_OVFICR (1 << 29)
170#define S5P_CISTATUS_VSYNC (1 << 28)
171#define S5P_CISTATUS_WINOFF_EN (1 << 25)
172#define S5P_CISTATUS_IMGCPT_EN (1 << 22)
173#define S5P_CISTATUS_IMGCPT_SCEN (1 << 21)
174#define S5P_CISTATUS_VSYNC_A (1 << 20)
175#define S5P_CISTATUS_VSYNC_B (1 << 19)
176#define S5P_CISTATUS_OVRLB (1 << 18)
177#define S5P_CISTATUS_FRAME_END (1 << 17)
178#define S5P_CISTATUS_LASTCAPT_END (1 << 16)
179#define S5P_CISTATUS_VVALID_A (1 << 15)
180#define S5P_CISTATUS_VVALID_B (1 << 14)
181
182/* Image capture control */
183#define S5P_CIIMGCPT 0xc0
184#define S5P_CIIMGCPT_IMGCPTEN (1 << 31)
185#define S5P_CIIMGCPT_IMGCPTEN_SC (1 << 30)
186#define S5P_CIIMGCPT_CPT_FREN_ENABLE (1 << 25)
187#define S5P_CIIMGCPT_CPT_FRMOD_CNT (1 << 18)
188
189/* Frame capture sequence */
190#define S5P_CICPTSEQ 0xc4
191
192/* Image effect */
193#define S5P_CIIMGEFF 0xd0
194#define S5P_CIIMGEFF_IE_DISABLE (0 << 30)
195#define S5P_CIIMGEFF_IE_ENABLE (1 << 30)
196#define S5P_CIIMGEFF_IE_SC_BEFORE (0 << 29)
197#define S5P_CIIMGEFF_IE_SC_AFTER (1 << 29)
198#define S5P_CIIMGEFF_FIN_BYPASS (0 << 26)
199#define S5P_CIIMGEFF_FIN_ARBITRARY (1 << 26)
200#define S5P_CIIMGEFF_FIN_NEGATIVE (2 << 26)
201#define S5P_CIIMGEFF_FIN_ARTFREEZE (3 << 26)
202#define S5P_CIIMGEFF_FIN_EMBOSSING (4 << 26)
203#define S5P_CIIMGEFF_FIN_SILHOUETTE (5 << 26)
204#define S5P_CIIMGEFF_FIN_MASK (7 << 26)
205#define S5P_CIIMGEFF_PAT_CBCR_MASK ((0xff < 13) | (0xff < 0))
206#define S5P_CIIMGEFF_PAT_CB(x) ((x) << 13)
207#define S5P_CIIMGEFF_PAT_CR(x) ((x) << 0)
208
209/* Input DMA Y/Cb/Cr plane start address 0 */
210#define S5P_CIIYSA0 0xd4
211#define S5P_CIICBSA0 0xd8
212#define S5P_CIICRSA0 0xdc
213
214/* Real input DMA image size */
215#define S5P_CIREAL_ISIZE 0xf8
216#define S5P_CIREAL_ISIZE_AUTOLOAD_EN (1 << 31)
217#define S5P_CIREAL_ISIZE_ADDR_CH_DIS (1 << 30)
218#define S5P_CIREAL_ISIZE_HEIGHT(x) ((x) << 16)
219#define S5P_CIREAL_ISIZE_WIDTH(x) ((x) << 0)
220
221
222/* Input DMA control */
223#define S5P_MSCTRL 0xfc
224#define S5P_MSCTRL_IN_BURST_COUNT_MASK (3 << 24)
225#define S5P_MSCTRL_2P_IN_ORDER_MASK (3 << 16)
226#define S5P_MSCTRL_2P_IN_ORDER_SHIFT 16
227#define S5P_MSCTRL_C_INT_IN_3PLANE (0 << 15)
228#define S5P_MSCTRL_C_INT_IN_2PLANE (1 << 15)
229#define S5P_MSCTRL_C_INT_IN_MASK (1 << 15)
230#define S5P_MSCTRL_FLIP_SHIFT 13
231#define S5P_MSCTRL_FLIP_MASK (3 << 13)
232#define S5P_MSCTRL_FLIP_NORMAL (0 << 13)
233#define S5P_MSCTRL_FLIP_X_MIRROR (1 << 13)
234#define S5P_MSCTRL_FLIP_Y_MIRROR (2 << 13)
235#define S5P_MSCTRL_FLIP_180 (3 << 13)
236#define S5P_MSCTRL_ORDER422_SHIFT 4
237#define S5P_MSCTRL_ORDER422_CRYCBY (0 << 4)
238#define S5P_MSCTRL_ORDER422_YCRYCB (1 << 4)
239#define S5P_MSCTRL_ORDER422_CBYCRY (2 << 4)
240#define S5P_MSCTRL_ORDER422_YCBYCR (3 << 4)
241#define S5P_MSCTRL_ORDER422_MASK (3 << 4)
242#define S5P_MSCTRL_INPUT_EXTCAM (0 << 3)
243#define S5P_MSCTRL_INPUT_MEMORY (1 << 3)
244#define S5P_MSCTRL_INPUT_MASK (1 << 3)
245#define S5P_MSCTRL_INFORMAT_YCBCR420 (0 << 1)
246#define S5P_MSCTRL_INFORMAT_YCBCR422 (1 << 1)
247#define S5P_MSCTRL_INFORMAT_YCBCR422_1P (2 << 1)
248#define S5P_MSCTRL_INFORMAT_RGB (3 << 1)
249#define S5P_MSCTRL_INFORMAT_MASK (3 << 1)
250#define S5P_MSCTRL_ENVID (1 << 0)
251#define S5P_MSCTRL_FRAME_COUNT(x) ((x) << 24)
252
253/* Input DMA Y/Cb/Cr plane start address 1 */
254#define S5P_CIIYSA1 0x144
255#define S5P_CIICBSA1 0x148
256#define S5P_CIICRSA1 0x14c
257
258/* Output DMA Y/Cb/Cr offset */
259#define S5P_CIOYOFF 0x168
260#define S5P_CIOCBOFF 0x16c
261#define S5P_CIOCROFF 0x170
262
263/* Input DMA Y/Cb/Cr offset */
264#define S5P_CIIYOFF 0x174
265#define S5P_CIICBOFF 0x178
266#define S5P_CIICROFF 0x17c
267
268#define S5P_CIO_OFFS_VER(x) ((x) << 16)
269#define S5P_CIO_OFFS_HOR(x) ((x) << 0)
270
271/* Input DMA original image size */
272#define S5P_ORGISIZE 0x180
273
274/* Output DMA original image size */
275#define S5P_ORGOSIZE 0x184
276
277#define S5P_ORIG_SIZE_VER(x) ((x) << 16)
278#define S5P_ORIG_SIZE_HOR(x) ((x) << 0)
279
280/* Real output DMA image size (extension register) */
281#define S5P_CIEXTEN 0x188
282
283#define S5P_CIDMAPARAM 0x18c
284#define S5P_CIDMAPARAM_R_LINEAR (0 << 29)
285#define S5P_CIDMAPARAM_R_64X32 (3 << 29)
286#define S5P_CIDMAPARAM_W_LINEAR (0 << 13)
287#define S5P_CIDMAPARAM_W_64X32 (3 << 13)
288#define S5P_CIDMAPARAM_TILE_MASK ((3 << 29) | (3 << 13))
289
290/* MIPI CSI image format */
291#define S5P_CSIIMGFMT 0x194
292
293#endif /* REGS_FIMC_H_ */