blob: 0806724553a23f9a0a4f1d26a096e12fa2eafb4e [file] [log] [blame]
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -03001/*
2 * Register interface file for Samsung Camera Interface (FIMC) driver
3 *
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -03004 * Copyright (C) 2010 - 2013 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
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030012#include <linux/delay.h>
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -030013#include <linux/io.h>
14#include <linux/regmap.h>
15
Mauro Carvalho Chehabd647f0b2015-11-13 19:40:07 -020016#include <media/drv-intf/exynos-fimc.h>
Sylwester Nawrocki56fa1a62013-03-24 16:54:25 +010017#include "media-dev.h"
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030018
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030019#include "fimc-reg.h"
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030020#include "fimc-core.h"
21
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030022void fimc_hw_reset(struct fimc_dev *dev)
23{
24 u32 cfg;
25
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030026 cfg = readl(dev->regs + FIMC_REG_CISRCFMT);
27 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
28 writel(cfg, dev->regs + FIMC_REG_CISRCFMT);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030029
30 /* Software reset. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030031 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
32 cfg |= (FIMC_REG_CIGCTRL_SWRST | FIMC_REG_CIGCTRL_IRQ_LEVEL);
33 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrockie9e21082011-09-02 06:25:32 -030034 udelay(10);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030035
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030036 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
37 cfg &= ~FIMC_REG_CIGCTRL_SWRST;
38 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -030039
Sylwester Nawrockie80cb1f2013-03-26 08:22:21 -030040 if (dev->drv_data->out_buf_count > 4)
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -030041 fimc_hw_set_dma_seq(dev, 0xF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030042}
43
Sylwester Nawrockiac759342010-12-27 14:47:32 -030044static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030045{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030046 u32 flip = FIMC_REG_MSCTRL_FLIP_NORMAL;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030047
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030048 if (ctx->hflip)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030049 flip = FIMC_REG_MSCTRL_FLIP_Y_MIRROR;
Sylwester Nawrocki1bc05e72012-11-26 11:08:26 -030050 if (ctx->vflip)
51 flip = FIMC_REG_MSCTRL_FLIP_X_MIRROR;
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030052
Sylwester Nawrockiac759342010-12-27 14:47:32 -030053 if (ctx->rotation <= 90)
54 return flip;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030055
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030056 return (flip ^ FIMC_REG_MSCTRL_FLIP_180) & FIMC_REG_MSCTRL_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030057}
58
Sylwester Nawrockiac759342010-12-27 14:47:32 -030059static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030060{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030061 u32 flip = FIMC_REG_CITRGFMT_FLIP_NORMAL;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030062
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030063 if (ctx->hflip)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030064 flip |= FIMC_REG_CITRGFMT_FLIP_Y_MIRROR;
Sylwester Nawrocki1bc05e72012-11-26 11:08:26 -030065 if (ctx->vflip)
66 flip |= FIMC_REG_CITRGFMT_FLIP_X_MIRROR;
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030067
Sylwester Nawrockiac759342010-12-27 14:47:32 -030068 if (ctx->rotation <= 90)
69 return flip;
70
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030071 return (flip ^ FIMC_REG_CITRGFMT_FLIP_180) & FIMC_REG_CITRGFMT_FLIP_180;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -030072}
73
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030074void fimc_hw_set_rotation(struct fimc_ctx *ctx)
75{
76 u32 cfg, flip;
77 struct fimc_dev *dev = ctx->fimc_dev;
78
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030079 cfg = readl(dev->regs + FIMC_REG_CITRGFMT);
80 cfg &= ~(FIMC_REG_CITRGFMT_INROT90 | FIMC_REG_CITRGFMT_OUTROT90 |
81 FIMC_REG_CITRGFMT_FLIP_180);
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030082
83 /*
84 * The input and output rotator cannot work simultaneously.
85 * Use the output rotator in output DMA mode or the input rotator
86 * in direct fifo output mode.
87 */
88 if (ctx->rotation == 90 || ctx->rotation == 270) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -030089 if (ctx->out_path == FIMC_IO_LCDFIFO)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030090 cfg |= FIMC_REG_CITRGFMT_INROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030091 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030092 cfg |= FIMC_REG_CITRGFMT_OUTROT90;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030093 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -030094
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -030095 if (ctx->out_path == FIMC_IO_DMA) {
Sylwester Nawrockiac759342010-12-27 14:47:32 -030096 cfg |= fimc_hw_get_target_flip(ctx);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -030097 writel(cfg, dev->regs + FIMC_REG_CITRGFMT);
Sylwester Nawrockiac759342010-12-27 14:47:32 -030098 } else {
99 /* LCD FIFO path */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300100 flip = readl(dev->regs + FIMC_REG_MSCTRL);
101 flip &= ~FIMC_REG_MSCTRL_FLIP_MASK;
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300102 flip |= fimc_hw_get_in_flip(ctx);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300103 writel(flip, dev->regs + FIMC_REG_MSCTRL);
Sylwester Nawrockiac759342010-12-27 14:47:32 -0300104 }
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300105}
106
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300107void fimc_hw_set_target_format(struct fimc_ctx *ctx)
108{
109 u32 cfg;
110 struct fimc_dev *dev = ctx->fimc_dev;
111 struct fimc_frame *frame = &ctx->d_frame;
112
113 dbg("w= %d, h= %d color: %d", frame->width,
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300114 frame->height, frame->fmt->color);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300115
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300116 cfg = readl(dev->regs + FIMC_REG_CITRGFMT);
117 cfg &= ~(FIMC_REG_CITRGFMT_FMT_MASK | FIMC_REG_CITRGFMT_HSIZE_MASK |
118 FIMC_REG_CITRGFMT_VSIZE_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300119
120 switch (frame->fmt->color) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300121 case FIMC_FMT_RGB444...FIMC_FMT_RGB888:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300122 cfg |= FIMC_REG_CITRGFMT_RGB;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300123 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300124 case FIMC_FMT_YCBCR420:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300125 cfg |= FIMC_REG_CITRGFMT_YCBCR420;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300126 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300127 case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300128 if (frame->fmt->colplanes == 1)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300129 cfg |= FIMC_REG_CITRGFMT_YCBCR422_1P;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300130 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300131 cfg |= FIMC_REG_CITRGFMT_YCBCR422;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300132 break;
133 default:
134 break;
135 }
136
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300137 if (ctx->rotation == 90 || ctx->rotation == 270)
138 cfg |= (frame->height << 16) | frame->width;
139 else
140 cfg |= (frame->width << 16) | frame->height;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300141
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300142 writel(cfg, dev->regs + FIMC_REG_CITRGFMT);
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300143
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300144 cfg = readl(dev->regs + FIMC_REG_CITAREA);
145 cfg &= ~FIMC_REG_CITAREA_MASK;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300146 cfg |= (frame->width * frame->height);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300147 writel(cfg, dev->regs + FIMC_REG_CITAREA);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300148}
149
150static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
151{
152 struct fimc_dev *dev = ctx->fimc_dev;
153 struct fimc_frame *frame = &ctx->d_frame;
Sylwester Nawrocki47654df2010-10-08 05:01:22 -0300154 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300155
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300156 cfg = (frame->f_height << 16) | frame->f_width;
157 writel(cfg, dev->regs + FIMC_REG_ORGOSIZE);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300158
159 /* Select color space conversion equation (HD/SD size).*/
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300160 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300161 if (frame->f_width >= 1280) /* HD */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300162 cfg |= FIMC_REG_CIGCTRL_CSC_ITU601_709;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300163 else /* SD */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300164 cfg &= ~FIMC_REG_CIGCTRL_CSC_ITU601_709;
165 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300166
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300167}
168
169void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
170{
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300171 struct fimc_dev *dev = ctx->fimc_dev;
172 struct fimc_frame *frame = &ctx->d_frame;
173 struct fimc_dma_offset *offset = &frame->dma_offset;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300174 struct fimc_fmt *fmt = frame->fmt;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300175 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300176
177 /* Set the input dma offsets. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300178 cfg = (offset->y_v << 16) | offset->y_h;
179 writel(cfg, dev->regs + FIMC_REG_CIOYOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300180
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300181 cfg = (offset->cb_v << 16) | offset->cb_h;
182 writel(cfg, dev->regs + FIMC_REG_CIOCBOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300183
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300184 cfg = (offset->cr_v << 16) | offset->cr_h;
185 writel(cfg, dev->regs + FIMC_REG_CIOCROFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300186
187 fimc_hw_set_out_dma_size(ctx);
188
189 /* Configure chroma components order. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300190 cfg = readl(dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300191
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300192 cfg &= ~(FIMC_REG_CIOCTRL_ORDER2P_MASK |
193 FIMC_REG_CIOCTRL_ORDER422_MASK |
194 FIMC_REG_CIOCTRL_YCBCR_PLANE_MASK |
195 FIMC_REG_CIOCTRL_RGB16FMT_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300196
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300197 if (fmt->colplanes == 1)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300198 cfg |= ctx->out_order_1p;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300199 else if (fmt->colplanes == 2)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300200 cfg |= ctx->out_order_2p | FIMC_REG_CIOCTRL_YCBCR_2PLANE;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300201 else if (fmt->colplanes == 3)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300202 cfg |= FIMC_REG_CIOCTRL_YCBCR_3PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300203
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300204 if (fmt->color == FIMC_FMT_RGB565)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300205 cfg |= FIMC_REG_CIOCTRL_RGB565;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300206 else if (fmt->color == FIMC_FMT_RGB555)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300207 cfg |= FIMC_REG_CIOCTRL_ARGB1555;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300208 else if (fmt->color == FIMC_FMT_RGB444)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300209 cfg |= FIMC_REG_CIOCTRL_ARGB4444;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300210
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300211 writel(cfg, dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300212}
213
214static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
215{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300216 u32 cfg = readl(dev->regs + FIMC_REG_ORGISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300217 if (enable)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300218 cfg |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300219 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300220 cfg &= ~FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN;
221 writel(cfg, dev->regs + FIMC_REG_ORGISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300222}
223
224void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
225{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300226 u32 cfg = readl(dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300227 if (enable)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300228 cfg |= FIMC_REG_CIOCTRL_LASTIRQ_ENABLE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300229 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300230 cfg &= ~FIMC_REG_CIOCTRL_LASTIRQ_ENABLE;
231 writel(cfg, dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300232}
233
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300234void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300235{
236 struct fimc_dev *dev = ctx->fimc_dev;
237 struct fimc_scaler *sc = &ctx->scaler;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300238 u32 cfg, shfactor;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300239
240 shfactor = 10 - (sc->hfactor + sc->vfactor);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300241 cfg = shfactor << 28;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300242
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300243 cfg |= (sc->pre_hratio << 16) | sc->pre_vratio;
244 writel(cfg, dev->regs + FIMC_REG_CISCPRERATIO);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300245
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300246 cfg = (sc->pre_dst_width << 16) | sc->pre_dst_height;
247 writel(cfg, dev->regs + FIMC_REG_CISCPREDST);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300248}
249
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300250static void fimc_hw_set_scaler(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300251{
252 struct fimc_dev *dev = ctx->fimc_dev;
253 struct fimc_scaler *sc = &ctx->scaler;
254 struct fimc_frame *src_frame = &ctx->s_frame;
255 struct fimc_frame *dst_frame = &ctx->d_frame;
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -0300256
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300257 u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki2c1bb622011-10-05 14:20:45 -0300258
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300259 cfg &= ~(FIMC_REG_CISCCTRL_CSCR2Y_WIDE | FIMC_REG_CISCCTRL_CSCY2R_WIDE |
260 FIMC_REG_CISCCTRL_SCALEUP_H | FIMC_REG_CISCCTRL_SCALEUP_V |
261 FIMC_REG_CISCCTRL_SCALERBYPASS | FIMC_REG_CISCCTRL_ONE2ONE |
262 FIMC_REG_CISCCTRL_INRGB_FMT_MASK | FIMC_REG_CISCCTRL_OUTRGB_FMT_MASK |
263 FIMC_REG_CISCCTRL_INTERLACE | FIMC_REG_CISCCTRL_RGB_EXT);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300264
265 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300266 cfg |= (FIMC_REG_CISCCTRL_CSCR2Y_WIDE |
267 FIMC_REG_CISCCTRL_CSCY2R_WIDE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300268
269 if (!sc->enabled)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300270 cfg |= FIMC_REG_CISCCTRL_SCALERBYPASS;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300271
272 if (sc->scaleup_h)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300273 cfg |= FIMC_REG_CISCCTRL_SCALEUP_H;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300274
275 if (sc->scaleup_v)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300276 cfg |= FIMC_REG_CISCCTRL_SCALEUP_V;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300277
278 if (sc->copy_mode)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300279 cfg |= FIMC_REG_CISCCTRL_ONE2ONE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300280
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300281 if (ctx->in_path == FIMC_IO_DMA) {
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300282 switch (src_frame->fmt->color) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300283 case FIMC_FMT_RGB565:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300284 cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB565;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300285 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300286 case FIMC_FMT_RGB666:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300287 cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB666;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300288 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300289 case FIMC_FMT_RGB888:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300290 cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB888;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300291 break;
292 }
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300293 }
294
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300295 if (ctx->out_path == FIMC_IO_DMA) {
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300296 u32 color = dst_frame->fmt->color;
297
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300298 if (color >= FIMC_FMT_RGB444 && color <= FIMC_FMT_RGB565)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300299 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB565;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300300 else if (color == FIMC_FMT_RGB666)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300301 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB666;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300302 else if (color == FIMC_FMT_RGB888)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300303 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB888;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300304 } else {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300305 cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB888;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300306
307 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300308 cfg |= FIMC_REG_CISCCTRL_INTERLACE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300309 }
310
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300311 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300312}
313
314void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
315{
316 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki405f2302012-08-02 10:27:46 -0300317 const struct fimc_variant *variant = dev->variant;
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300318 struct fimc_scaler *sc = &ctx->scaler;
319 u32 cfg;
320
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300321 dbg("main_hratio= 0x%X main_vratio= 0x%X",
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300322 sc->main_hratio, sc->main_vratio);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300323
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300324 fimc_hw_set_scaler(ctx);
325
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300326 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
327 cfg &= ~(FIMC_REG_CISCCTRL_MHRATIO_MASK |
328 FIMC_REG_CISCCTRL_MVRATIO_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300329
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300330 if (variant->has_mainscaler_ext) {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300331 cfg |= FIMC_REG_CISCCTRL_MHRATIO_EXT(sc->main_hratio);
332 cfg |= FIMC_REG_CISCCTRL_MVRATIO_EXT(sc->main_vratio);
333 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300334
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300335 cfg = readl(dev->regs + FIMC_REG_CIEXTEN);
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300336
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300337 cfg &= ~(FIMC_REG_CIEXTEN_MVRATIO_EXT_MASK |
338 FIMC_REG_CIEXTEN_MHRATIO_EXT_MASK);
339 cfg |= FIMC_REG_CIEXTEN_MHRATIO_EXT(sc->main_hratio);
340 cfg |= FIMC_REG_CIEXTEN_MVRATIO_EXT(sc->main_vratio);
341 writel(cfg, dev->regs + FIMC_REG_CIEXTEN);
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300342 } else {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300343 cfg |= FIMC_REG_CISCCTRL_MHRATIO(sc->main_hratio);
344 cfg |= FIMC_REG_CISCCTRL_MVRATIO(sc->main_vratio);
345 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300346 }
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300347}
348
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300349void fimc_hw_enable_capture(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300350{
351 struct fimc_dev *dev = ctx->fimc_dev;
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300352 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300353
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300354 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
355 cfg |= FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300356
357 if (ctx->scaler.enabled)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300358 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN_SC;
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300359 else
360 cfg &= FIMC_REG_CIIMGCPT_IMGCPTEN_SC;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300361
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300362 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN;
363 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300364}
365
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300366void fimc_hw_disable_capture(struct fimc_dev *dev)
367{
368 u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
369 cfg &= ~(FIMC_REG_CIIMGCPT_IMGCPTEN |
370 FIMC_REG_CIIMGCPT_IMGCPTEN_SC);
371 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
372}
373
Sylwester Nawrocki9448ab72012-04-02 06:41:22 -0300374void fimc_hw_set_effect(struct fimc_ctx *ctx)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300375{
376 struct fimc_dev *dev = ctx->fimc_dev;
377 struct fimc_effect *effect = &ctx->effect;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300378 u32 cfg = 0;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300379
Sylwester Nawrocki9448ab72012-04-02 06:41:22 -0300380 if (effect->type != FIMC_REG_CIIMGEFF_FIN_BYPASS) {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300381 cfg |= FIMC_REG_CIIMGEFF_IE_SC_AFTER |
382 FIMC_REG_CIIMGEFF_IE_ENABLE;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300383 cfg |= effect->type;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300384 if (effect->type == FIMC_REG_CIIMGEFF_FIN_ARBITRARY)
385 cfg |= (effect->pat_cb << 13) | effect->pat_cr;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300386 }
387
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300388 writel(cfg, dev->regs + FIMC_REG_CIIMGEFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300389}
390
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300391void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx)
392{
393 struct fimc_dev *dev = ctx->fimc_dev;
394 struct fimc_frame *frame = &ctx->d_frame;
395 u32 cfg;
396
397 if (!(frame->fmt->flags & FMT_HAS_ALPHA))
398 return;
399
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300400 cfg = readl(dev->regs + FIMC_REG_CIOCTRL);
401 cfg &= ~FIMC_REG_CIOCTRL_ALPHA_OUT_MASK;
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300402 cfg |= (frame->alpha << 4);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300403 writel(cfg, dev->regs + FIMC_REG_CIOCTRL);
Sylwester Nawrockidafb9c72011-12-01 14:02:24 -0300404}
405
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300406static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
407{
408 struct fimc_dev *dev = ctx->fimc_dev;
409 struct fimc_frame *frame = &ctx->s_frame;
410 u32 cfg_o = 0;
411 u32 cfg_r = 0;
412
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300413 if (FIMC_IO_LCDFIFO == ctx->out_path)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300414 cfg_r |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300415
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300416 cfg_o |= (frame->f_height << 16) | frame->f_width;
417 cfg_r |= (frame->height << 16) | frame->width;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300418
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300419 writel(cfg_o, dev->regs + FIMC_REG_ORGISIZE);
420 writel(cfg_r, dev->regs + FIMC_REG_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300421}
422
423void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
424{
425 struct fimc_dev *dev = ctx->fimc_dev;
426 struct fimc_frame *frame = &ctx->s_frame;
427 struct fimc_dma_offset *offset = &frame->dma_offset;
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300428 u32 cfg;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300429
430 /* Set the pixel offsets. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300431 cfg = (offset->y_v << 16) | offset->y_h;
432 writel(cfg, dev->regs + FIMC_REG_CIIYOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300433
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300434 cfg = (offset->cb_v << 16) | offset->cb_h;
435 writel(cfg, dev->regs + FIMC_REG_CIICBOFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300436
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300437 cfg = (offset->cr_v << 16) | offset->cr_h;
438 writel(cfg, dev->regs + FIMC_REG_CIICROFF);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300439
440 /* Input original and real size. */
441 fimc_hw_set_in_dma_size(ctx);
442
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300443 /* Use DMA autoload only in FIFO mode. */
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300444 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_IO_LCDFIFO);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300445
446 /* Set the input DMA to process single frame only. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300447 cfg = readl(dev->regs + FIMC_REG_MSCTRL);
448 cfg &= ~(FIMC_REG_MSCTRL_INFORMAT_MASK
449 | FIMC_REG_MSCTRL_IN_BURST_COUNT_MASK
450 | FIMC_REG_MSCTRL_INPUT_MASK
451 | FIMC_REG_MSCTRL_C_INT_IN_MASK
Sylwester Nawrocki43979792013-03-21 14:22:34 -0300452 | FIMC_REG_MSCTRL_2P_IN_ORDER_MASK
453 | FIMC_REG_MSCTRL_ORDER422_MASK);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300454
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300455 cfg |= (FIMC_REG_MSCTRL_IN_BURST_COUNT(4)
456 | FIMC_REG_MSCTRL_INPUT_MEMORY
457 | FIMC_REG_MSCTRL_FIFO_CTRL_FULL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300458
459 switch (frame->fmt->color) {
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300460 case FIMC_FMT_RGB565...FIMC_FMT_RGB888:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300461 cfg |= FIMC_REG_MSCTRL_INFORMAT_RGB;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300462 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300463 case FIMC_FMT_YCBCR420:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300464 cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR420;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300465
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300466 if (frame->fmt->colplanes == 2)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300467 cfg |= ctx->in_order_2p | FIMC_REG_MSCTRL_C_INT_IN_2PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300468 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300469 cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300470
471 break;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300472 case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422:
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300473 if (frame->fmt->colplanes == 1) {
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300474 cfg |= ctx->in_order_1p
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300475 | FIMC_REG_MSCTRL_INFORMAT_YCBCR422_1P;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300476 } else {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300477 cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR422;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300478
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300479 if (frame->fmt->colplanes == 2)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300480 cfg |= ctx->in_order_2p
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300481 | FIMC_REG_MSCTRL_C_INT_IN_2PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300482 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300483 cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300484 }
485 break;
486 default:
487 break;
488 }
489
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300490 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300491
492 /* Input/output DMA linear/tiled mode. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300493 cfg = readl(dev->regs + FIMC_REG_CIDMAPARAM);
494 cfg &= ~FIMC_REG_CIDMAPARAM_TILE_MASK;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300495
496 if (tiled_fmt(ctx->s_frame.fmt))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300497 cfg |= FIMC_REG_CIDMAPARAM_R_64X32;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300498
499 if (tiled_fmt(ctx->d_frame.fmt))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300500 cfg |= FIMC_REG_CIDMAPARAM_W_64X32;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300501
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300502 writel(cfg, dev->regs + FIMC_REG_CIDMAPARAM);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300503}
504
505
506void fimc_hw_set_input_path(struct fimc_ctx *ctx)
507{
508 struct fimc_dev *dev = ctx->fimc_dev;
509
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300510 u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL);
511 cfg &= ~FIMC_REG_MSCTRL_INPUT_MASK;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300512
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300513 if (ctx->in_path == FIMC_IO_DMA)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300514 cfg |= FIMC_REG_MSCTRL_INPUT_MEMORY;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300515 else
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300516 cfg |= FIMC_REG_MSCTRL_INPUT_EXTCAM;
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300517
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300518 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300519}
520
521void fimc_hw_set_output_path(struct fimc_ctx *ctx)
522{
523 struct fimc_dev *dev = ctx->fimc_dev;
524
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300525 u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
526 cfg &= ~FIMC_REG_CISCCTRL_LCDPATHEN_FIFO;
Sylwester Nawrocki3d112d92012-04-26 06:26:29 -0300527 if (ctx->out_path == FIMC_IO_LCDFIFO)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300528 cfg |= FIMC_REG_CISCCTRL_LCDPATHEN_FIFO;
529 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300530}
531
532void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
533{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300534 u32 cfg = readl(dev->regs + FIMC_REG_CIREAL_ISIZE);
535 cfg |= FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS;
536 writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300537
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300538 writel(paddr->y, dev->regs + FIMC_REG_CIIYSA(0));
539 writel(paddr->cb, dev->regs + FIMC_REG_CIICBSA(0));
540 writel(paddr->cr, dev->regs + FIMC_REG_CIICRSA(0));
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300541
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300542 cfg &= ~FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS;
543 writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300544}
545
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300546void fimc_hw_set_output_addr(struct fimc_dev *dev,
547 struct fimc_addr *paddr, int index)
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300548{
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300549 int i = (index == -1) ? 0 : index;
550 do {
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300551 writel(paddr->y, dev->regs + FIMC_REG_CIOYSA(i));
552 writel(paddr->cb, dev->regs + FIMC_REG_CIOCBSA(i));
553 writel(paddr->cr, dev->regs + FIMC_REG_CIOCRSA(i));
Sylwester Nawrocki548aafc2010-10-08 05:01:14 -0300554 dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
555 i, paddr->y, paddr->cb, paddr->cr);
556 } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
Sylwester Nawrocki5fd8f732010-08-03 09:50:29 -0300557}
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300558
559int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300560 struct fimc_source_info *cam)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300561{
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300562 u32 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300563
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300564 cfg &= ~(FIMC_REG_CIGCTRL_INVPOLPCLK | FIMC_REG_CIGCTRL_INVPOLVSYNC |
565 FIMC_REG_CIGCTRL_INVPOLHREF | FIMC_REG_CIGCTRL_INVPOLHSYNC |
566 FIMC_REG_CIGCTRL_INVPOLFIELD);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300567
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300568 if (cam->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300569 cfg |= FIMC_REG_CIGCTRL_INVPOLPCLK;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300570
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300571 if (cam->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300572 cfg |= FIMC_REG_CIGCTRL_INVPOLVSYNC;
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_INVPOLHREF;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300576
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300577 if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300578 cfg |= FIMC_REG_CIGCTRL_INVPOLHSYNC;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300579
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300580 if (cam->flags & V4L2_MBUS_FIELD_EVEN_LOW)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300581 cfg |= FIMC_REG_CIGCTRL_INVPOLFIELD;
Sylwester Nawrocki12ecf562011-09-19 12:38:35 -0300582
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300583 writel(cfg, fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300584
585 return 0;
586}
587
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300588struct mbus_pixfmt_desc {
589 u32 pixelcode;
590 u32 cisrcfmt;
591 u16 bus_width;
592};
593
594static const struct mbus_pixfmt_desc pix_desc[] = {
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -0300595 { MEDIA_BUS_FMT_YUYV8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCBYCR, 8 },
596 { MEDIA_BUS_FMT_YVYU8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCRYCB, 8 },
597 { MEDIA_BUS_FMT_VYUY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CRYCBY, 8 },
598 { MEDIA_BUS_FMT_UYVY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CBYCRY, 8 },
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300599};
600
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300601int fimc_hw_set_camera_source(struct fimc_dev *fimc,
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300602 struct fimc_source_info *source)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300603{
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300604 struct fimc_vid_cap *vc = &fimc->vid_cap;
605 struct fimc_frame *f = &vc->ctx->s_frame;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300606 u32 bus_width, cfg = 0;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300607 int i;
608
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300609 switch (source->fimc_bus_type) {
610 case FIMC_BUS_TYPE_ITU_601:
611 case FIMC_BUS_TYPE_ITU_656:
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300612 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300613 if (vc->ci_fmt.code == pix_desc[i].pixelcode) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300614 cfg = pix_desc[i].cisrcfmt;
615 bus_width = pix_desc[i].bus_width;
616 break;
617 }
618 }
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300619
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300620 if (i == ARRAY_SIZE(pix_desc)) {
Sylwester Nawrockibc7584b2013-05-31 11:37:18 -0300621 v4l2_err(&vc->ve.vdev,
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300622 "Camera color format not supported: %d\n",
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300623 vc->ci_fmt.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300624 return -EINVAL;
625 }
626
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300627 if (source->fimc_bus_type == FIMC_BUS_TYPE_ITU_601) {
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300628 if (bus_width == 8)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300629 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
Sylwester Nawrocki3d0ce7e2010-12-27 15:02:16 -0300630 else if (bus_width == 16)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300631 cfg |= FIMC_REG_CISRCFMT_ITU601_16BIT;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300632 } /* else defaults to ITU-R BT.656 8-bit */
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300633 break;
634 case FIMC_BUS_TYPE_MIPI_CSI2:
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300635 if (fimc_fmt_is_user_defined(f->fmt->color))
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300636 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300637 break;
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300638 default:
639 case FIMC_BUS_TYPE_ISP_WRITEBACK:
640 /* Anything to do here ? */
641 break;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300642 }
643
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300644 cfg |= (f->o_width << 16) | f->o_height;
645 writel(cfg, fimc->regs + FIMC_REG_CISRCFMT);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300646 return 0;
647}
648
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300649void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300650{
651 u32 hoff2, voff2;
652
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300653 u32 cfg = readl(fimc->regs + FIMC_REG_CIWDOFST);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300654
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300655 cfg &= ~(FIMC_REG_CIWDOFST_HOROFF_MASK | FIMC_REG_CIWDOFST_VEROFF_MASK);
656 cfg |= FIMC_REG_CIWDOFST_OFF_EN |
657 (f->offs_h << 16) | f->offs_v;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300658
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300659 writel(cfg, fimc->regs + FIMC_REG_CIWDOFST);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300660
661 /* See CIWDOFSTn register description in the datasheet for details. */
662 hoff2 = f->o_width - f->width - f->offs_h;
663 voff2 = f->o_height - f->height - f->offs_v;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300664 cfg = (hoff2 << 16) | voff2;
665 writel(cfg, fimc->regs + FIMC_REG_CIWDOFST2);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300666}
667
668int fimc_hw_set_camera_type(struct fimc_dev *fimc,
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300669 struct fimc_source_info *source)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300670{
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300671 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
Sylwester Nawrocki20676a42012-03-21 06:21:30 -0300672 u32 csis_data_alignment = 32;
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300673 u32 cfg, tmp;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300674
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300675 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300676
677 /* Select ITU B interface, disable Writeback path and test pattern. */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300678 cfg &= ~(FIMC_REG_CIGCTRL_TESTPAT_MASK | FIMC_REG_CIGCTRL_SELCAM_ITU_A |
679 FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB |
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300680 FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG |
681 FIMC_REG_CIGCTRL_SELWB_A);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300682
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300683 switch (source->fimc_bus_type) {
684 case FIMC_BUS_TYPE_MIPI_CSI2:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300685 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300686
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300687 if (source->mux_id == 0)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300688 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300689
690 /* TODO: add remaining supported formats. */
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300691 switch (vid_cap->ci_fmt.code) {
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -0300692 case MEDIA_BUS_FMT_VYUY8_2X8:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300693 tmp = FIMC_REG_CSIIMGFMT_YCBCR422_8BIT;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300694 break;
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -0300695 case MEDIA_BUS_FMT_JPEG_1X8:
696 case MEDIA_BUS_FMT_S5C_UYVY_JPEG_1X8:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300697 tmp = FIMC_REG_CSIIMGFMT_USER(1);
698 cfg |= FIMC_REG_CIGCTRL_CAM_JPEG;
Sylwester Nawrockiee7160e2011-08-26 14:57:06 -0300699 break;
700 default:
Sylwester Nawrockibc7584b2013-05-31 11:37:18 -0300701 v4l2_err(&vid_cap->ve.vdev,
Sachin Kamata516d082012-06-12 03:12:26 -0300702 "Not supported camera pixel format: %#x\n",
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300703 vid_cap->ci_fmt.code);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300704 return -EINVAL;
705 }
Sylwester Nawrocki20676a42012-03-21 06:21:30 -0300706 tmp |= (csis_data_alignment == 32) << 8;
Sylwester Nawrockie0eec9a2011-02-21 12:09:01 -0300707
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300708 writel(tmp, fimc->regs + FIMC_REG_CSIIMGFMT);
Sylwester Nawrocki31ce54f2012-07-24 12:06:26 -0300709 break;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300710 case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656:
711 if (source->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300712 cfg |= FIMC_REG_CIGCTRL_SELCAM_ITU_A;
Sylwester Nawrocki31ce54f2012-07-24 12:06:26 -0300713 break;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300714 case FIMC_BUS_TYPE_LCD_WRITEBACK_A:
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300715 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB;
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300716 /* fall through */
717 case FIMC_BUS_TYPE_ISP_WRITEBACK:
718 if (fimc->variant->has_isp_wb)
719 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB;
720 else
721 WARN_ONCE(1, "ISP Writeback input is not supported\n");
Sylwester Nawrocki31ce54f2012-07-24 12:06:26 -0300722 break;
723 default:
Sylwester Nawrockibc7584b2013-05-31 11:37:18 -0300724 v4l2_err(&vid_cap->ve.vdev,
725 "Invalid FIMC bus type selected: %d\n",
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300726 source->fimc_bus_type);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300727 return -EINVAL;
728 }
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300729 writel(cfg, fimc->regs + FIMC_REG_CIGCTRL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300730
731 return 0;
732}
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300733
734void fimc_hw_clear_irq(struct fimc_dev *dev)
735{
736 u32 cfg = readl(dev->regs + FIMC_REG_CIGCTRL);
737 cfg |= FIMC_REG_CIGCTRL_IRQ_CLR;
738 writel(cfg, dev->regs + FIMC_REG_CIGCTRL);
739}
740
741void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on)
742{
743 u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL);
744 if (on)
745 cfg |= FIMC_REG_CISCCTRL_SCALERSTART;
746 else
747 cfg &= ~FIMC_REG_CISCCTRL_SCALERSTART;
748 writel(cfg, dev->regs + FIMC_REG_CISCCTRL);
749}
750
751void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on)
752{
753 u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL);
754 if (on)
755 cfg |= FIMC_REG_MSCTRL_ENVID;
756 else
757 cfg &= ~FIMC_REG_MSCTRL_ENVID;
758 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
759}
760
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300761/* Return an index to the buffer actually being written. */
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300762s32 fimc_hw_get_frame_index(struct fimc_dev *dev)
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300763{
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300764 s32 reg;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300765
Sylwester Nawrockie80cb1f2013-03-26 08:22:21 -0300766 if (dev->drv_data->cistatus2) {
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300767 reg = readl(dev->regs + FIMC_REG_CISTATUS2) & 0x3f;
768 return reg - 1;
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300769 }
770
771 reg = readl(dev->regs + FIMC_REG_CISTATUS);
772
773 return (reg & FIMC_REG_CISTATUS_FRAMECNT_MASK) >>
774 FIMC_REG_CISTATUS_FRAMECNT_SHIFT;
775}
776
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300777/* Return an index to the buffer being written previously. */
778s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev)
779{
780 s32 reg;
781
Sylwester Nawrockie80cb1f2013-03-26 08:22:21 -0300782 if (!dev->drv_data->cistatus2)
Sylwester Nawrocki14783d22012-09-24 11:08:45 -0300783 return -1;
784
785 reg = readl(dev->regs + FIMC_REG_CISTATUS2);
786 return ((reg >> 7) & 0x3f) - 1;
787}
788
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300789/* Locking: the caller holds fimc->slock */
790void fimc_activate_capture(struct fimc_ctx *ctx)
791{
792 fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled);
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300793 fimc_hw_enable_capture(ctx);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300794}
795
796void fimc_deactivate_capture(struct fimc_dev *fimc)
797{
798 fimc_hw_en_lastirq(fimc, true);
Sylwester Nawrocki35f29242012-11-22 14:01:39 -0300799 fimc_hw_disable_capture(fimc);
Sylwester Nawrockic83a1ff2012-05-02 06:14:49 -0300800 fimc_hw_enable_scaler(fimc, false);
801 fimc_hw_en_lastirq(fimc, false);
802}
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300803
804int fimc_hw_camblk_cfg_writeback(struct fimc_dev *fimc)
805{
806 struct regmap *map = fimc->sysreg;
807 unsigned int mask, val, camblk_cfg;
808 int ret;
809
Sylwester Nawrockib3d8b552013-03-31 20:31:02 -0300810 if (map == NULL)
811 return 0;
812
Sylwester Nawrocki88fa8312013-03-20 10:44:39 -0300813 ret = regmap_read(map, SYSREG_CAMBLK, &camblk_cfg);
814 if (ret < 0 || ((camblk_cfg & 0x00700000) >> 20 != 0x3))
815 return ret;
816
817 if (!WARN(fimc->id >= 3, "not supported id: %d\n", fimc->id))
818 val = 0x1 << (fimc->id + 20);
819 else
820 val = 0;
821
822 mask = SYSREG_CAMBLK_FIFORST_ISP | SYSREG_CAMBLK_ISPWB_FULL_EN;
823 ret = regmap_update_bits(map, SYSREG_CAMBLK, mask, val);
824 if (ret < 0)
825 return ret;
826
827 usleep_range(1000, 2000);
828
829 val |= SYSREG_CAMBLK_FIFORST_ISP;
830 ret = regmap_update_bits(map, SYSREG_CAMBLK, mask, val);
831 if (ret < 0)
832 return ret;
833
834 mask = SYSREG_ISPBLK_FIFORST_CAM_BLK;
835 ret = regmap_update_bits(map, SYSREG_ISPBLK, mask, ~mask);
836 if (ret < 0)
837 return ret;
838
839 usleep_range(1000, 2000);
840
841 return regmap_update_bits(map, SYSREG_ISPBLK, mask, mask);
842}