blob: 50b97c75b956d7f47f6195812cc043499f4b12b0 [file] [log] [blame]
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -03001/*
2 * Register interface file for Samsung Camera Interface (FIMC) driver
3 *
Sylwester Nawrocki0c9204d2012-04-25 06:55:42 -03004 * Copyright (C) 2010 - 2012 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki, <s.nawrocki@samsung.com>
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -03006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/io.h>
13#include <linux/delay.h>
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -030014#include <media/s5p_fimc.h>
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030015
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030016#include "fimc-reg.h"
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030017#include "fimc-core.h"
18
19
20void fimc_hw_reset(struct fimc_dev *dev)
21{
22 u32 cfg;
23
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030024 cfg = readl(dev->regs + FIMC_REG_CISRCFMT);
25 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
26 writel(cfg, dev->regs + FIMC_REG_CISRCFMT);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030027
28 /* Software reset. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030029 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
30 cfg |= (FIMC_REG_CIGCTRL_SWRST | FIMC_REG_CIGCTRL_IRQ_LEVEL);
31 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrockie9e21082011-09-02 06:25:32 -030032 udelay(10);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030033
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030034 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
35 cfg &= ~FIMC_REG_CIGCTRL_SWRST;
36 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -030037
38 if (dev->variant->out_buf_count > 4)
39 fimc_hw_set_dma_seq(dev, 0xF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030040}
41
Sylwester Nawrockiac759342010-12-27 14:47:32 -030042static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030043{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030044 u32 flip = FIMC_REG_MSCTRL_FLIP_NORMAL;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030045
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030046 if (ctx->hflip)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030047 flip = FIMC_REG_MSCTRL_FLIP_Y_MIRROR;
Sylwester Nawrocki1bc05e72012-11-26 11:08:26 -030048 if (ctx->vflip)
49 flip = FIMC_REG_MSCTRL_FLIP_X_MIRROR;
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030050
Sylwester Nawrockiac759342010-12-27 14:47:32 -030051 if (ctx->rotation <= 90)
52 return flip;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030053
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030054 return (flip ^ FIMC_REG_MSCTRL_FLIP_180) & FIMC_REG_MSCTRL_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030055}
56
Sylwester Nawrockiac759342010-12-27 14:47:32 -030057static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030058{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030059 u32 flip = FIMC_REG_CITRGFMT_FLIP_NORMAL;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030060
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030061 if (ctx->hflip)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030062 flip |= FIMC_REG_CITRGFMT_FLIP_Y_MIRROR;
Sylwester Nawrocki1bc05e72012-11-26 11:08:26 -030063 if (ctx->vflip)
64 flip |= FIMC_REG_CITRGFMT_FLIP_X_MIRROR;
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030065
Sylwester Nawrockiac759342010-12-27 14:47:32 -030066 if (ctx->rotation <= 90)
67 return flip;
68
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030069 return (flip ^ FIMC_REG_CITRGFMT_FLIP_180) & FIMC_REG_CITRGFMT_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030070}
71
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030072void fimc_hw_set_rotation(struct fimc_ctx *ctx)
73{
74 u32 cfg, flip;
75 struct fimc_dev *dev = ctx->fimc_dev;
76
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030077 cfg = readl(dev->regs + FIMC_REG_CITRGFMT);
78 cfg &= ~(FIMC_REG_CITRGFMT_INROT90 | FIMC_REG_CITRGFMT_OUTROT90 |
79 FIMC_REG_CITRGFMT_FLIP_180);
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030080
81 /*
82 * The input and output rotator cannot work simultaneously.
83 * Use the output rotator in output DMA mode or the input rotator
84 * in direct fifo output mode.
85 */
86 if (ctx->rotation == 90 || ctx->rotation == 270) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -030087 if (ctx->out_path == FIMC_IO_LCDFIFO)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030088 cfg |= FIMC_REG_CITRGFMT_INROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030089 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030090 cfg |= FIMC_REG_CITRGFMT_OUTROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030091 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030092
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -030093 if (ctx->out_path == FIMC_IO_DMA) {
Sylwester Nawrockiac759342010-12-27 14:47:32 -030094 cfg |= fimc_hw_get_target_flip(ctx);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030095 writel(cfg, dev->regs + FIMC_REG_CITRGFMT);
Sylwester Nawrockiac759342010-12-27 14:47:32 -030096 } else {
97 /* LCD FIFO path */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030098 flip = readl(dev->regs + FIMC_REG_MSCTRL);
99 flip &= ~FIMC_REG_MSCTRL_FLIP_MASK;
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300100 flip |= fimc_hw_get_in_flip(ctx);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300101 writel(flip, dev->regs + FIMC_REG_MSCTRL);
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300102 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300103}
104
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300105void fimc_hw_set_target_format(struct fimc_ctx *ctx)
106{
107 u32 cfg;
108 struct fimc_dev *dev = ctx->fimc_dev;
109 struct fimc_frame *frame = &ctx->d_frame;
110
111 dbg("w= %d, h= %d color: %d", frame->width,
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300112 frame->height, frame->fmt->color);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300113
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300114 cfg = readl(dev->regs + FIMC_REG_CITRGFMT);
115 cfg &= ~(FIMC_REG_CITRGFMT_FMT_MASK | FIMC_REG_CITRGFMT_HSIZE_MASK |
116 FIMC_REG_CITRGFMT_VSIZE_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300117
118 switch (frame->fmt->color) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300119 case FIMC_FMT_RGB444...FIMC_FMT_RGB888:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300120 cfg |= FIMC_REG_CITRGFMT_RGB;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300121 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300122 case FIMC_FMT_YCBCR420:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300123 cfg |= FIMC_REG_CITRGFMT_YCBCR420;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300124 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300125 case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300126 if (frame->fmt->colplanes == 1)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300127 cfg |= FIMC_REG_CITRGFMT_YCBCR422_1P;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300128 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300129 cfg |= FIMC_REG_CITRGFMT_YCBCR422;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300130 break;
131 default:
132 break;
133 }
134
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300135 if (ctx->rotation == 90 || ctx->rotation == 270)
136 cfg |= (frame->height << 16) | frame->width;
137 else
138 cfg |= (frame->width << 16) | frame->height;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300139
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300140 writel(cfg, dev->regs + FIMC_REG_CITRGFMT);
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300141
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300142 cfg = readl(dev->regs + FIMC_REG_CITAREA);
143 cfg &= ~FIMC_REG_CITAREA_MASK;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300144 cfg |= (frame->width * frame->height);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300145 writel(cfg, dev->regs + FIMC_REG_CITAREA);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300146}
147
148static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
149{
150 struct fimc_dev *dev = ctx->fimc_dev;
151 struct fimc_frame *frame = &ctx->d_frame;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300152 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300153
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300154 cfg = (frame->f_height << 16) | frame->f_width;
155 writel(cfg, dev->regs + FIMC_REG_ORGOSIZE);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300156
157 /* Select color space conversion equation (HD/SD size).*/
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300158 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300159 if (frame->f_width >= 1280) /* HD */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300160 cfg |= FIMC_REG_CIGCTRL_CSC_ITU601_709;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300161 else /* SD */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300162 cfg &= ~FIMC_REG_CIGCTRL_CSC_ITU601_709;
163 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300164
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300165}
166
167void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
168{
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300169 struct fimc_dev *dev = ctx->fimc_dev;
170 struct fimc_frame *frame = &ctx->d_frame;
171 struct fimc_dma_offset *offset = &frame->dma_offset;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300172 struct fimc_fmt *fmt = frame->fmt;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300173 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300174
175 /* Set the input dma offsets. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300176 cfg = (offset->y_v << 16) | offset->y_h;
177 writel(cfg, dev->regs + FIMC_REG_CIOYOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300178
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300179 cfg = (offset->cb_v << 16) | offset->cb_h;
180 writel(cfg, dev->regs + FIMC_REG_CIOCBOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300181
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300182 cfg = (offset->cr_v << 16) | offset->cr_h;
183 writel(cfg, dev->regs + FIMC_REG_CIOCROFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300184
185 fimc_hw_set_out_dma_size(ctx);
186
187 /* Configure chroma components order. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300188 cfg = readl(dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300189
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300190 cfg &= ~(FIMC_REG_CIOCTRL_ORDER2P_MASK |
191 FIMC_REG_CIOCTRL_ORDER422_MASK |
192 FIMC_REG_CIOCTRL_YCBCR_PLANE_MASK |
193 FIMC_REG_CIOCTRL_RGB16FMT_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300194
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300195 if (fmt->colplanes == 1)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300196 cfg |= ctx->out_order_1p;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300197 else if (fmt->colplanes == 2)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300198 cfg |= ctx->out_order_2p | FIMC_REG_CIOCTRL_YCBCR_2PLANE;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300199 else if (fmt->colplanes == 3)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300200 cfg |= FIMC_REG_CIOCTRL_YCBCR_3PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300201
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300202 if (fmt->color == FIMC_FMT_RGB565)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300203 cfg |= FIMC_REG_CIOCTRL_RGB565;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300204 else if (fmt->color == FIMC_FMT_RGB555)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300205 cfg |= FIMC_REG_CIOCTRL_ARGB1555;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300206 else if (fmt->color == FIMC_FMT_RGB444)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300207 cfg |= FIMC_REG_CIOCTRL_ARGB4444;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300208
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300209 writel(cfg, dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300210}
211
212static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
213{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300214 u32 cfg = readl(dev->regs + FIMC_REG_ORGISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300215 if (enable)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300216 cfg |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300217 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300218 cfg &= ~FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN;
219 writel(cfg, dev->regs + FIMC_REG_ORGISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300220}
221
222void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
223{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300224 u32 cfg = readl(dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300225 if (enable)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300226 cfg |= FIMC_REG_CIOCTRL_LASTIRQ_ENABLE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300227 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300228 cfg &= ~FIMC_REG_CIOCTRL_LASTIRQ_ENABLE;
229 writel(cfg, dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300230}
231
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300232void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300233{
234 struct fimc_dev *dev = ctx->fimc_dev;
235 struct fimc_scaler *sc = &ctx->scaler;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300236 u32 cfg, shfactor;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300237
238 shfactor = 10 - (sc->hfactor + sc->vfactor);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300239 cfg = shfactor << 28;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300240
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300241 cfg |= (sc->pre_hratio << 16) | sc->pre_vratio;
242 writel(cfg, dev->regs + FIMC_REG_CISCPRERATIO);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300243
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300244 cfg = (sc->pre_dst_width << 16) | sc->pre_dst_height;
245 writel(cfg, dev->regs + FIMC_REG_CISCPREDST);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300246}
247
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300248static void fimc_hw_set_scaler(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300249{
250 struct fimc_dev *dev = ctx->fimc_dev;
251 struct fimc_scaler *sc = &ctx->scaler;
252 struct fimc_frame *src_frame = &ctx->s_frame;
253 struct fimc_frame *dst_frame = &ctx->d_frame;
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -0300254
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300255 u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -0300256
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300257 cfg &= ~(FIMC_REG_CISCCTRL_CSCR2Y_WIDE | FIMC_REG_CISCCTRL_CSCY2R_WIDE |
258 FIMC_REG_CISCCTRL_SCALEUP_H | FIMC_REG_CISCCTRL_SCALEUP_V |
259 FIMC_REG_CISCCTRL_SCALERBYPASS | FIMC_REG_CISCCTRL_ONE2ONE |
260 FIMC_REG_CISCCTRL_INRGB_FMT_MASK | FIMC_REG_CISCCTRL_OUTRGB_FMT_MASK |
261 FIMC_REG_CISCCTRL_INTERLACE | FIMC_REG_CISCCTRL_RGB_EXT);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300262
263 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300264 cfg |= (FIMC_REG_CISCCTRL_CSCR2Y_WIDE |
265 FIMC_REG_CISCCTRL_CSCY2R_WIDE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300266
267 if (!sc->enabled)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300268 cfg |= FIMC_REG_CISCCTRL_SCALERBYPASS;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300269
270 if (sc->scaleup_h)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300271 cfg |= FIMC_REG_CISCCTRL_SCALEUP_H;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300272
273 if (sc->scaleup_v)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300274 cfg |= FIMC_REG_CISCCTRL_SCALEUP_V;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300275
276 if (sc->copy_mode)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300277 cfg |= FIMC_REG_CISCCTRL_ONE2ONE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300278
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300279 if (ctx->in_path == FIMC_IO_DMA) {
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300280 switch (src_frame->fmt->color) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300281 case FIMC_FMT_RGB565:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300282 cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB565;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300283 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300284 case FIMC_FMT_RGB666:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300285 cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB666;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300286 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300287 case FIMC_FMT_RGB888:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300288 cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB888;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300289 break;
290 }
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300291 }
292
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300293 if (ctx->out_path == FIMC_IO_DMA) {
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300294 u32 color = dst_frame->fmt->color;
295
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300296 if (color >= FIMC_FMT_RGB444 && color <= FIMC_FMT_RGB565)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300297 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB565;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300298 else if (color == FIMC_FMT_RGB666)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300299 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB666;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300300 else if (color == FIMC_FMT_RGB888)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300301 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB888;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300302 } else {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300303 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB888;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300304
305 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300306 cfg |= FIMC_REG_CISCCTRL_INTERLACE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300307 }
308
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300309 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300310}
311
312void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
313{
314 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki405f2302012-08-02 10:27:46 -0300315 const struct fimc_variant *variant = dev->variant;
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300316 struct fimc_scaler *sc = &ctx->scaler;
317 u32 cfg;
318
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300319 dbg("main_hratio= 0x%X main_vratio= 0x%X",
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300320 sc->main_hratio, sc->main_vratio);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300321
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300322 fimc_hw_set_scaler(ctx);
323
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300324 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
325 cfg &= ~(FIMC_REG_CISCCTRL_MHRATIO_MASK |
326 FIMC_REG_CISCCTRL_MVRATIO_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300327
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300328 if (variant->has_mainscaler_ext) {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300329 cfg |= FIMC_REG_CISCCTRL_MHRATIO_EXT(sc->main_hratio);
330 cfg |= FIMC_REG_CISCCTRL_MVRATIO_EXT(sc->main_vratio);
331 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300332
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300333 cfg = readl(dev->regs + FIMC_REG_CIEXTEN);
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300334
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300335 cfg &= ~(FIMC_REG_CIEXTEN_MVRATIO_EXT_MASK |
336 FIMC_REG_CIEXTEN_MHRATIO_EXT_MASK);
337 cfg |= FIMC_REG_CIEXTEN_MHRATIO_EXT(sc->main_hratio);
338 cfg |= FIMC_REG_CIEXTEN_MVRATIO_EXT(sc->main_vratio);
339 writel(cfg, dev->regs + FIMC_REG_CIEXTEN);
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300340 } else {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300341 cfg |= FIMC_REG_CISCCTRL_MHRATIO(sc->main_hratio);
342 cfg |= FIMC_REG_CISCCTRL_MVRATIO(sc->main_vratio);
343 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300344 }
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300345}
346
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300347void fimc_hw_enable_capture(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300348{
349 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300350 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300351
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300352 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
353 cfg |= FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300354
355 if (ctx->scaler.enabled)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300356 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN_SC;
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300357 else
358 cfg &= FIMC_REG_CIIMGCPT_IMGCPTEN_SC;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300359
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300360 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN;
361 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300362}
363
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300364void fimc_hw_disable_capture(struct fimc_dev *dev)
365{
366 u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
367 cfg &= ~(FIMC_REG_CIIMGCPT_IMGCPTEN |
368 FIMC_REG_CIIMGCPT_IMGCPTEN_SC);
369 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
370}
371
Sylwester Nawrocki9448ab72012-04-02 06:41:22 -0300372void fimc_hw_set_effect(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300373{
374 struct fimc_dev *dev = ctx->fimc_dev;
375 struct fimc_effect *effect = &ctx->effect;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300376 u32 cfg = 0;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300377
Sylwester Nawrocki9448ab72012-04-02 06:41:22 -0300378 if (effect->type != FIMC_REG_CIIMGEFF_FIN_BYPASS) {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300379 cfg |= FIMC_REG_CIIMGEFF_IE_SC_AFTER |
380 FIMC_REG_CIIMGEFF_IE_ENABLE;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300381 cfg |= effect->type;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300382 if (effect->type == FIMC_REG_CIIMGEFF_FIN_ARBITRARY)
383 cfg |= (effect->pat_cb << 13) | effect->pat_cr;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300384 }
385
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300386 writel(cfg, dev->regs + FIMC_REG_CIIMGEFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300387}
388
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300389void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx)
390{
391 struct fimc_dev *dev = ctx->fimc_dev;
392 struct fimc_frame *frame = &ctx->d_frame;
393 u32 cfg;
394
395 if (!(frame->fmt->flags & FMT_HAS_ALPHA))
396 return;
397
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300398 cfg = readl(dev->regs + FIMC_REG_CIOCTRL);
399 cfg &= ~FIMC_REG_CIOCTRL_ALPHA_OUT_MASK;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300400 cfg |= (frame->alpha << 4);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300401 writel(cfg, dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300402}
403
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300404static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
405{
406 struct fimc_dev *dev = ctx->fimc_dev;
407 struct fimc_frame *frame = &ctx->s_frame;
408 u32 cfg_o = 0;
409 u32 cfg_r = 0;
410
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300411 if (FIMC_IO_LCDFIFO == ctx->out_path)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300412 cfg_r |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300413
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300414 cfg_o |= (frame->f_height << 16) | frame->f_width;
415 cfg_r |= (frame->height << 16) | frame->width;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300416
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300417 writel(cfg_o, dev->regs + FIMC_REG_ORGISIZE);
418 writel(cfg_r, dev->regs + FIMC_REG_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300419}
420
421void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
422{
423 struct fimc_dev *dev = ctx->fimc_dev;
424 struct fimc_frame *frame = &ctx->s_frame;
425 struct fimc_dma_offset *offset = &frame->dma_offset;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300426 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300427
428 /* Set the pixel offsets. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300429 cfg = (offset->y_v << 16) | offset->y_h;
430 writel(cfg, dev->regs + FIMC_REG_CIIYOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300431
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300432 cfg = (offset->cb_v << 16) | offset->cb_h;
433 writel(cfg, dev->regs + FIMC_REG_CIICBOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300434
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300435 cfg = (offset->cr_v << 16) | offset->cr_h;
436 writel(cfg, dev->regs + FIMC_REG_CIICROFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300437
438 /* Input original and real size. */
439 fimc_hw_set_in_dma_size(ctx);
440
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300441 /* Use DMA autoload only in FIFO mode. */
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300442 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_IO_LCDFIFO);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300443
444 /* Set the input DMA to process single frame only. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300445 cfg = readl(dev->regs + FIMC_REG_MSCTRL);
446 cfg &= ~(FIMC_REG_MSCTRL_INFORMAT_MASK
447 | FIMC_REG_MSCTRL_IN_BURST_COUNT_MASK
448 | FIMC_REG_MSCTRL_INPUT_MASK
449 | FIMC_REG_MSCTRL_C_INT_IN_MASK
450 | FIMC_REG_MSCTRL_2P_IN_ORDER_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300451
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300452 cfg |= (FIMC_REG_MSCTRL_IN_BURST_COUNT(4)
453 | FIMC_REG_MSCTRL_INPUT_MEMORY
454 | FIMC_REG_MSCTRL_FIFO_CTRL_FULL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300455
456 switch (frame->fmt->color) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300457 case FIMC_FMT_RGB565...FIMC_FMT_RGB888:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300458 cfg |= FIMC_REG_MSCTRL_INFORMAT_RGB;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300459 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300460 case FIMC_FMT_YCBCR420:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300461 cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR420;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300462
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300463 if (frame->fmt->colplanes == 2)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300464 cfg |= ctx->in_order_2p | FIMC_REG_MSCTRL_C_INT_IN_2PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300465 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300466 cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300467
468 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300469 case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300470 if (frame->fmt->colplanes == 1) {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300471 cfg |= ctx->in_order_1p
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300472 | FIMC_REG_MSCTRL_INFORMAT_YCBCR422_1P;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300473 } else {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300474 cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR422;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300475
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300476 if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300477 cfg |= ctx->in_order_2p
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300478 | FIMC_REG_MSCTRL_C_INT_IN_2PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300479 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300480 cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300481 }
482 break;
483 default:
484 break;
485 }
486
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300487 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300488
489 /* Input/output DMA linear/tiled mode. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300490 cfg = readl(dev->regs + FIMC_REG_CIDMAPARAM);
491 cfg &= ~FIMC_REG_CIDMAPARAM_TILE_MASK;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300492
493 if (tiled_fmt(ctx->s_frame.fmt))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300494 cfg |= FIMC_REG_CIDMAPARAM_R_64X32;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300495
496 if (tiled_fmt(ctx->d_frame.fmt))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300497 cfg |= FIMC_REG_CIDMAPARAM_W_64X32;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300498
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300499 writel(cfg, dev->regs + FIMC_REG_CIDMAPARAM);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300500}
501
502
503void fimc_hw_set_input_path(struct fimc_ctx *ctx)
504{
505 struct fimc_dev *dev = ctx->fimc_dev;
506
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300507 u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL);
508 cfg &= ~FIMC_REG_MSCTRL_INPUT_MASK;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300509
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300510 if (ctx->in_path == FIMC_IO_DMA)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300511 cfg |= FIMC_REG_MSCTRL_INPUT_MEMORY;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300512 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300513 cfg |= FIMC_REG_MSCTRL_INPUT_EXTCAM;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300514
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300515 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300516}
517
518void fimc_hw_set_output_path(struct fimc_ctx *ctx)
519{
520 struct fimc_dev *dev = ctx->fimc_dev;
521
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300522 u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
523 cfg &= ~FIMC_REG_CISCCTRL_LCDPATHEN_FIFO;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300524 if (ctx->out_path == FIMC_IO_LCDFIFO)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300525 cfg |= FIMC_REG_CISCCTRL_LCDPATHEN_FIFO;
526 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300527}
528
529void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
530{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300531 u32 cfg = readl(dev->regs + FIMC_REG_CIREAL_ISIZE);
532 cfg |= FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS;
533 writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300534
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300535 writel(paddr->y, dev->regs + FIMC_REG_CIIYSA(0));
536 writel(paddr->cb, dev->regs + FIMC_REG_CIICBSA(0));
537 writel(paddr->cr, dev->regs + FIMC_REG_CIICRSA(0));
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300538
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300539 cfg &= ~FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS;
540 writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300541}
542
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300543void fimc_hw_set_output_addr(struct fimc_dev *dev,
544 struct fimc_addr *paddr, int index)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300545{
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300546 int i = (index == -1) ? 0 : index;
547 do {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300548 writel(paddr->y, dev->regs + FIMC_REG_CIOYSA(i));
549 writel(paddr->cb, dev->regs + FIMC_REG_CIOCBSA(i));
550 writel(paddr->cr, dev->regs + FIMC_REG_CIOCRSA(i));
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300551 dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
552 i, paddr->y, paddr->cb, paddr->cr);
553 } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300554}
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300555
556int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300557 struct fimc_source_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300558{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300559 u32 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300560
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300561 cfg &= ~(FIMC_REG_CIGCTRL_INVPOLPCLK | FIMC_REG_CIGCTRL_INVPOLVSYNC |
562 FIMC_REG_CIGCTRL_INVPOLHREF | FIMC_REG_CIGCTRL_INVPOLHSYNC |
563 FIMC_REG_CIGCTRL_INVPOLFIELD);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300564
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300565 if (cam->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300566 cfg |= FIMC_REG_CIGCTRL_INVPOLPCLK;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300567
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300568 if (cam->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300569 cfg |= FIMC_REG_CIGCTRL_INVPOLVSYNC;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300570
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300571 if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300572 cfg |= FIMC_REG_CIGCTRL_INVPOLHREF;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300573
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300574 if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300575 cfg |= FIMC_REG_CIGCTRL_INVPOLHSYNC;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300576
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300577 if (cam->flags & V4L2_MBUS_FIELD_EVEN_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300578 cfg |= FIMC_REG_CIGCTRL_INVPOLFIELD;
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300579
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300580 writel(cfg, fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300581
582 return 0;
583}
584
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300585struct mbus_pixfmt_desc {
586 u32 pixelcode;
587 u32 cisrcfmt;
588 u16 bus_width;
589};
590
591static const struct mbus_pixfmt_desc pix_desc[] = {
592 { V4L2_MBUS_FMT_YUYV8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCBYCR, 8 },
593 { V4L2_MBUS_FMT_YVYU8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCRYCB, 8 },
594 { V4L2_MBUS_FMT_VYUY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CRYCBY, 8 },
595 { V4L2_MBUS_FMT_UYVY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CBYCRY, 8 },
596};
597
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300598int fimc_hw_set_camera_source(struct fimc_dev *fimc,
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300599 struct fimc_source_info *source)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300600{
601 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300602 u32 bus_width, cfg = 0;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300603 int i;
604
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300605 switch (source->fimc_bus_type) {
606 case FIMC_BUS_TYPE_ITU_601:
607 case FIMC_BUS_TYPE_ITU_656:
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300608 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300609 if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300610 cfg = pix_desc[i].cisrcfmt;
611 bus_width = pix_desc[i].bus_width;
612 break;
613 }
614 }
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300615
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300616 if (i == ARRAY_SIZE(pix_desc)) {
Sylwester Nawrocki31d34d92012-07-26 07:15:42 -0300617 v4l2_err(&fimc->vid_cap.vfd,
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300618 "Camera color format not supported: %d\n",
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300619 fimc->vid_cap.mf.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300620 return -EINVAL;
621 }
622
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300623 if (source->fimc_bus_type == FIMC_BUS_TYPE_ITU_601) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300624 if (bus_width == 8)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300625 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300626 else if (bus_width == 16)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300627 cfg |= FIMC_REG_CISRCFMT_ITU601_16BIT;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300628 } /* else defaults to ITU-R BT.656 8-bit */
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300629 break;
630 case FIMC_BUS_TYPE_MIPI_CSI2:
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300631 if (fimc_fmt_is_user_defined(f->fmt->color))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300632 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300633 break;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300634 }
635
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300636 cfg |= (f->o_width << 16) | f->o_height;
637 writel(cfg, fimc->regs + FIMC_REG_CISRCFMT);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300638 return 0;
639}
640
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300641void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300642{
643 u32 hoff2, voff2;
644
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300645 u32 cfg = readl(fimc->regs + FIMC_REG_CIWDOFST);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300646
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300647 cfg &= ~(FIMC_REG_CIWDOFST_HOROFF_MASK | FIMC_REG_CIWDOFST_VEROFF_MASK);
648 cfg |= FIMC_REG_CIWDOFST_OFF_EN |
649 (f->offs_h << 16) | f->offs_v;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300650
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300651 writel(cfg, fimc->regs + FIMC_REG_CIWDOFST);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300652
653 /* See CIWDOFSTn register description in the datasheet for details. */
654 hoff2 = f->o_width - f->width - f->offs_h;
655 voff2 = f->o_height - f->height - f->offs_v;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300656 cfg = (hoff2 << 16) | voff2;
657 writel(cfg, fimc->regs + FIMC_REG_CIWDOFST2);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300658}
659
660int fimc_hw_set_camera_type(struct fimc_dev *fimc,
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300661 struct fimc_source_info *source)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300662{
663 u32 cfg, tmp;
664 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
Sylwester Nawrocki20676a42012-03-21 06:21:30 -0300665 u32 csis_data_alignment = 32;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300666
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300667 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300668
669 /* Select ITU B interface, disable Writeback path and test pattern. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300670 cfg &= ~(FIMC_REG_CIGCTRL_TESTPAT_MASK | FIMC_REG_CIGCTRL_SELCAM_ITU_A |
671 FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB |
672 FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300673
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300674 switch (source->fimc_bus_type) {
675 case FIMC_BUS_TYPE_MIPI_CSI2:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300676 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300677
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300678 if (source->mux_id == 0)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300679 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300680
681 /* TODO: add remaining supported formats. */
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300682 switch (vid_cap->mf.code) {
683 case V4L2_MBUS_FMT_VYUY8_2X8:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300684 tmp = FIMC_REG_CSIIMGFMT_YCBCR422_8BIT;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300685 break;
686 case V4L2_MBUS_FMT_JPEG_1X8:
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300687 case V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300688 tmp = FIMC_REG_CSIIMGFMT_USER(1);
689 cfg |= FIMC_REG_CIGCTRL_CAM_JPEG;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300690 break;
691 default:
Sylwester Nawrocki31d34d92012-07-26 07:15:42 -0300692 v4l2_err(&vid_cap->vfd,
Sachin Kamata516d082012-06-12 03:12:26 -0300693 "Not supported camera pixel format: %#x\n",
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300694 vid_cap->mf.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300695 return -EINVAL;
696 }
Sylwester Nawrocki20676a42012-03-21 06:21:30 -0300697 tmp |= (csis_data_alignment == 32) << 8;
Sylwester Nawrockie0eec9a2011-02-21 12:09:01 -0300698
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300699 writel(tmp, fimc->regs + FIMC_REG_CSIIMGFMT);
Sylwester Nawrocki31ce54f2012-07-24 12:06:26 -0300700 break;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300701 case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656:
702 if (source->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300703 cfg |= FIMC_REG_CIGCTRL_SELCAM_ITU_A;
Sylwester Nawrocki31ce54f2012-07-24 12:06:26 -0300704 break;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300705 case FIMC_BUS_TYPE_LCD_WRITEBACK_A:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300706 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB;
Sylwester Nawrocki31ce54f2012-07-24 12:06:26 -0300707 break;
708 default:
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300709 v4l2_err(&vid_cap->vfd, "Invalid FIMC bus type selected: %d\n",
710 source->fimc_bus_type);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300711 return -EINVAL;
712 }
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300713 writel(cfg, fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300714
715 return 0;
716}
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300717
718void fimc_hw_clear_irq(struct fimc_dev *dev)
719{
720 u32 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
721 cfg |= FIMC_REG_CIGCTRL_IRQ_CLR;
722 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
723}
724
725void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on)
726{
727 u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
728 if (on)
729 cfg |= FIMC_REG_CISCCTRL_SCALERSTART;
730 else
731 cfg &= ~FIMC_REG_CISCCTRL_SCALERSTART;
732 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
733}
734
735void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on)
736{
737 u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL);
738 if (on)
739 cfg |= FIMC_REG_MSCTRL_ENVID;
740 else
741 cfg &= ~FIMC_REG_MSCTRL_ENVID;
742 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
743}
744
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300745/* Return an index to the buffer actually being written. */
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300746s32 fimc_hw_get_frame_index(struct fimc_dev *dev)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300747{
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300748 s32 reg;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300749
750 if (dev->variant->has_cistatus2) {
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300751 reg = readl(dev->regs + FIMC_REG_CISTATUS2) & 0x3f;
752 return reg - 1;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300753 }
754
755 reg = readl(dev->regs + FIMC_REG_CISTATUS);
756
757 return (reg & FIMC_REG_CISTATUS_FRAMECNT_MASK) >>
758 FIMC_REG_CISTATUS_FRAMECNT_SHIFT;
759}
760
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300761/* Return an index to the buffer being written previously. */
762s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev)
763{
764 s32 reg;
765
766 if (!dev->variant->has_cistatus2)
767 return -1;
768
769 reg = readl(dev->regs + FIMC_REG_CISTATUS2);
770 return ((reg >> 7) & 0x3f) - 1;
771}
772
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300773/* Locking: the caller holds fimc->slock */
774void fimc_activate_capture(struct fimc_ctx *ctx)
775{
776 fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled);
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300777 fimc_hw_enable_capture(ctx);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300778}
779
780void fimc_deactivate_capture(struct fimc_dev *fimc)
781{
782 fimc_hw_en_lastirq(fimc, true);
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300783 fimc_hw_disable_capture(fimc);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300784 fimc_hw_enable_scaler(fimc, false);
785 fimc_hw_en_lastirq(fimc, false);
786}