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.
14 #include <linux/delay.h>
16 #include <media/s5p_fimc.h>
18 #include "fimc-core.h"
21 void fimc_hw_reset(struct fimc_dev *dev)
25 cfg = readl(dev->regs + S5P_CISRCFMT);
26 cfg |= S5P_CISRCFMT_ITU601_8BIT;
27 writel(cfg, dev->regs + S5P_CISRCFMT);
30 cfg = readl(dev->regs + S5P_CIGCTRL);
31 cfg |= S5P_CIGCTRL_SWRST;
32 writel(cfg, dev->regs + S5P_CIGCTRL);
35 cfg = readl(dev->regs + S5P_CIGCTRL);
36 cfg &= ~S5P_CIGCTRL_SWRST;
37 writel(cfg, dev->regs + S5P_CIGCTRL);
40 void fimc_hw_set_irq_level(struct fimc_dev *dev)
43 cfg = readl(dev->regs + S5P_CIGCTRL);
44 cfg |= S5P_CIGCTRL_IRQ_LEVEL;
45 writel(cfg, dev->regs + S5P_CIGCTRL);
48 static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx)
50 u32 flip = S5P_MSCTRL_FLIP_NORMAL;
54 flip = S5P_MSCTRL_FLIP_X_MIRROR;
57 flip = S5P_MSCTRL_FLIP_Y_MIRROR;
60 flip = S5P_MSCTRL_FLIP_180;
65 if (ctx->rotation <= 90)
68 return (flip ^ S5P_MSCTRL_FLIP_180) & S5P_MSCTRL_FLIP_180;
71 static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
73 u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
77 flip = S5P_CITRGFMT_FLIP_X_MIRROR;
80 flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
83 flip = S5P_CITRGFMT_FLIP_180;
88 if (ctx->rotation <= 90)
91 return (flip ^ S5P_CITRGFMT_FLIP_180) & S5P_CITRGFMT_FLIP_180;
94 void fimc_hw_set_rotation(struct fimc_ctx *ctx)
97 struct fimc_dev *dev = ctx->fimc_dev;
99 cfg = readl(dev->regs + S5P_CITRGFMT);
100 cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90 |
101 S5P_CITRGFMT_FLIP_180);
104 * The input and output rotator cannot work simultaneously.
105 * Use the output rotator in output DMA mode or the input rotator
106 * in direct fifo output mode.
108 if (ctx->rotation == 90 || ctx->rotation == 270) {
109 if (ctx->out_path == FIMC_LCDFIFO)
110 cfg |= S5P_CITRGFMT_INROT90;
112 cfg |= S5P_CITRGFMT_OUTROT90;
115 if (ctx->out_path == FIMC_DMA) {
116 cfg |= fimc_hw_get_target_flip(ctx);
117 writel(cfg, dev->regs + S5P_CITRGFMT);
120 flip = readl(dev->regs + S5P_MSCTRL);
121 flip &= ~S5P_MSCTRL_FLIP_MASK;
122 flip |= fimc_hw_get_in_flip(ctx);
123 writel(flip, dev->regs + S5P_MSCTRL);
127 void fimc_hw_set_target_format(struct fimc_ctx *ctx)
130 struct fimc_dev *dev = ctx->fimc_dev;
131 struct fimc_frame *frame = &ctx->d_frame;
133 dbg("w= %d, h= %d color: %d", frame->width,
134 frame->height, frame->fmt->color);
136 cfg_ext = readl(dev->regs + S5P_CIEXTEN);
137 cfg_ext &= ~(S5P_CIEXTEN_TRGHSIZE_EXT_MASK |
138 S5P_CIEXTEN_TRGVSIZE_EXT_MASK);
139 cfg = readl(dev->regs + S5P_CITRGFMT);
140 cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
141 S5P_CITRGFMT_VSIZE_MASK);
143 switch (frame->fmt->color) {
144 case S5P_FIMC_RGB565...S5P_FIMC_RGB444:
145 cfg |= S5P_CITRGFMT_RGB;
147 case S5P_FIMC_YCBCR420: /* fall through */
148 case S5P_FIMC_YCRCB420:
149 cfg |= S5P_CITRGFMT_YCBCR420;
151 case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
152 if (frame->fmt->colplanes == 1)
153 cfg |= S5P_CITRGFMT_YCBCR422_1P;
155 cfg |= S5P_CITRGFMT_YCBCR422;
161 if (ctx->rotation == 90 || ctx->rotation == 270) {
162 cfg |= S5P_CITRGFMT_HSIZE(frame->height);
163 cfg |= S5P_CITRGFMT_VSIZE(frame->width);
164 cfg_ext |= S5P_CIEXTEN_TRGHSIZE_EXT(frame->height);
165 cfg_ext |= S5P_CIEXTEN_TRGVSIZE_EXT(frame->width);
168 cfg |= S5P_CITRGFMT_HSIZE(frame->width);
169 cfg |= S5P_CITRGFMT_VSIZE(frame->height);
170 cfg_ext |= S5P_CIEXTEN_TRGHSIZE_EXT(frame->width);
171 cfg_ext |= S5P_CIEXTEN_TRGVSIZE_EXT(frame->height);
174 writel(cfg, dev->regs + S5P_CITRGFMT);
175 writel(cfg_ext, dev->regs + S5P_CIEXTEN);
177 cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
178 cfg |= (frame->width * frame->height);
179 writel(cfg, dev->regs + S5P_CITAREA);
182 static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
184 struct fimc_dev *dev = ctx->fimc_dev;
185 struct fimc_frame *frame = &ctx->d_frame;
188 cfg = S5P_ORIG_SIZE_HOR(frame->f_width);
189 cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
190 writel(cfg, dev->regs + S5P_ORGOSIZE);
192 /* Select color space conversion equation (HD/SD size).*/
193 cfg = readl(dev->regs + S5P_CIGCTRL);
194 if (frame->f_width >= 1280) /* HD */
195 cfg |= S5P_CIGCTRL_CSC_ITU601_709;
197 cfg &= ~S5P_CIGCTRL_CSC_ITU601_709;
198 writel(cfg, dev->regs + S5P_CIGCTRL);
202 void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
205 struct fimc_dev *dev = ctx->fimc_dev;
206 struct fimc_frame *frame = &ctx->d_frame;
207 struct fimc_dma_offset *offset = &frame->dma_offset;
209 /* Set the input dma offsets. */
211 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
212 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
213 writel(cfg, dev->regs + S5P_CIOYOFF);
216 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
217 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
218 writel(cfg, dev->regs + S5P_CIOCBOFF);
221 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
222 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
223 writel(cfg, dev->regs + S5P_CIOCROFF);
225 fimc_hw_set_out_dma_size(ctx);
227 /* Configure chroma components order. */
228 cfg = readl(dev->regs + S5P_CIOCTRL);
230 cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
231 S5P_CIOCTRL_YCBCR_PLANE_MASK | S5P_CIOCTRL_RGB16FMT_MASK);
233 if (frame->fmt->colplanes == 1)
234 cfg |= ctx->out_order_1p;
235 else if (frame->fmt->colplanes == 2)
236 cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
237 else if (frame->fmt->colplanes == 3)
238 cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
240 if (frame->fmt->color == S5P_FIMC_RGB565)
241 cfg |= S5P_CIOCTRL_RGB565;
242 else if (frame->fmt->color == S5P_FIMC_RGB555)
243 cfg |= S5P_CIOCTRL_ARGB1555;
244 else if (frame->fmt->color == S5P_FIMC_RGB444)
245 cfg |= S5P_CIOCTRL_ARGB4444;
246 else if (frame->fmt->color == S5P_FIMC_YCRCB420)
247 cfg |= S5P_CIOCTRL_ORDER422_2P_LSB_CBCR;
249 writel(cfg, dev->regs + S5P_CIOCTRL);
252 static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
254 u32 cfg = readl(dev->regs + S5P_ORGISIZE);
256 cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
258 cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
259 writel(cfg, dev->regs + S5P_ORGISIZE);
262 void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
264 u32 cfg = readl(dev->regs + S5P_CIOCTRL);
266 cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
268 cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
269 writel(cfg, dev->regs + S5P_CIOCTRL);
272 void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
274 struct fimc_dev *dev = ctx->fimc_dev;
275 struct fimc_scaler *sc = &ctx->scaler;
278 shfactor = 10 - (sc->hfactor + sc->vfactor);
280 cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor);
281 cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
282 cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
283 writel(cfg, dev->regs + S5P_CISCPRERATIO);
285 cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
286 cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
287 writel(cfg, dev->regs + S5P_CISCPREDST);
290 static void fimc_hw_set_scaler(struct fimc_ctx *ctx)
292 struct fimc_dev *dev = ctx->fimc_dev;
293 struct fimc_scaler *sc = &ctx->scaler;
294 struct fimc_frame *src_frame = &ctx->s_frame;
295 struct fimc_frame *dst_frame = &ctx->d_frame;
298 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
299 cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
302 cfg |= S5P_CISCCTRL_SCALERBYPASS;
305 cfg |= S5P_CISCCTRL_SCALEUP_H;
308 cfg |= S5P_CISCCTRL_SCALEUP_V;
311 cfg |= S5P_CISCCTRL_ONE2ONE;
314 if (ctx->in_path == FIMC_DMA) {
315 if (src_frame->fmt->color == S5P_FIMC_RGB565)
316 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
317 else if (src_frame->fmt->color == S5P_FIMC_RGB666)
318 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
319 else if (src_frame->fmt->color == S5P_FIMC_RGB888)
320 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
323 if (ctx->out_path == FIMC_DMA) {
324 if ((dst_frame->fmt->color == S5P_FIMC_RGB565)
325 | (dst_frame->fmt->color == S5P_FIMC_RGB555)
326 | (dst_frame->fmt->color == S5P_FIMC_RGB444))
327 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
328 else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
329 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
330 else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
331 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
332 cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
334 cfg |= (S5P_CISCCTRL_OUTRGB_FMT_RGB888
335 | S5P_CISCCTRL_LCDPATHEN_FIFO);
337 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
338 cfg |= S5P_CISCCTRL_INTERLACE;
341 writel(cfg, dev->regs + S5P_CISCCTRL);
344 void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
346 struct fimc_dev *dev = ctx->fimc_dev;
347 struct samsung_fimc_variant *variant = dev->variant;
348 struct fimc_scaler *sc = &ctx->scaler;
351 dbg("main_hratio= 0x%X main_vratio= 0x%X",
352 sc->main_hratio, sc->main_vratio);
354 fimc_hw_set_scaler(ctx);
356 cfg = readl(dev->regs + S5P_CISCCTRL);
358 if (variant->has_mainscaler_ext) {
359 cfg &= ~(S5P_CISCCTRL_MHRATIO_MASK | S5P_CISCCTRL_MVRATIO_MASK);
360 cfg |= S5P_CISCCTRL_MHRATIO_EXT(sc->main_hratio);
361 cfg |= S5P_CISCCTRL_MVRATIO_EXT(sc->main_vratio);
362 writel(cfg, dev->regs + S5P_CISCCTRL);
364 cfg = readl(dev->regs + S5P_CIEXTEN);
366 cfg &= ~(S5P_CIEXTEN_MVRATIO_EXT_MASK |
367 S5P_CIEXTEN_MHRATIO_EXT_MASK);
368 cfg |= S5P_CIEXTEN_MHRATIO_EXT(sc->main_hratio);
369 cfg |= S5P_CIEXTEN_MVRATIO_EXT(sc->main_vratio);
370 writel(cfg, dev->regs + S5P_CIEXTEN);
372 cfg &= ~(S5P_CISCCTRL_MHRATIO_MASK | S5P_CISCCTRL_MVRATIO_MASK);
373 cfg |= S5P_CISCCTRL_MHRATIO(sc->main_hratio);
374 cfg |= S5P_CISCCTRL_MVRATIO(sc->main_vratio);
375 writel(cfg, dev->regs + S5P_CISCCTRL);
379 void fimc_hw_en_capture(struct fimc_ctx *ctx)
381 struct fimc_dev *dev = ctx->fimc_dev;
383 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
385 if (ctx->out_path == FIMC_DMA) {
387 cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN;
389 /* Continous frame capture mode (freerun). */
390 cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE |
391 S5P_CIIMGCPT_CPT_FRMOD_CNT);
392 cfg |= S5P_CIIMGCPT_IMGCPTEN;
395 if (ctx->scaler.enabled)
396 cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
398 writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
401 void fimc_hw_set_effect(struct fimc_ctx *ctx)
403 struct fimc_dev *dev = ctx->fimc_dev;
404 struct fimc_effect *effect = &ctx->effect;
405 u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
409 if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
410 cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
411 cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
414 writel(cfg, dev->regs + S5P_CIIMGEFF);
417 void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx)
419 struct fimc_dev *dev = ctx->fimc_dev;
420 struct fimc_frame *frame = &ctx->d_frame;
423 if (!((frame->fmt->color == S5P_FIMC_RGB555)
424 | (frame->fmt->color == S5P_FIMC_RGB444)
425 | (frame->fmt->color == S5P_FIMC_RGB888)))
428 cfg = readl(dev->regs + S5P_CIOCTRL);
429 cfg &= ~S5P_CIOCTRL_ALPHA_OUT_MASK;
430 cfg |= (frame->alpha << 4);
431 writel(cfg, dev->regs + S5P_CIOCTRL);
434 static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
436 struct fimc_dev *dev = ctx->fimc_dev;
437 struct fimc_frame *frame = &ctx->s_frame;
441 if (FIMC_LCDFIFO == ctx->out_path)
442 cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
444 cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
445 cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
446 cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
447 cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
449 writel(cfg_o, dev->regs + S5P_ORGISIZE);
450 writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
453 void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
455 struct fimc_dev *dev = ctx->fimc_dev;
456 struct fimc_frame *frame = &ctx->s_frame;
457 struct fimc_dma_offset *offset = &frame->dma_offset;
460 /* Set the pixel offsets. */
461 cfg = S5P_CIO_OFFS_HOR(offset->y_h);
462 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
463 writel(cfg, dev->regs + S5P_CIIYOFF);
465 cfg = S5P_CIO_OFFS_HOR(offset->cb_h);
466 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
467 writel(cfg, dev->regs + S5P_CIICBOFF);
469 cfg = S5P_CIO_OFFS_HOR(offset->cr_h);
470 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
471 writel(cfg, dev->regs + S5P_CIICROFF);
473 /* Input original and real size. */
474 fimc_hw_set_in_dma_size(ctx);
476 /* Use DMA autoload only in FIFO mode. */
477 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
479 /* Set the input DMA to process single frame only. */
480 cfg = readl(dev->regs + S5P_MSCTRL);
481 cfg &= ~(S5P_MSCTRL_INFORMAT_MASK
482 | S5P_MSCTRL_IN_BURST_COUNT_MASK
483 | S5P_MSCTRL_INPUT_MASK
484 | S5P_MSCTRL_C_INT_IN_MASK
485 | S5P_MSCTRL_2P_IN_ORDER_MASK);
487 cfg |= (S5P_MSCTRL_IN_BURST_COUNT(4)
488 | S5P_MSCTRL_INPUT_MEMORY
489 | S5P_MSCTRL_FIFO_CTRL_FULL);
491 switch (frame->fmt->color) {
492 case S5P_FIMC_RGB565...S5P_FIMC_RGB888:
493 cfg |= S5P_MSCTRL_INFORMAT_RGB;
495 case S5P_FIMC_YCBCR420: /* fall through */
496 case S5P_FIMC_YCRCB420:
497 cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
499 if (frame->fmt->colplanes == 2)
500 cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
502 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
504 if (frame->fmt->color == S5P_FIMC_YCRCB420)
505 cfg |= S5P_MSCTRL_2P_IN_YCRCB;
507 case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
508 if (frame->fmt->colplanes == 1) {
509 cfg |= ctx->in_order_1p
510 | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
512 cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
514 if (frame->fmt->colplanes == 2)
515 cfg |= ctx->in_order_2p
516 | S5P_MSCTRL_C_INT_IN_2PLANE;
518 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
525 writel(cfg, dev->regs + S5P_MSCTRL);
527 /* Input/output DMA linear/tiled mode. */
528 cfg = readl(dev->regs + S5P_CIDMAPARAM);
529 cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
531 if (tiled_fmt(ctx->s_frame.fmt))
532 cfg |= S5P_CIDMAPARAM_R_64X32;
534 if (tiled_fmt(ctx->d_frame.fmt))
535 cfg |= S5P_CIDMAPARAM_W_64X32;
537 writel(cfg, dev->regs + S5P_CIDMAPARAM);
541 void fimc_hw_set_input_path(struct fimc_ctx *ctx)
543 struct fimc_dev *dev = ctx->fimc_dev;
545 u32 cfg = readl(dev->regs + S5P_MSCTRL);
546 cfg &= ~S5P_MSCTRL_INPUT_MASK;
548 if (ctx->in_path == FIMC_DMA)
549 cfg |= S5P_MSCTRL_INPUT_MEMORY;
551 cfg |= S5P_MSCTRL_INPUT_EXTCAM;
553 writel(cfg, dev->regs + S5P_MSCTRL);
556 void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
558 u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
559 cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
560 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
562 writel(paddr->y, dev->regs + S5P_CIIYSA(0));
563 writel(paddr->cb, dev->regs + S5P_CIICBSA(0));
564 writel(paddr->cr, dev->regs + S5P_CIICRSA(0));
566 cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
567 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
570 void fimc_hw_set_output_addr(struct fimc_dev *dev,
571 struct fimc_addr *paddr, int index)
573 int i = (index == -1) ? 0 : index;
575 writel(paddr->y, dev->regs + S5P_CIOYSA(i));
576 writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
577 writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
578 dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
579 i, paddr->y, paddr->cb, paddr->cr);
580 } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
583 int fimc_hw_save_output_addr(struct fimc_dev *fimc)
586 for (i = 0; i < FIMC_MAX_OUT_BUFS; i++) {
587 fimc->paddr[i].y = readl(fimc->regs + S5P_CIOYSA(i));
588 fimc->paddr[i].cb = readl(fimc->regs + S5P_CIOCBSA(i));
589 fimc->paddr[i].cr = readl(fimc->regs + S5P_CIOCRSA(i));
594 int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
595 struct s5p_fimc_isp_info *cam)
597 u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
599 cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
600 S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC);
602 if (cam->flags & FIMC_CLK_INV_PCLK)
603 cfg |= S5P_CIGCTRL_INVPOLPCLK;
605 if (cam->flags & FIMC_CLK_INV_VSYNC)
606 cfg |= S5P_CIGCTRL_INVPOLVSYNC;
608 if (cam->flags & FIMC_CLK_INV_HREF)
609 cfg |= S5P_CIGCTRL_INVPOLHREF;
611 if (cam->flags & FIMC_CLK_INV_HSYNC)
612 cfg |= S5P_CIGCTRL_INVPOLHSYNC;
614 writel(cfg, fimc->regs + S5P_CIGCTRL);
619 int fimc_hw_set_camera_source(struct fimc_dev *fimc,
620 struct s5p_fimc_isp_info *cam)
622 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
627 static const struct {
632 { V4L2_MBUS_FMT_YUYV8_2X8, S5P_CISRCFMT_ORDER422_YCBYCR, 8 },
633 { V4L2_MBUS_FMT_YVYU8_2X8, S5P_CISRCFMT_ORDER422_YCRYCB, 8 },
634 { V4L2_MBUS_FMT_VYUY8_2X8, S5P_CISRCFMT_ORDER422_CRYCBY, 8 },
635 { V4L2_MBUS_FMT_UYVY8_2X8, S5P_CISRCFMT_ORDER422_CBYCRY, 8 },
636 /* TODO: Add pixel codes for 16-bit bus width */
639 if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
640 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
641 if (fimc->vid_cap.fmt.code == pix_desc[i].pixelcode) {
642 cfg = pix_desc[i].cisrcfmt;
643 bus_width = pix_desc[i].bus_width;
648 if (i == ARRAY_SIZE(pix_desc)) {
649 v4l2_err(&fimc->vid_cap.v4l2_dev,
650 "Camera color format not supported: %d\n",
651 fimc->vid_cap.fmt.code);
655 if (cam->bus_type == FIMC_ITU_601) {
657 cfg |= S5P_CISRCFMT_ITU601_8BIT;
658 else if (bus_width == 16)
659 cfg |= S5P_CISRCFMT_ITU601_16BIT;
660 } /* else defaults to ITU-R BT.656 8-bit */
663 cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
664 writel(cfg, fimc->regs + S5P_CISRCFMT);
669 int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
673 u32 cfg = readl(fimc->regs + S5P_CIWDOFST);
675 cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK);
676 cfg |= S5P_CIWDOFST_OFF_EN |
677 S5P_CIWDOFST_HOROFF(f->offs_h) |
678 S5P_CIWDOFST_VEROFF(f->offs_v);
680 writel(cfg, fimc->regs + S5P_CIWDOFST);
682 /* See CIWDOFSTn register description in the datasheet for details. */
683 hoff2 = f->o_width - f->width - f->offs_h;
684 voff2 = f->o_height - f->height - f->offs_v;
685 cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2);
687 writel(cfg, fimc->regs + S5P_CIWDOFST2);
691 int fimc_hw_set_camera_type(struct fimc_dev *fimc,
692 struct s5p_fimc_isp_info *cam)
695 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
697 cfg = readl(fimc->regs + S5P_CIGCTRL);
699 /* Select ITU B interface, disable Writeback path and test pattern. */
700 cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
701 S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
702 S5P_CIGCTRL_SELCAM_MIPI_A | S5P_CIGCTRL_CAM_JPEG |
703 S5P_CIGCTRL_SELWRITEBACK_A);
705 if (cam->bus_type == FIMC_MIPI_CSI2) {
706 cfg |= S5P_CIGCTRL_SELCAM_MIPI;
708 if (cam->mux_id == 0)
709 cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
711 /* TODO: add remaining supported formats. */
712 if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8 ||
713 vid_cap->fmt.code == V4L2_MBUS_FMT_UYVY8_2X8) {
714 tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
715 } else if (vid_cap->fmt.code == V4L2_MBUS_FMT_JPEG_1X8) {
716 tmp = S5P_CSIIMGFMT_USER(1);
717 cfg |= S5P_CIGCTRL_CAM_JPEG;
719 err("camera image format not supported: %d",
723 tmp |= (cam->csi_data_align == 32) << 8;
725 writel(tmp, fimc->regs + S5P_CSIIMGFMT);
726 } else if (cam->bus_type == FIMC_ITU_601 ||
727 cam->bus_type == FIMC_ITU_656) {
728 if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
729 cfg |= S5P_CIGCTRL_SELCAM_ITU_A;
730 } else if (cam->bus_type == FIMC_LCD_WB) {
731 cfg |= S5P_CIGCTRL_CAMIF_SELWB;
732 if (cam->mux_id == 0)
733 cfg |= S5P_CIGCTRL_SELWRITEBACK_A;
735 err("invalid camera bus type selected\n");
738 writel(cfg, fimc->regs + S5P_CIGCTRL);
743 int fimc_hwset_sysreg_camblk_fimd0_wb(struct fimc_dev *fimc)
745 u32 cfg = readl(SYSREG_CAMERA_BLK);
746 cfg = cfg & (~(0x3 << 14));
748 cfg = cfg | FIMD0_WB_DEST_FIMC0;
749 else if (fimc->id == 1)
750 cfg = cfg | FIMD0_WB_DEST_FIMC1;
751 else if (fimc->id == 2)
752 cfg = cfg | FIMD0_WB_DEST_FIMC2;
753 else if (fimc->id == 3)
754 cfg = cfg | FIMD0_WB_DEST_FIMC3;
756 err("%s: not supported id : %d\n", __func__, fimc->id);
758 writel(cfg, SYSREG_CAMERA_BLK);
762 int fimc_hwset_sysreg_camblk_fimd1_wb(struct fimc_dev *fimc)
764 u32 cfg = readl(SYSREG_CAMERA_BLK);
765 cfg = cfg & (~(0x3 << 10));
767 cfg = cfg | FIMD1_WB_DEST_FIMC0;
768 else if (fimc->id == 1)
769 cfg = cfg | FIMD1_WB_DEST_FIMC1;
770 else if (fimc->id == 2)
771 cfg = cfg | FIMD1_WB_DEST_FIMC2;
772 else if (fimc->id == 3)
773 cfg = cfg | FIMD1_WB_DEST_FIMC3;
775 err("%s: not supported id : %d\n", __func__, fimc->id);
777 writel(cfg, SYSREG_CAMERA_BLK);