blob: 50937b40854ff379c837c4412b7a85ca7cec36e4 [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 Nawrockie9e21082011-09-02 06:25:32 -030033 udelay(10);
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 Nawrocki131b6c62011-08-24 19:25:10 -030044 if (ctx->hflip)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030045 flip = S5P_MSCTRL_FLIP_X_MIRROR;
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030046 if (ctx->vflip)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030047 flip = S5P_MSCTRL_FLIP_Y_MIRROR;
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030048
Sylwester Nawrockiac759342010-12-27 14:47:32 -030049 if (ctx->rotation <= 90)
50 return flip;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030051
Sylwester Nawrockiac759342010-12-27 14:47:32 -030052 return (flip ^ S5P_MSCTRL_FLIP_180) & S5P_MSCTRL_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030053}
54
Sylwester Nawrockiac759342010-12-27 14:47:32 -030055static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030056{
57 u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
58
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030059 if (ctx->hflip)
60 flip |= S5P_CITRGFMT_FLIP_X_MIRROR;
61 if (ctx->vflip)
62 flip |= S5P_CITRGFMT_FLIP_Y_MIRROR;
63
Sylwester Nawrockiac759342010-12-27 14:47:32 -030064 if (ctx->rotation <= 90)
65 return flip;
66
67 return (flip ^ S5P_CITRGFMT_FLIP_180) & S5P_CITRGFMT_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030068}
69
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030070void fimc_hw_set_rotation(struct fimc_ctx *ctx)
71{
72 u32 cfg, flip;
73 struct fimc_dev *dev = ctx->fimc_dev;
74
75 cfg = readl(dev->regs + S5P_CITRGFMT);
76 cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90 |
Sylwester Nawrockiac759342010-12-27 14:47:32 -030077 S5P_CITRGFMT_FLIP_180);
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030078
79 /*
80 * The input and output rotator cannot work simultaneously.
81 * Use the output rotator in output DMA mode or the input rotator
82 * in direct fifo output mode.
83 */
84 if (ctx->rotation == 90 || ctx->rotation == 270) {
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030085 if (ctx->out_path == FIMC_LCDFIFO)
Sylwester Nawrockiac759342010-12-27 14:47:32 -030086 cfg |= S5P_CITRGFMT_INROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030087 else
Sylwester Nawrockiac759342010-12-27 14:47:32 -030088 cfg |= S5P_CITRGFMT_OUTROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030089 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030090
Sylwester Nawrockiac759342010-12-27 14:47:32 -030091 if (ctx->out_path == FIMC_DMA) {
92 cfg |= fimc_hw_get_target_flip(ctx);
93 writel(cfg, dev->regs + S5P_CITRGFMT);
94 } else {
95 /* LCD FIFO path */
96 flip = readl(dev->regs + S5P_MSCTRL);
97 flip &= ~S5P_MSCTRL_FLIP_MASK;
98 flip |= fimc_hw_get_in_flip(ctx);
99 writel(flip, dev->regs + S5P_MSCTRL);
100 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300101}
102
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300103void fimc_hw_set_target_format(struct fimc_ctx *ctx)
104{
105 u32 cfg;
106 struct fimc_dev *dev = ctx->fimc_dev;
107 struct fimc_frame *frame = &ctx->d_frame;
108
109 dbg("w= %d, h= %d color: %d", frame->width,
110 frame->height, frame->fmt->color);
111
112 cfg = readl(dev->regs + S5P_CITRGFMT);
113 cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
114 S5P_CITRGFMT_VSIZE_MASK);
115
116 switch (frame->fmt->color) {
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300117 case S5P_FIMC_RGB565...S5P_FIMC_RGB888:
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300118 cfg |= S5P_CITRGFMT_RGB;
119 break;
120 case S5P_FIMC_YCBCR420:
121 cfg |= S5P_CITRGFMT_YCBCR420;
122 break;
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300123 case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300124 if (frame->fmt->colplanes == 1)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300125 cfg |= S5P_CITRGFMT_YCBCR422_1P;
126 else
127 cfg |= S5P_CITRGFMT_YCBCR422;
128 break;
129 default:
130 break;
131 }
132
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300133 if (ctx->rotation == 90 || ctx->rotation == 270) {
134 cfg |= S5P_CITRGFMT_HSIZE(frame->height);
135 cfg |= S5P_CITRGFMT_VSIZE(frame->width);
136 } else {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300137
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300138 cfg |= S5P_CITRGFMT_HSIZE(frame->width);
139 cfg |= S5P_CITRGFMT_VSIZE(frame->height);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300140 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300141
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300142 writel(cfg, dev->regs + S5P_CITRGFMT);
143
144 cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
145 cfg |= (frame->width * frame->height);
146 writel(cfg, dev->regs + S5P_CITAREA);
147}
148
149static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
150{
151 struct fimc_dev *dev = ctx->fimc_dev;
152 struct fimc_frame *frame = &ctx->d_frame;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300153 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300154
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300155 cfg = S5P_ORIG_SIZE_HOR(frame->f_width);
156 cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300157 writel(cfg, dev->regs + S5P_ORGOSIZE);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300158
159 /* Select color space conversion equation (HD/SD size).*/
160 cfg = readl(dev->regs + S5P_CIGCTRL);
161 if (frame->f_width >= 1280) /* HD */
162 cfg |= S5P_CIGCTRL_CSC_ITU601_709;
163 else /* SD */
164 cfg &= ~S5P_CIGCTRL_CSC_ITU601_709;
165 writel(cfg, dev->regs + S5P_CIGCTRL);
166
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300167}
168
169void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
170{
171 u32 cfg;
172 struct fimc_dev *dev = ctx->fimc_dev;
173 struct fimc_frame *frame = &ctx->d_frame;
174 struct fimc_dma_offset *offset = &frame->dma_offset;
175
176 /* Set the input dma offsets. */
177 cfg = 0;
178 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
179 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
180 writel(cfg, dev->regs + S5P_CIOYOFF);
181
182 cfg = 0;
183 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
184 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
185 writel(cfg, dev->regs + S5P_CIOCBOFF);
186
187 cfg = 0;
188 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
189 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
190 writel(cfg, dev->regs + S5P_CIOCROFF);
191
192 fimc_hw_set_out_dma_size(ctx);
193
194 /* Configure chroma components order. */
195 cfg = readl(dev->regs + S5P_CIOCTRL);
196
197 cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
198 S5P_CIOCTRL_YCBCR_PLANE_MASK);
199
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300200 if (frame->fmt->colplanes == 1)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300201 cfg |= ctx->out_order_1p;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300202 else if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300203 cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300204 else if (frame->fmt->colplanes == 3)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300205 cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
206
207 writel(cfg, dev->regs + S5P_CIOCTRL);
208}
209
210static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
211{
212 u32 cfg = readl(dev->regs + S5P_ORGISIZE);
213 if (enable)
214 cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
215 else
216 cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
217 writel(cfg, dev->regs + S5P_ORGISIZE);
218}
219
220void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
221{
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300222 u32 cfg = readl(dev->regs + S5P_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300223 if (enable)
224 cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
225 else
226 cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
227 writel(cfg, dev->regs + S5P_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300228}
229
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300230void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300231{
232 struct fimc_dev *dev = ctx->fimc_dev;
233 struct fimc_scaler *sc = &ctx->scaler;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300234 u32 cfg, shfactor;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300235
236 shfactor = 10 - (sc->hfactor + sc->vfactor);
237
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300238 cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300239 cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
240 cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
241 writel(cfg, dev->regs + S5P_CISCPRERATIO);
242
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300243 cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300244 cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
245 writel(cfg, dev->regs + S5P_CISCPREDST);
246}
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;
254 u32 cfg = 0;
255
256 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
257 cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
258
259 if (!sc->enabled)
260 cfg |= S5P_CISCCTRL_SCALERBYPASS;
261
262 if (sc->scaleup_h)
263 cfg |= S5P_CISCCTRL_SCALEUP_H;
264
265 if (sc->scaleup_v)
266 cfg |= S5P_CISCCTRL_SCALEUP_V;
267
268 if (sc->copy_mode)
269 cfg |= S5P_CISCCTRL_ONE2ONE;
270
271
272 if (ctx->in_path == FIMC_DMA) {
273 if (src_frame->fmt->color == S5P_FIMC_RGB565)
274 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
275 else if (src_frame->fmt->color == S5P_FIMC_RGB666)
276 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
277 else if (src_frame->fmt->color == S5P_FIMC_RGB888)
278 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
279 }
280
281 if (ctx->out_path == FIMC_DMA) {
282 if (dst_frame->fmt->color == S5P_FIMC_RGB565)
283 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
284 else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
285 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
286 else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
287 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
288 } else {
289 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
290
291 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
292 cfg |= S5P_CISCCTRL_INTERLACE;
293 }
294
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300295 writel(cfg, dev->regs + S5P_CISCCTRL);
296}
297
298void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
299{
300 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300301 struct samsung_fimc_variant *variant = dev->variant;
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300302 struct fimc_scaler *sc = &ctx->scaler;
303 u32 cfg;
304
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300305 dbg("main_hratio= 0x%X main_vratio= 0x%X",
306 sc->main_hratio, sc->main_vratio);
307
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300308 fimc_hw_set_scaler(ctx);
309
310 cfg = readl(dev->regs + S5P_CISCCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300311
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300312 if (variant->has_mainscaler_ext) {
313 cfg &= ~(S5P_CISCCTRL_MHRATIO_MASK | S5P_CISCCTRL_MVRATIO_MASK);
314 cfg |= S5P_CISCCTRL_MHRATIO_EXT(sc->main_hratio);
315 cfg |= S5P_CISCCTRL_MVRATIO_EXT(sc->main_vratio);
316 writel(cfg, dev->regs + S5P_CISCCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300317
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300318 cfg = readl(dev->regs + S5P_CIEXTEN);
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300319
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300320 cfg &= ~(S5P_CIEXTEN_MVRATIO_EXT_MASK |
321 S5P_CIEXTEN_MHRATIO_EXT_MASK);
322 cfg |= S5P_CIEXTEN_MHRATIO_EXT(sc->main_hratio);
323 cfg |= S5P_CIEXTEN_MVRATIO_EXT(sc->main_vratio);
324 writel(cfg, dev->regs + S5P_CIEXTEN);
325 } else {
326 cfg &= ~(S5P_CISCCTRL_MHRATIO_MASK | S5P_CISCCTRL_MVRATIO_MASK);
327 cfg |= S5P_CISCCTRL_MHRATIO(sc->main_hratio);
328 cfg |= S5P_CISCCTRL_MVRATIO(sc->main_vratio);
329 writel(cfg, dev->regs + S5P_CISCCTRL);
330 }
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300331}
332
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300333void fimc_hw_en_capture(struct fimc_ctx *ctx)
334{
335 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300336
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300337 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
338
339 if (ctx->out_path == FIMC_DMA) {
340 /* one shot mode */
341 cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN;
342 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300343 /* Continuous frame capture mode (freerun). */
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300344 cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE |
345 S5P_CIIMGCPT_CPT_FRMOD_CNT);
346 cfg |= S5P_CIIMGCPT_IMGCPTEN;
347 }
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300348
349 if (ctx->scaler.enabled)
350 cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
351
352 writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
353}
354
355void fimc_hw_set_effect(struct fimc_ctx *ctx)
356{
357 struct fimc_dev *dev = ctx->fimc_dev;
358 struct fimc_effect *effect = &ctx->effect;
359 u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
360
361 cfg |= effect->type;
362
363 if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
364 cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
365 cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
366 }
367
368 writel(cfg, dev->regs + S5P_CIIMGEFF);
369}
370
371static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
372{
373 struct fimc_dev *dev = ctx->fimc_dev;
374 struct fimc_frame *frame = &ctx->s_frame;
375 u32 cfg_o = 0;
376 u32 cfg_r = 0;
377
378 if (FIMC_LCDFIFO == ctx->out_path)
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300379 cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300380
381 cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
382 cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
383 cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
384 cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
385
386 writel(cfg_o, dev->regs + S5P_ORGISIZE);
387 writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
388}
389
390void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
391{
392 struct fimc_dev *dev = ctx->fimc_dev;
393 struct fimc_frame *frame = &ctx->s_frame;
394 struct fimc_dma_offset *offset = &frame->dma_offset;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300395 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300396
397 /* Set the pixel offsets. */
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300398 cfg = S5P_CIO_OFFS_HOR(offset->y_h);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300399 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
400 writel(cfg, dev->regs + S5P_CIIYOFF);
401
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300402 cfg = S5P_CIO_OFFS_HOR(offset->cb_h);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300403 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
404 writel(cfg, dev->regs + S5P_CIICBOFF);
405
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300406 cfg = S5P_CIO_OFFS_HOR(offset->cr_h);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300407 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
408 writel(cfg, dev->regs + S5P_CIICROFF);
409
410 /* Input original and real size. */
411 fimc_hw_set_in_dma_size(ctx);
412
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300413 /* Use DMA autoload only in FIFO mode. */
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300414 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
415
416 /* Set the input DMA to process single frame only. */
417 cfg = readl(dev->regs + S5P_MSCTRL);
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300418 cfg &= ~(S5P_MSCTRL_INFORMAT_MASK
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300419 | S5P_MSCTRL_IN_BURST_COUNT_MASK
420 | S5P_MSCTRL_INPUT_MASK
421 | S5P_MSCTRL_C_INT_IN_MASK
422 | S5P_MSCTRL_2P_IN_ORDER_MASK);
423
Hyunwoong Kim5bbe425e2010-12-29 07:08:32 -0300424 cfg |= (S5P_MSCTRL_IN_BURST_COUNT(4)
425 | S5P_MSCTRL_INPUT_MEMORY
426 | S5P_MSCTRL_FIFO_CTRL_FULL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300427
428 switch (frame->fmt->color) {
Sylwester Nawrockid9160af2010-12-08 12:48:23 -0300429 case S5P_FIMC_RGB565...S5P_FIMC_RGB888:
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300430 cfg |= S5P_MSCTRL_INFORMAT_RGB;
431 break;
432 case S5P_FIMC_YCBCR420:
433 cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
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 | S5P_MSCTRL_C_INT_IN_2PLANE;
437 else
438 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
439
440 break;
Sylwester Nawrockid9160af2010-12-08 12:48:23 -0300441 case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300442 if (frame->fmt->colplanes == 1) {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300443 cfg |= ctx->in_order_1p
444 | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
445 } else {
446 cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
447
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300448 if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300449 cfg |= ctx->in_order_2p
450 | S5P_MSCTRL_C_INT_IN_2PLANE;
451 else
452 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
453 }
454 break;
455 default:
456 break;
457 }
458
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300459 writel(cfg, dev->regs + S5P_MSCTRL);
460
461 /* Input/output DMA linear/tiled mode. */
462 cfg = readl(dev->regs + S5P_CIDMAPARAM);
463 cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
464
465 if (tiled_fmt(ctx->s_frame.fmt))
466 cfg |= S5P_CIDMAPARAM_R_64X32;
467
468 if (tiled_fmt(ctx->d_frame.fmt))
469 cfg |= S5P_CIDMAPARAM_W_64X32;
470
471 writel(cfg, dev->regs + S5P_CIDMAPARAM);
472}
473
474
475void fimc_hw_set_input_path(struct fimc_ctx *ctx)
476{
477 struct fimc_dev *dev = ctx->fimc_dev;
478
479 u32 cfg = readl(dev->regs + S5P_MSCTRL);
480 cfg &= ~S5P_MSCTRL_INPUT_MASK;
481
482 if (ctx->in_path == FIMC_DMA)
483 cfg |= S5P_MSCTRL_INPUT_MEMORY;
484 else
485 cfg |= S5P_MSCTRL_INPUT_EXTCAM;
486
487 writel(cfg, dev->regs + S5P_MSCTRL);
488}
489
490void fimc_hw_set_output_path(struct fimc_ctx *ctx)
491{
492 struct fimc_dev *dev = ctx->fimc_dev;
493
494 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
495 cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
496 if (ctx->out_path == FIMC_LCDFIFO)
497 cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
498 writel(cfg, dev->regs + S5P_CISCCTRL);
499}
500
501void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
502{
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300503 u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300504 cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
505 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
506
Sylwester Nawrocki77e62082010-09-28 05:49:11 -0300507 writel(paddr->y, dev->regs + S5P_CIIYSA(0));
508 writel(paddr->cb, dev->regs + S5P_CIICBSA(0));
509 writel(paddr->cr, dev->regs + S5P_CIICRSA(0));
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300510
511 cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
512 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
513}
514
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300515void fimc_hw_set_output_addr(struct fimc_dev *dev,
516 struct fimc_addr *paddr, int index)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300517{
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300518 int i = (index == -1) ? 0 : index;
519 do {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300520 writel(paddr->y, dev->regs + S5P_CIOYSA(i));
521 writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
522 writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300523 dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
524 i, paddr->y, paddr->cb, paddr->cr);
525 } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300526}
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300527
528int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300529 struct s5p_fimc_isp_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300530{
531 u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
532
533 cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
534 S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC);
535
536 if (cam->flags & FIMC_CLK_INV_PCLK)
537 cfg |= S5P_CIGCTRL_INVPOLPCLK;
538
539 if (cam->flags & FIMC_CLK_INV_VSYNC)
540 cfg |= S5P_CIGCTRL_INVPOLVSYNC;
541
542 if (cam->flags & FIMC_CLK_INV_HREF)
543 cfg |= S5P_CIGCTRL_INVPOLHREF;
544
545 if (cam->flags & FIMC_CLK_INV_HSYNC)
546 cfg |= S5P_CIGCTRL_INVPOLHSYNC;
547
548 writel(cfg, fimc->regs + S5P_CIGCTRL);
549
550 return 0;
551}
552
553int fimc_hw_set_camera_source(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300554 struct s5p_fimc_isp_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300555{
556 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
557 u32 cfg = 0;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300558 u32 bus_width;
559 int i;
560
561 static const struct {
562 u32 pixelcode;
563 u32 cisrcfmt;
564 u16 bus_width;
565 } pix_desc[] = {
566 { V4L2_MBUS_FMT_YUYV8_2X8, S5P_CISRCFMT_ORDER422_YCBYCR, 8 },
567 { V4L2_MBUS_FMT_YVYU8_2X8, S5P_CISRCFMT_ORDER422_YCRYCB, 8 },
568 { V4L2_MBUS_FMT_VYUY8_2X8, S5P_CISRCFMT_ORDER422_CRYCBY, 8 },
569 { V4L2_MBUS_FMT_UYVY8_2X8, S5P_CISRCFMT_ORDER422_CBYCRY, 8 },
570 /* TODO: Add pixel codes for 16-bit bus width */
571 };
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300572
573 if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300574 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
575 if (fimc->vid_cap.fmt.code == pix_desc[i].pixelcode) {
576 cfg = pix_desc[i].cisrcfmt;
577 bus_width = pix_desc[i].bus_width;
578 break;
579 }
580 }
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300581
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300582 if (i == ARRAY_SIZE(pix_desc)) {
Sylwester Nawrocki30c99392011-06-10 15:36:48 -0300583 v4l2_err(fimc->vid_cap.vfd,
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300584 "Camera color format not supported: %d\n",
585 fimc->vid_cap.fmt.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300586 return -EINVAL;
587 }
588
589 if (cam->bus_type == FIMC_ITU_601) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300590 if (bus_width == 8)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300591 cfg |= S5P_CISRCFMT_ITU601_8BIT;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300592 else if (bus_width == 16)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300593 cfg |= S5P_CISRCFMT_ITU601_16BIT;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300594 } /* else defaults to ITU-R BT.656 8-bit */
595 }
596
597 cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
598 writel(cfg, fimc->regs + S5P_CISRCFMT);
599 return 0;
600}
601
602
603int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
604{
605 u32 hoff2, voff2;
606
607 u32 cfg = readl(fimc->regs + S5P_CIWDOFST);
608
609 cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK);
610 cfg |= S5P_CIWDOFST_OFF_EN |
611 S5P_CIWDOFST_HOROFF(f->offs_h) |
612 S5P_CIWDOFST_VEROFF(f->offs_v);
613
614 writel(cfg, fimc->regs + S5P_CIWDOFST);
615
616 /* See CIWDOFSTn register description in the datasheet for details. */
617 hoff2 = f->o_width - f->width - f->offs_h;
618 voff2 = f->o_height - f->height - f->offs_v;
619 cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2);
620
621 writel(cfg, fimc->regs + S5P_CIWDOFST2);
622 return 0;
623}
624
625int fimc_hw_set_camera_type(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300626 struct s5p_fimc_isp_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300627{
628 u32 cfg, tmp;
629 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
630
631 cfg = readl(fimc->regs + S5P_CIGCTRL);
632
633 /* Select ITU B interface, disable Writeback path and test pattern. */
634 cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
635 S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
636 S5P_CIGCTRL_SELCAM_MIPI_A);
637
638 if (cam->bus_type == FIMC_MIPI_CSI2) {
639 cfg |= S5P_CIGCTRL_SELCAM_MIPI;
640
641 if (cam->mux_id == 0)
642 cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
643
644 /* TODO: add remaining supported formats. */
645 if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8) {
646 tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
647 } else {
Sylwester Nawrocki30c99392011-06-10 15:36:48 -0300648 v4l2_err(fimc->vid_cap.vfd,
649 "Not supported camera pixel format: %d",
650 vid_cap->fmt.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300651 return -EINVAL;
652 }
Sylwester Nawrockie0eec9a2011-02-21 12:09:01 -0300653 tmp |= (cam->csi_data_align == 32) << 8;
654
655 writel(tmp, fimc->regs + S5P_CSIIMGFMT);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300656
657 } else if (cam->bus_type == FIMC_ITU_601 ||
Sylwester Nawrockie0eec9a2011-02-21 12:09:01 -0300658 cam->bus_type == FIMC_ITU_656) {
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300659 if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
660 cfg |= S5P_CIGCTRL_SELCAM_ITU_A;
661 } else if (cam->bus_type == FIMC_LCD_WB) {
662 cfg |= S5P_CIGCTRL_CAMIF_SELWB;
663 } else {
664 err("invalid camera bus type selected\n");
665 return -EINVAL;
666 }
667 writel(cfg, fimc->regs + S5P_CIGCTRL);
668
669 return 0;
670}