[media] s5p-fimc: Derive camera bus width from mediabus pixelcode
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / media / video / s5p-fimc / fimc-reg.c
blob63660119ef7f016e7e8312aa924caa45ff233ddd
1 /*
2 * Register interface file for Samsung Camera Interface (FIMC) driver
4 * Copyright (c) 2010 Samsung Electronics
6 * Sylwester Nawrocki, s.nawrocki@samsung.com
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.
13 #include <linux/io.h>
14 #include <linux/delay.h>
15 #include <mach/map.h>
16 #include <media/s5p_fimc.h>
18 #include "fimc-core.h"
21 void fimc_hw_reset(struct fimc_dev *dev)
23 u32 cfg;
25 cfg = readl(dev->regs + S5P_CISRCFMT);
26 cfg |= S5P_CISRCFMT_ITU601_8BIT;
27 writel(cfg, dev->regs + S5P_CISRCFMT);
29 /* Software reset. */
30 cfg = readl(dev->regs + S5P_CIGCTRL);
31 cfg |= (S5P_CIGCTRL_SWRST | S5P_CIGCTRL_IRQ_LEVEL);
32 writel(cfg, dev->regs + S5P_CIGCTRL);
33 udelay(1000);
35 cfg = readl(dev->regs + S5P_CIGCTRL);
36 cfg &= ~S5P_CIGCTRL_SWRST;
37 writel(cfg, dev->regs + S5P_CIGCTRL);
40 static u32 fimc_hw_get_in_flip(u32 ctx_flip)
42 u32 flip = S5P_MSCTRL_FLIP_NORMAL;
44 switch (ctx_flip) {
45 case FLIP_X_AXIS:
46 flip = S5P_MSCTRL_FLIP_X_MIRROR;
47 break;
48 case FLIP_Y_AXIS:
49 flip = S5P_MSCTRL_FLIP_Y_MIRROR;
50 break;
51 case FLIP_XY_AXIS:
52 flip = S5P_MSCTRL_FLIP_180;
53 break;
56 return flip;
59 static u32 fimc_hw_get_target_flip(u32 ctx_flip)
61 u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
63 switch (ctx_flip) {
64 case FLIP_X_AXIS:
65 flip = S5P_CITRGFMT_FLIP_X_MIRROR;
66 break;
67 case FLIP_Y_AXIS:
68 flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
69 break;
70 case FLIP_XY_AXIS:
71 flip = S5P_CITRGFMT_FLIP_180;
72 break;
73 case FLIP_NONE:
74 break;
77 return flip;
80 void fimc_hw_set_rotation(struct fimc_ctx *ctx)
82 u32 cfg, flip;
83 struct fimc_dev *dev = ctx->fimc_dev;
85 cfg = readl(dev->regs + S5P_CITRGFMT);
86 cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90 |
87 S5P_CITRGFMT_FLIP_180);
89 flip = readl(dev->regs + S5P_MSCTRL);
90 flip &= ~S5P_MSCTRL_FLIP_MASK;
93 * The input and output rotator cannot work simultaneously.
94 * Use the output rotator in output DMA mode or the input rotator
95 * in direct fifo output mode.
97 if (ctx->rotation == 90 || ctx->rotation == 270) {
98 if (ctx->out_path == FIMC_LCDFIFO) {
99 cfg |= S5P_CITRGFMT_INROT90;
100 if (ctx->rotation == 270)
101 flip |= S5P_MSCTRL_FLIP_180;
102 } else {
103 cfg |= S5P_CITRGFMT_OUTROT90;
104 if (ctx->rotation == 270)
105 cfg |= S5P_CITRGFMT_FLIP_180;
107 } else if (ctx->rotation == 180) {
108 if (ctx->out_path == FIMC_LCDFIFO)
109 flip |= S5P_MSCTRL_FLIP_180;
110 else
111 cfg |= S5P_CITRGFMT_FLIP_180;
113 if (ctx->rotation == 180 || ctx->rotation == 270)
114 writel(flip, dev->regs + S5P_MSCTRL);
116 cfg |= fimc_hw_get_target_flip(ctx->flip);
117 writel(cfg, dev->regs + S5P_CITRGFMT);
120 void fimc_hw_set_target_format(struct fimc_ctx *ctx)
122 u32 cfg;
123 struct fimc_dev *dev = ctx->fimc_dev;
124 struct fimc_frame *frame = &ctx->d_frame;
126 dbg("w= %d, h= %d color: %d", frame->width,
127 frame->height, frame->fmt->color);
129 cfg = readl(dev->regs + S5P_CITRGFMT);
130 cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
131 S5P_CITRGFMT_VSIZE_MASK);
133 switch (frame->fmt->color) {
134 case S5P_FIMC_RGB565:
135 case S5P_FIMC_RGB666:
136 case S5P_FIMC_RGB888:
137 cfg |= S5P_CITRGFMT_RGB;
138 break;
139 case S5P_FIMC_YCBCR420:
140 cfg |= S5P_CITRGFMT_YCBCR420;
141 break;
142 case S5P_FIMC_YCBYCR422:
143 case S5P_FIMC_YCRYCB422:
144 case S5P_FIMC_CBYCRY422:
145 case S5P_FIMC_CRYCBY422:
146 if (frame->fmt->colplanes == 1)
147 cfg |= S5P_CITRGFMT_YCBCR422_1P;
148 else
149 cfg |= S5P_CITRGFMT_YCBCR422;
150 break;
151 default:
152 break;
155 if (ctx->rotation == 90 || ctx->rotation == 270) {
156 cfg |= S5P_CITRGFMT_HSIZE(frame->height);
157 cfg |= S5P_CITRGFMT_VSIZE(frame->width);
158 } else {
160 cfg |= S5P_CITRGFMT_HSIZE(frame->width);
161 cfg |= S5P_CITRGFMT_VSIZE(frame->height);
164 writel(cfg, dev->regs + S5P_CITRGFMT);
166 cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
167 cfg |= (frame->width * frame->height);
168 writel(cfg, dev->regs + S5P_CITAREA);
171 static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
173 struct fimc_dev *dev = ctx->fimc_dev;
174 struct fimc_frame *frame = &ctx->d_frame;
175 u32 cfg;
177 cfg = S5P_ORIG_SIZE_HOR(frame->f_width);
178 cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
179 writel(cfg, dev->regs + S5P_ORGOSIZE);
181 /* Select color space conversion equation (HD/SD size).*/
182 cfg = readl(dev->regs + S5P_CIGCTRL);
183 if (frame->f_width >= 1280) /* HD */
184 cfg |= S5P_CIGCTRL_CSC_ITU601_709;
185 else /* SD */
186 cfg &= ~S5P_CIGCTRL_CSC_ITU601_709;
187 writel(cfg, dev->regs + S5P_CIGCTRL);
191 void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
193 u32 cfg;
194 struct fimc_dev *dev = ctx->fimc_dev;
195 struct fimc_frame *frame = &ctx->d_frame;
196 struct fimc_dma_offset *offset = &frame->dma_offset;
198 /* Set the input dma offsets. */
199 cfg = 0;
200 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
201 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
202 writel(cfg, dev->regs + S5P_CIOYOFF);
204 cfg = 0;
205 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
206 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
207 writel(cfg, dev->regs + S5P_CIOCBOFF);
209 cfg = 0;
210 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
211 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
212 writel(cfg, dev->regs + S5P_CIOCROFF);
214 fimc_hw_set_out_dma_size(ctx);
216 /* Configure chroma components order. */
217 cfg = readl(dev->regs + S5P_CIOCTRL);
219 cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
220 S5P_CIOCTRL_YCBCR_PLANE_MASK);
222 if (frame->fmt->colplanes == 1)
223 cfg |= ctx->out_order_1p;
224 else if (frame->fmt->colplanes == 2)
225 cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
226 else if (frame->fmt->colplanes == 3)
227 cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
229 writel(cfg, dev->regs + S5P_CIOCTRL);
232 static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
234 u32 cfg = readl(dev->regs + S5P_ORGISIZE);
235 if (enable)
236 cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
237 else
238 cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
239 writel(cfg, dev->regs + S5P_ORGISIZE);
242 void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
244 u32 cfg = readl(dev->regs + S5P_CIOCTRL);
245 if (enable)
246 cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
247 else
248 cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
249 writel(cfg, dev->regs + S5P_CIOCTRL);
252 static void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
254 struct fimc_dev *dev = ctx->fimc_dev;
255 struct fimc_scaler *sc = &ctx->scaler;
256 u32 cfg, shfactor;
258 shfactor = 10 - (sc->hfactor + sc->vfactor);
260 cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor);
261 cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
262 cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
263 writel(cfg, dev->regs + S5P_CISCPRERATIO);
265 cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
266 cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
267 writel(cfg, dev->regs + S5P_CISCPREDST);
270 void fimc_hw_set_scaler(struct fimc_ctx *ctx)
272 struct fimc_dev *dev = ctx->fimc_dev;
273 struct fimc_scaler *sc = &ctx->scaler;
274 struct fimc_frame *src_frame = &ctx->s_frame;
275 struct fimc_frame *dst_frame = &ctx->d_frame;
276 u32 cfg = 0;
278 fimc_hw_set_prescaler(ctx);
280 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
281 cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
283 if (!sc->enabled)
284 cfg |= S5P_CISCCTRL_SCALERBYPASS;
286 if (sc->scaleup_h)
287 cfg |= S5P_CISCCTRL_SCALEUP_H;
289 if (sc->scaleup_v)
290 cfg |= S5P_CISCCTRL_SCALEUP_V;
292 if (sc->copy_mode)
293 cfg |= S5P_CISCCTRL_ONE2ONE;
296 if (ctx->in_path == FIMC_DMA) {
297 if (src_frame->fmt->color == S5P_FIMC_RGB565)
298 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
299 else if (src_frame->fmt->color == S5P_FIMC_RGB666)
300 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
301 else if (src_frame->fmt->color == S5P_FIMC_RGB888)
302 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
305 if (ctx->out_path == FIMC_DMA) {
306 if (dst_frame->fmt->color == S5P_FIMC_RGB565)
307 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
308 else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
309 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
310 else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
311 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
312 } else {
313 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
315 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
316 cfg |= S5P_CISCCTRL_INTERLACE;
319 dbg("main_hratio= 0x%X main_vratio= 0x%X",
320 sc->main_hratio, sc->main_vratio);
322 cfg |= S5P_CISCCTRL_SC_HORRATIO(sc->main_hratio);
323 cfg |= S5P_CISCCTRL_SC_VERRATIO(sc->main_vratio);
325 writel(cfg, dev->regs + S5P_CISCCTRL);
328 void fimc_hw_en_capture(struct fimc_ctx *ctx)
330 struct fimc_dev *dev = ctx->fimc_dev;
332 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
334 if (ctx->out_path == FIMC_DMA) {
335 /* one shot mode */
336 cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN;
337 } else {
338 /* Continous frame capture mode (freerun). */
339 cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE |
340 S5P_CIIMGCPT_CPT_FRMOD_CNT);
341 cfg |= S5P_CIIMGCPT_IMGCPTEN;
344 if (ctx->scaler.enabled)
345 cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
347 writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
350 void fimc_hw_set_effect(struct fimc_ctx *ctx)
352 struct fimc_dev *dev = ctx->fimc_dev;
353 struct fimc_effect *effect = &ctx->effect;
354 u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
356 cfg |= effect->type;
358 if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
359 cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
360 cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
363 writel(cfg, dev->regs + S5P_CIIMGEFF);
366 static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
368 struct fimc_dev *dev = ctx->fimc_dev;
369 struct fimc_frame *frame = &ctx->s_frame;
370 u32 cfg_o = 0;
371 u32 cfg_r = 0;
373 if (FIMC_LCDFIFO == ctx->out_path)
374 cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
376 cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
377 cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
378 cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
379 cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
381 writel(cfg_o, dev->regs + S5P_ORGISIZE);
382 writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
385 void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
387 struct fimc_dev *dev = ctx->fimc_dev;
388 struct fimc_frame *frame = &ctx->s_frame;
389 struct fimc_dma_offset *offset = &frame->dma_offset;
390 u32 cfg;
392 /* Set the pixel offsets. */
393 cfg = S5P_CIO_OFFS_HOR(offset->y_h);
394 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
395 writel(cfg, dev->regs + S5P_CIIYOFF);
397 cfg = S5P_CIO_OFFS_HOR(offset->cb_h);
398 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
399 writel(cfg, dev->regs + S5P_CIICBOFF);
401 cfg = S5P_CIO_OFFS_HOR(offset->cr_h);
402 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
403 writel(cfg, dev->regs + S5P_CIICROFF);
405 /* Input original and real size. */
406 fimc_hw_set_in_dma_size(ctx);
408 /* Use DMA autoload only in FIFO mode. */
409 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
411 /* Set the input DMA to process single frame only. */
412 cfg = readl(dev->regs + S5P_MSCTRL);
413 cfg &= ~(S5P_MSCTRL_FLIP_MASK
414 | S5P_MSCTRL_INFORMAT_MASK
415 | S5P_MSCTRL_IN_BURST_COUNT_MASK
416 | S5P_MSCTRL_INPUT_MASK
417 | S5P_MSCTRL_C_INT_IN_MASK
418 | S5P_MSCTRL_2P_IN_ORDER_MASK);
420 cfg |= (S5P_MSCTRL_FRAME_COUNT(1) | S5P_MSCTRL_INPUT_MEMORY);
422 switch (frame->fmt->color) {
423 case S5P_FIMC_RGB565:
424 case S5P_FIMC_RGB666:
425 case S5P_FIMC_RGB888:
426 cfg |= S5P_MSCTRL_INFORMAT_RGB;
427 break;
428 case S5P_FIMC_YCBCR420:
429 cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
431 if (frame->fmt->colplanes == 2)
432 cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
433 else
434 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
436 break;
437 case S5P_FIMC_YCBYCR422:
438 case S5P_FIMC_YCRYCB422:
439 case S5P_FIMC_CBYCRY422:
440 case S5P_FIMC_CRYCBY422:
441 if (frame->fmt->colplanes == 1) {
442 cfg |= ctx->in_order_1p
443 | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
444 } else {
445 cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
447 if (frame->fmt->colplanes == 2)
448 cfg |= ctx->in_order_2p
449 | S5P_MSCTRL_C_INT_IN_2PLANE;
450 else
451 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
453 break;
454 default:
455 break;
459 * Input DMA flip mode (and rotation).
460 * Do not allow simultaneous rotation and flipping.
462 if (!ctx->rotation && ctx->out_path == FIMC_LCDFIFO)
463 cfg |= fimc_hw_get_in_flip(ctx->flip);
465 writel(cfg, dev->regs + S5P_MSCTRL);
467 /* Input/output DMA linear/tiled mode. */
468 cfg = readl(dev->regs + S5P_CIDMAPARAM);
469 cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
471 if (tiled_fmt(ctx->s_frame.fmt))
472 cfg |= S5P_CIDMAPARAM_R_64X32;
474 if (tiled_fmt(ctx->d_frame.fmt))
475 cfg |= S5P_CIDMAPARAM_W_64X32;
477 writel(cfg, dev->regs + S5P_CIDMAPARAM);
481 void fimc_hw_set_input_path(struct fimc_ctx *ctx)
483 struct fimc_dev *dev = ctx->fimc_dev;
485 u32 cfg = readl(dev->regs + S5P_MSCTRL);
486 cfg &= ~S5P_MSCTRL_INPUT_MASK;
488 if (ctx->in_path == FIMC_DMA)
489 cfg |= S5P_MSCTRL_INPUT_MEMORY;
490 else
491 cfg |= S5P_MSCTRL_INPUT_EXTCAM;
493 writel(cfg, dev->regs + S5P_MSCTRL);
496 void fimc_hw_set_output_path(struct fimc_ctx *ctx)
498 struct fimc_dev *dev = ctx->fimc_dev;
500 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
501 cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
502 if (ctx->out_path == FIMC_LCDFIFO)
503 cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
504 writel(cfg, dev->regs + S5P_CISCCTRL);
507 void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
509 u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
510 cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
511 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
513 writel(paddr->y, dev->regs + S5P_CIIYSA(0));
514 writel(paddr->cb, dev->regs + S5P_CIICBSA(0));
515 writel(paddr->cr, dev->regs + S5P_CIICRSA(0));
517 cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
518 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
521 void fimc_hw_set_output_addr(struct fimc_dev *dev,
522 struct fimc_addr *paddr, int index)
524 int i = (index == -1) ? 0 : index;
525 do {
526 writel(paddr->y, dev->regs + S5P_CIOYSA(i));
527 writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
528 writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
529 dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
530 i, paddr->y, paddr->cb, paddr->cr);
531 } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
534 int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
535 struct s5p_fimc_isp_info *cam)
537 u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
539 cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
540 S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC);
542 if (cam->flags & FIMC_CLK_INV_PCLK)
543 cfg |= S5P_CIGCTRL_INVPOLPCLK;
545 if (cam->flags & FIMC_CLK_INV_VSYNC)
546 cfg |= S5P_CIGCTRL_INVPOLVSYNC;
548 if (cam->flags & FIMC_CLK_INV_HREF)
549 cfg |= S5P_CIGCTRL_INVPOLHREF;
551 if (cam->flags & FIMC_CLK_INV_HSYNC)
552 cfg |= S5P_CIGCTRL_INVPOLHSYNC;
554 writel(cfg, fimc->regs + S5P_CIGCTRL);
556 return 0;
559 int fimc_hw_set_camera_source(struct fimc_dev *fimc,
560 struct s5p_fimc_isp_info *cam)
562 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
563 u32 cfg = 0;
564 u32 bus_width;
565 int i;
567 static const struct {
568 u32 pixelcode;
569 u32 cisrcfmt;
570 u16 bus_width;
571 } pix_desc[] = {
572 { V4L2_MBUS_FMT_YUYV8_2X8, S5P_CISRCFMT_ORDER422_YCBYCR, 8 },
573 { V4L2_MBUS_FMT_YVYU8_2X8, S5P_CISRCFMT_ORDER422_YCRYCB, 8 },
574 { V4L2_MBUS_FMT_VYUY8_2X8, S5P_CISRCFMT_ORDER422_CRYCBY, 8 },
575 { V4L2_MBUS_FMT_UYVY8_2X8, S5P_CISRCFMT_ORDER422_CBYCRY, 8 },
576 /* TODO: Add pixel codes for 16-bit bus width */
579 if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
580 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
581 if (fimc->vid_cap.fmt.code == pix_desc[i].pixelcode) {
582 cfg = pix_desc[i].cisrcfmt;
583 bus_width = pix_desc[i].bus_width;
584 break;
588 if (i == ARRAY_SIZE(pix_desc)) {
589 v4l2_err(&fimc->vid_cap.v4l2_dev,
590 "Camera color format not supported: %d\n",
591 fimc->vid_cap.fmt.code);
592 return -EINVAL;
595 if (cam->bus_type == FIMC_ITU_601) {
596 if (bus_width == 8)
597 cfg |= S5P_CISRCFMT_ITU601_8BIT;
598 else if (bus_width == 16)
599 cfg |= S5P_CISRCFMT_ITU601_16BIT;
600 } /* else defaults to ITU-R BT.656 8-bit */
603 cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
604 writel(cfg, fimc->regs + S5P_CISRCFMT);
605 return 0;
609 int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
611 u32 hoff2, voff2;
613 u32 cfg = readl(fimc->regs + S5P_CIWDOFST);
615 cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK);
616 cfg |= S5P_CIWDOFST_OFF_EN |
617 S5P_CIWDOFST_HOROFF(f->offs_h) |
618 S5P_CIWDOFST_VEROFF(f->offs_v);
620 writel(cfg, fimc->regs + S5P_CIWDOFST);
622 /* See CIWDOFSTn register description in the datasheet for details. */
623 hoff2 = f->o_width - f->width - f->offs_h;
624 voff2 = f->o_height - f->height - f->offs_v;
625 cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2);
627 writel(cfg, fimc->regs + S5P_CIWDOFST2);
628 return 0;
631 int fimc_hw_set_camera_type(struct fimc_dev *fimc,
632 struct s5p_fimc_isp_info *cam)
634 u32 cfg, tmp;
635 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
637 cfg = readl(fimc->regs + S5P_CIGCTRL);
639 /* Select ITU B interface, disable Writeback path and test pattern. */
640 cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
641 S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
642 S5P_CIGCTRL_SELCAM_MIPI_A);
644 if (cam->bus_type == FIMC_MIPI_CSI2) {
645 cfg |= S5P_CIGCTRL_SELCAM_MIPI;
647 if (cam->mux_id == 0)
648 cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
650 /* TODO: add remaining supported formats. */
651 if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8) {
652 tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
653 } else {
654 err("camera image format not supported: %d",
655 vid_cap->fmt.code);
656 return -EINVAL;
658 writel(tmp | (0x1 << 8), fimc->regs + S5P_CSIIMGFMT);
660 } else if (cam->bus_type == FIMC_ITU_601 ||
661 cam->bus_type == FIMC_ITU_656) {
662 if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
663 cfg |= S5P_CIGCTRL_SELCAM_ITU_A;
664 } else if (cam->bus_type == FIMC_LCD_WB) {
665 cfg |= S5P_CIGCTRL_CAMIF_SELWB;
666 } else {
667 err("invalid camera bus type selected\n");
668 return -EINVAL;
670 writel(cfg, fimc->regs + S5P_CIGCTRL);
672 return 0;