blob: c14c8316ea135c5148c07a319adb91603ffea534 [file] [log] [blame]
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -03001/*
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>
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -030016#include <media/s5p_fimc.h>
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030017
18#include "fimc-core.h"
19
20
21void fimc_hw_reset(struct fimc_dev *dev)
22{
23 u32 cfg;
24
25 cfg = readl(dev->regs + S5P_CISRCFMT);
26 cfg |= S5P_CISRCFMT_ITU601_8BIT;
27 writel(cfg, dev->regs + S5P_CISRCFMT);
28
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);
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -030033 udelay(1000);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030034
35 cfg = readl(dev->regs + S5P_CIGCTRL);
36 cfg &= ~S5P_CIGCTRL_SWRST;
37 writel(cfg, dev->regs + S5P_CIGCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030038}
39
Sylwester Nawrockiac759342010-12-27 14:47:32 -030040static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030041{
42 u32 flip = S5P_MSCTRL_FLIP_NORMAL;
43
Sylwester Nawrockiac759342010-12-27 14:47:32 -030044 switch (ctx->flip) {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030045 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;
Sylwester Nawrockiac759342010-12-27 14:47:32 -030054 default:
55 break;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030056 }
Sylwester Nawrockiac759342010-12-27 14:47:32 -030057 if (ctx->rotation <= 90)
58 return flip;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030059
Sylwester Nawrockiac759342010-12-27 14:47:32 -030060 return (flip ^ S5P_MSCTRL_FLIP_180) & S5P_MSCTRL_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030061}
62
Sylwester Nawrockiac759342010-12-27 14:47:32 -030063static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030064{
65 u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
66
Sylwester Nawrockiac759342010-12-27 14:47:32 -030067 switch (ctx->flip) {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030068 case FLIP_X_AXIS:
69 flip = S5P_CITRGFMT_FLIP_X_MIRROR;
70 break;
71 case FLIP_Y_AXIS:
72 flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
73 break;
74 case FLIP_XY_AXIS:
75 flip = S5P_CITRGFMT_FLIP_180;
76 break;
Sylwester Nawrockiac759342010-12-27 14:47:32 -030077 default:
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030078 break;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030079 }
Sylwester Nawrockiac759342010-12-27 14:47:32 -030080 if (ctx->rotation <= 90)
81 return flip;
82
83 return (flip ^ S5P_CITRGFMT_FLIP_180) & S5P_CITRGFMT_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030084}
85
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030086void fimc_hw_set_rotation(struct fimc_ctx *ctx)
87{
88 u32 cfg, flip;
89 struct fimc_dev *dev = ctx->fimc_dev;
90
91 cfg = readl(dev->regs + S5P_CITRGFMT);
92 cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90 |
Sylwester Nawrockiac759342010-12-27 14:47:32 -030093 S5P_CITRGFMT_FLIP_180);
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030094
95 /*
96 * The input and output rotator cannot work simultaneously.
97 * Use the output rotator in output DMA mode or the input rotator
98 * in direct fifo output mode.
99 */
100 if (ctx->rotation == 90 || ctx->rotation == 270) {
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300101 if (ctx->out_path == FIMC_LCDFIFO)
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300102 cfg |= S5P_CITRGFMT_INROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300103 else
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300104 cfg |= S5P_CITRGFMT_OUTROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300105 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300106
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300107 if (ctx->out_path == FIMC_DMA) {
108 cfg |= fimc_hw_get_target_flip(ctx);
109 writel(cfg, dev->regs + S5P_CITRGFMT);
110 } else {
111 /* LCD FIFO path */
112 flip = readl(dev->regs + S5P_MSCTRL);
113 flip &= ~S5P_MSCTRL_FLIP_MASK;
114 flip |= fimc_hw_get_in_flip(ctx);
115 writel(flip, dev->regs + S5P_MSCTRL);
116 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300117}
118
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300119void fimc_hw_set_target_format(struct fimc_ctx *ctx)
120{
121 u32 cfg;
122 struct fimc_dev *dev = ctx->fimc_dev;
123 struct fimc_frame *frame = &ctx->d_frame;
124
125 dbg("w= %d, h= %d color: %d", frame->width,
126 frame->height, frame->fmt->color);
127
128 cfg = readl(dev->regs + S5P_CITRGFMT);
129 cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
130 S5P_CITRGFMT_VSIZE_MASK);
131
132 switch (frame->fmt->color) {
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300133 case S5P_FIMC_RGB565...S5P_FIMC_RGB888:
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300134 cfg |= S5P_CITRGFMT_RGB;
135 break;
136 case S5P_FIMC_YCBCR420:
137 cfg |= S5P_CITRGFMT_YCBCR420;
138 break;
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300139 case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300140 if (frame->fmt->colplanes == 1)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300141 cfg |= S5P_CITRGFMT_YCBCR422_1P;
142 else
143 cfg |= S5P_CITRGFMT_YCBCR422;
144 break;
145 default:
146 break;
147 }
148
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300149 if (ctx->rotation == 90 || ctx->rotation == 270) {
150 cfg |= S5P_CITRGFMT_HSIZE(frame->height);
151 cfg |= S5P_CITRGFMT_VSIZE(frame->width);
152 } else {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300153
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300154 cfg |= S5P_CITRGFMT_HSIZE(frame->width);
155 cfg |= S5P_CITRGFMT_VSIZE(frame->height);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300156 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300157
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300158 writel(cfg, dev->regs + S5P_CITRGFMT);
159
160 cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
161 cfg |= (frame->width * frame->height);
162 writel(cfg, dev->regs + S5P_CITAREA);
163}
164
165static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
166{
167 struct fimc_dev *dev = ctx->fimc_dev;
168 struct fimc_frame *frame = &ctx->d_frame;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300169 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300170
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300171 cfg = S5P_ORIG_SIZE_HOR(frame->f_width);
172 cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300173 writel(cfg, dev->regs + S5P_ORGOSIZE);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300174
175 /* Select color space conversion equation (HD/SD size).*/
176 cfg = readl(dev->regs + S5P_CIGCTRL);
177 if (frame->f_width >= 1280) /* HD */
178 cfg |= S5P_CIGCTRL_CSC_ITU601_709;
179 else /* SD */
180 cfg &= ~S5P_CIGCTRL_CSC_ITU601_709;
181 writel(cfg, dev->regs + S5P_CIGCTRL);
182
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300183}
184
185void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
186{
187 u32 cfg;
188 struct fimc_dev *dev = ctx->fimc_dev;
189 struct fimc_frame *frame = &ctx->d_frame;
190 struct fimc_dma_offset *offset = &frame->dma_offset;
191
192 /* Set the input dma offsets. */
193 cfg = 0;
194 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
195 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
196 writel(cfg, dev->regs + S5P_CIOYOFF);
197
198 cfg = 0;
199 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
200 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
201 writel(cfg, dev->regs + S5P_CIOCBOFF);
202
203 cfg = 0;
204 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
205 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
206 writel(cfg, dev->regs + S5P_CIOCROFF);
207
208 fimc_hw_set_out_dma_size(ctx);
209
210 /* Configure chroma components order. */
211 cfg = readl(dev->regs + S5P_CIOCTRL);
212
213 cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
214 S5P_CIOCTRL_YCBCR_PLANE_MASK);
215
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300216 if (frame->fmt->colplanes == 1)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300217 cfg |= ctx->out_order_1p;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300218 else if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300219 cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300220 else if (frame->fmt->colplanes == 3)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300221 cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
222
223 writel(cfg, dev->regs + S5P_CIOCTRL);
224}
225
226static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
227{
228 u32 cfg = readl(dev->regs + S5P_ORGISIZE);
229 if (enable)
230 cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
231 else
232 cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
233 writel(cfg, dev->regs + S5P_ORGISIZE);
234}
235
236void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
237{
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300238 u32 cfg = readl(dev->regs + S5P_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300239 if (enable)
240 cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
241 else
242 cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
243 writel(cfg, dev->regs + S5P_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300244}
245
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300246static void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300247{
248 struct fimc_dev *dev = ctx->fimc_dev;
249 struct fimc_scaler *sc = &ctx->scaler;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300250 u32 cfg, shfactor;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300251
252 shfactor = 10 - (sc->hfactor + sc->vfactor);
253
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300254 cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300255 cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
256 cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
257 writel(cfg, dev->regs + S5P_CISCPRERATIO);
258
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300259 cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300260 cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
261 writel(cfg, dev->regs + S5P_CISCPREDST);
262}
263
264void fimc_hw_set_scaler(struct fimc_ctx *ctx)
265{
266 struct fimc_dev *dev = ctx->fimc_dev;
267 struct fimc_scaler *sc = &ctx->scaler;
268 struct fimc_frame *src_frame = &ctx->s_frame;
269 struct fimc_frame *dst_frame = &ctx->d_frame;
270 u32 cfg = 0;
271
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300272 fimc_hw_set_prescaler(ctx);
273
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300274 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
275 cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
276
277 if (!sc->enabled)
278 cfg |= S5P_CISCCTRL_SCALERBYPASS;
279
280 if (sc->scaleup_h)
281 cfg |= S5P_CISCCTRL_SCALEUP_H;
282
283 if (sc->scaleup_v)
284 cfg |= S5P_CISCCTRL_SCALEUP_V;
285
286 if (sc->copy_mode)
287 cfg |= S5P_CISCCTRL_ONE2ONE;
288
289
290 if (ctx->in_path == FIMC_DMA) {
291 if (src_frame->fmt->color == S5P_FIMC_RGB565)
292 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
293 else if (src_frame->fmt->color == S5P_FIMC_RGB666)
294 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
295 else if (src_frame->fmt->color == S5P_FIMC_RGB888)
296 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
297 }
298
299 if (ctx->out_path == FIMC_DMA) {
300 if (dst_frame->fmt->color == S5P_FIMC_RGB565)
301 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
302 else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
303 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
304 else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
305 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
306 } else {
307 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
308
309 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
310 cfg |= S5P_CISCCTRL_INTERLACE;
311 }
312
313 dbg("main_hratio= 0x%X main_vratio= 0x%X",
314 sc->main_hratio, sc->main_vratio);
315
316 cfg |= S5P_CISCCTRL_SC_HORRATIO(sc->main_hratio);
317 cfg |= S5P_CISCCTRL_SC_VERRATIO(sc->main_vratio);
318
319 writel(cfg, dev->regs + S5P_CISCCTRL);
320}
321
322void fimc_hw_en_capture(struct fimc_ctx *ctx)
323{
324 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300325
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300326 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
327
328 if (ctx->out_path == FIMC_DMA) {
329 /* one shot mode */
330 cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN;
331 } else {
332 /* Continous frame capture mode (freerun). */
333 cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE |
334 S5P_CIIMGCPT_CPT_FRMOD_CNT);
335 cfg |= S5P_CIIMGCPT_IMGCPTEN;
336 }
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300337
338 if (ctx->scaler.enabled)
339 cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
340
341 writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
342}
343
344void fimc_hw_set_effect(struct fimc_ctx *ctx)
345{
346 struct fimc_dev *dev = ctx->fimc_dev;
347 struct fimc_effect *effect = &ctx->effect;
348 u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
349
350 cfg |= effect->type;
351
352 if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
353 cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
354 cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
355 }
356
357 writel(cfg, dev->regs + S5P_CIIMGEFF);
358}
359
360static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
361{
362 struct fimc_dev *dev = ctx->fimc_dev;
363 struct fimc_frame *frame = &ctx->s_frame;
364 u32 cfg_o = 0;
365 u32 cfg_r = 0;
366
367 if (FIMC_LCDFIFO == ctx->out_path)
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300368 cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300369
370 cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
371 cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
372 cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
373 cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
374
375 writel(cfg_o, dev->regs + S5P_ORGISIZE);
376 writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
377}
378
379void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
380{
381 struct fimc_dev *dev = ctx->fimc_dev;
382 struct fimc_frame *frame = &ctx->s_frame;
383 struct fimc_dma_offset *offset = &frame->dma_offset;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300384 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300385
386 /* Set the pixel offsets. */
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300387 cfg = S5P_CIO_OFFS_HOR(offset->y_h);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300388 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
389 writel(cfg, dev->regs + S5P_CIIYOFF);
390
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300391 cfg = S5P_CIO_OFFS_HOR(offset->cb_h);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300392 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
393 writel(cfg, dev->regs + S5P_CIICBOFF);
394
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300395 cfg = S5P_CIO_OFFS_HOR(offset->cr_h);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300396 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
397 writel(cfg, dev->regs + S5P_CIICROFF);
398
399 /* Input original and real size. */
400 fimc_hw_set_in_dma_size(ctx);
401
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300402 /* Use DMA autoload only in FIFO mode. */
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300403 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
404
405 /* Set the input DMA to process single frame only. */
406 cfg = readl(dev->regs + S5P_MSCTRL);
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300407 cfg &= ~(S5P_MSCTRL_INFORMAT_MASK
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300408 | S5P_MSCTRL_IN_BURST_COUNT_MASK
409 | S5P_MSCTRL_INPUT_MASK
410 | S5P_MSCTRL_C_INT_IN_MASK
411 | S5P_MSCTRL_2P_IN_ORDER_MASK);
412
Sylwester Nawrockid9160af2010-12-08 12:48:23 -0300413 cfg |= S5P_MSCTRL_IN_BURST_COUNT(4) | S5P_MSCTRL_INPUT_MEMORY;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300414
415 switch (frame->fmt->color) {
Sylwester Nawrockid9160af2010-12-08 12:48:23 -0300416 case S5P_FIMC_RGB565...S5P_FIMC_RGB888:
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300417 cfg |= S5P_MSCTRL_INFORMAT_RGB;
418 break;
419 case S5P_FIMC_YCBCR420:
420 cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
421
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300422 if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300423 cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
424 else
425 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
426
427 break;
Sylwester Nawrockid9160af2010-12-08 12:48:23 -0300428 case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300429 if (frame->fmt->colplanes == 1) {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300430 cfg |= ctx->in_order_1p
431 | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
432 } else {
433 cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
434
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300435 if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300436 cfg |= ctx->in_order_2p
437 | S5P_MSCTRL_C_INT_IN_2PLANE;
438 else
439 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
440 }
441 break;
442 default:
443 break;
444 }
445
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300446 writel(cfg, dev->regs + S5P_MSCTRL);
447
448 /* Input/output DMA linear/tiled mode. */
449 cfg = readl(dev->regs + S5P_CIDMAPARAM);
450 cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
451
452 if (tiled_fmt(ctx->s_frame.fmt))
453 cfg |= S5P_CIDMAPARAM_R_64X32;
454
455 if (tiled_fmt(ctx->d_frame.fmt))
456 cfg |= S5P_CIDMAPARAM_W_64X32;
457
458 writel(cfg, dev->regs + S5P_CIDMAPARAM);
459}
460
461
462void fimc_hw_set_input_path(struct fimc_ctx *ctx)
463{
464 struct fimc_dev *dev = ctx->fimc_dev;
465
466 u32 cfg = readl(dev->regs + S5P_MSCTRL);
467 cfg &= ~S5P_MSCTRL_INPUT_MASK;
468
469 if (ctx->in_path == FIMC_DMA)
470 cfg |= S5P_MSCTRL_INPUT_MEMORY;
471 else
472 cfg |= S5P_MSCTRL_INPUT_EXTCAM;
473
474 writel(cfg, dev->regs + S5P_MSCTRL);
475}
476
477void fimc_hw_set_output_path(struct fimc_ctx *ctx)
478{
479 struct fimc_dev *dev = ctx->fimc_dev;
480
481 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
482 cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
483 if (ctx->out_path == FIMC_LCDFIFO)
484 cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
485 writel(cfg, dev->regs + S5P_CISCCTRL);
486}
487
488void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
489{
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300490 u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300491 cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
492 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
493
Sylwester Nawrocki77e62082010-09-28 05:49:11 -0300494 writel(paddr->y, dev->regs + S5P_CIIYSA(0));
495 writel(paddr->cb, dev->regs + S5P_CIICBSA(0));
496 writel(paddr->cr, dev->regs + S5P_CIICRSA(0));
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300497
498 cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
499 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
500}
501
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300502void fimc_hw_set_output_addr(struct fimc_dev *dev,
503 struct fimc_addr *paddr, int index)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300504{
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300505 int i = (index == -1) ? 0 : index;
506 do {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300507 writel(paddr->y, dev->regs + S5P_CIOYSA(i));
508 writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
509 writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300510 dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
511 i, paddr->y, paddr->cb, paddr->cr);
512 } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300513}
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300514
515int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300516 struct s5p_fimc_isp_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300517{
518 u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
519
520 cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
521 S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC);
522
523 if (cam->flags & FIMC_CLK_INV_PCLK)
524 cfg |= S5P_CIGCTRL_INVPOLPCLK;
525
526 if (cam->flags & FIMC_CLK_INV_VSYNC)
527 cfg |= S5P_CIGCTRL_INVPOLVSYNC;
528
529 if (cam->flags & FIMC_CLK_INV_HREF)
530 cfg |= S5P_CIGCTRL_INVPOLHREF;
531
532 if (cam->flags & FIMC_CLK_INV_HSYNC)
533 cfg |= S5P_CIGCTRL_INVPOLHSYNC;
534
535 writel(cfg, fimc->regs + S5P_CIGCTRL);
536
537 return 0;
538}
539
540int fimc_hw_set_camera_source(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300541 struct s5p_fimc_isp_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300542{
543 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
544 u32 cfg = 0;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300545 u32 bus_width;
546 int i;
547
548 static const struct {
549 u32 pixelcode;
550 u32 cisrcfmt;
551 u16 bus_width;
552 } pix_desc[] = {
553 { V4L2_MBUS_FMT_YUYV8_2X8, S5P_CISRCFMT_ORDER422_YCBYCR, 8 },
554 { V4L2_MBUS_FMT_YVYU8_2X8, S5P_CISRCFMT_ORDER422_YCRYCB, 8 },
555 { V4L2_MBUS_FMT_VYUY8_2X8, S5P_CISRCFMT_ORDER422_CRYCBY, 8 },
556 { V4L2_MBUS_FMT_UYVY8_2X8, S5P_CISRCFMT_ORDER422_CBYCRY, 8 },
557 /* TODO: Add pixel codes for 16-bit bus width */
558 };
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300559
560 if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300561 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
562 if (fimc->vid_cap.fmt.code == pix_desc[i].pixelcode) {
563 cfg = pix_desc[i].cisrcfmt;
564 bus_width = pix_desc[i].bus_width;
565 break;
566 }
567 }
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300568
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300569 if (i == ARRAY_SIZE(pix_desc)) {
570 v4l2_err(&fimc->vid_cap.v4l2_dev,
571 "Camera color format not supported: %d\n",
572 fimc->vid_cap.fmt.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300573 return -EINVAL;
574 }
575
576 if (cam->bus_type == FIMC_ITU_601) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300577 if (bus_width == 8)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300578 cfg |= S5P_CISRCFMT_ITU601_8BIT;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300579 else if (bus_width == 16)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300580 cfg |= S5P_CISRCFMT_ITU601_16BIT;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300581 } /* else defaults to ITU-R BT.656 8-bit */
582 }
583
584 cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
585 writel(cfg, fimc->regs + S5P_CISRCFMT);
586 return 0;
587}
588
589
590int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
591{
592 u32 hoff2, voff2;
593
594 u32 cfg = readl(fimc->regs + S5P_CIWDOFST);
595
596 cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK);
597 cfg |= S5P_CIWDOFST_OFF_EN |
598 S5P_CIWDOFST_HOROFF(f->offs_h) |
599 S5P_CIWDOFST_VEROFF(f->offs_v);
600
601 writel(cfg, fimc->regs + S5P_CIWDOFST);
602
603 /* See CIWDOFSTn register description in the datasheet for details. */
604 hoff2 = f->o_width - f->width - f->offs_h;
605 voff2 = f->o_height - f->height - f->offs_v;
606 cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2);
607
608 writel(cfg, fimc->regs + S5P_CIWDOFST2);
609 return 0;
610}
611
612int fimc_hw_set_camera_type(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300613 struct s5p_fimc_isp_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300614{
615 u32 cfg, tmp;
616 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
617
618 cfg = readl(fimc->regs + S5P_CIGCTRL);
619
620 /* Select ITU B interface, disable Writeback path and test pattern. */
621 cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
622 S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
623 S5P_CIGCTRL_SELCAM_MIPI_A);
624
625 if (cam->bus_type == FIMC_MIPI_CSI2) {
626 cfg |= S5P_CIGCTRL_SELCAM_MIPI;
627
628 if (cam->mux_id == 0)
629 cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
630
631 /* TODO: add remaining supported formats. */
632 if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8) {
633 tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
634 } else {
635 err("camera image format not supported: %d",
636 vid_cap->fmt.code);
637 return -EINVAL;
638 }
639 writel(tmp | (0x1 << 8), fimc->regs + S5P_CSIIMGFMT);
640
641 } else if (cam->bus_type == FIMC_ITU_601 ||
642 cam->bus_type == FIMC_ITU_656) {
643 if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
644 cfg |= S5P_CIGCTRL_SELCAM_ITU_A;
645 } else if (cam->bus_type == FIMC_LCD_WB) {
646 cfg |= S5P_CIGCTRL_CAMIF_SELWB;
647 } else {
648 err("invalid camera bus type selected\n");
649 return -EINVAL;
650 }
651 writel(cfg, fimc->regs + S5P_CIGCTRL);
652
653 return 0;
654}