Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1 | /* |
| 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> |
| 16 | |
| 17 | #include "fimc-core.h" |
| 18 | |
| 19 | |
| 20 | void fimc_hw_reset(struct fimc_dev *dev) |
| 21 | { |
| 22 | u32 cfg; |
| 23 | |
| 24 | cfg = readl(dev->regs + S5P_CISRCFMT); |
| 25 | cfg |= S5P_CISRCFMT_ITU601_8BIT; |
| 26 | writel(cfg, dev->regs + S5P_CISRCFMT); |
| 27 | |
| 28 | /* Software reset. */ |
| 29 | cfg = readl(dev->regs + S5P_CIGCTRL); |
| 30 | cfg |= (S5P_CIGCTRL_SWRST | S5P_CIGCTRL_IRQ_LEVEL); |
| 31 | writel(cfg, dev->regs + S5P_CIGCTRL); |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 32 | udelay(1000); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 33 | |
| 34 | cfg = readl(dev->regs + S5P_CIGCTRL); |
| 35 | cfg &= ~S5P_CIGCTRL_SWRST; |
| 36 | writel(cfg, dev->regs + S5P_CIGCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static u32 fimc_hw_get_in_flip(u32 ctx_flip) |
| 40 | { |
| 41 | u32 flip = S5P_MSCTRL_FLIP_NORMAL; |
| 42 | |
| 43 | switch (ctx_flip) { |
| 44 | case FLIP_X_AXIS: |
| 45 | flip = S5P_MSCTRL_FLIP_X_MIRROR; |
| 46 | break; |
| 47 | case FLIP_Y_AXIS: |
| 48 | flip = S5P_MSCTRL_FLIP_Y_MIRROR; |
| 49 | break; |
| 50 | case FLIP_XY_AXIS: |
| 51 | flip = S5P_MSCTRL_FLIP_180; |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | return flip; |
| 56 | } |
| 57 | |
| 58 | static u32 fimc_hw_get_target_flip(u32 ctx_flip) |
| 59 | { |
| 60 | u32 flip = S5P_CITRGFMT_FLIP_NORMAL; |
| 61 | |
| 62 | switch (ctx_flip) { |
| 63 | case FLIP_X_AXIS: |
| 64 | flip = S5P_CITRGFMT_FLIP_X_MIRROR; |
| 65 | break; |
| 66 | case FLIP_Y_AXIS: |
| 67 | flip = S5P_CITRGFMT_FLIP_Y_MIRROR; |
| 68 | break; |
| 69 | case FLIP_XY_AXIS: |
| 70 | flip = S5P_CITRGFMT_FLIP_180; |
| 71 | break; |
| 72 | case FLIP_NONE: |
| 73 | break; |
| 74 | |
| 75 | } |
| 76 | return flip; |
| 77 | } |
| 78 | |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame^] | 79 | void fimc_hw_set_rotation(struct fimc_ctx *ctx) |
| 80 | { |
| 81 | u32 cfg, flip; |
| 82 | struct fimc_dev *dev = ctx->fimc_dev; |
| 83 | |
| 84 | cfg = readl(dev->regs + S5P_CITRGFMT); |
| 85 | cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90 | |
| 86 | S5P_CITRGFMT_FLIP_180); |
| 87 | |
| 88 | flip = readl(dev->regs + S5P_MSCTRL); |
| 89 | flip &= ~S5P_MSCTRL_FLIP_MASK; |
| 90 | |
| 91 | /* |
| 92 | * The input and output rotator cannot work simultaneously. |
| 93 | * Use the output rotator in output DMA mode or the input rotator |
| 94 | * in direct fifo output mode. |
| 95 | */ |
| 96 | if (ctx->rotation == 90 || ctx->rotation == 270) { |
| 97 | if (ctx->out_path == FIMC_LCDFIFO) { |
| 98 | cfg |= S5P_CITRGFMT_INROT90; |
| 99 | if (ctx->rotation == 270) |
| 100 | flip |= S5P_MSCTRL_FLIP_180; |
| 101 | } else { |
| 102 | cfg |= S5P_CITRGFMT_OUTROT90; |
| 103 | if (ctx->rotation == 270) |
| 104 | cfg |= S5P_CITRGFMT_FLIP_180; |
| 105 | } |
| 106 | } else if (ctx->rotation == 180) { |
| 107 | if (ctx->out_path == FIMC_LCDFIFO) |
| 108 | flip |= S5P_MSCTRL_FLIP_180; |
| 109 | else |
| 110 | cfg |= S5P_CITRGFMT_FLIP_180; |
| 111 | } |
| 112 | if (ctx->rotation == 180 || ctx->rotation == 270) |
| 113 | writel(flip, dev->regs + S5P_MSCTRL); |
| 114 | |
| 115 | cfg |= fimc_hw_get_target_flip(ctx->flip); |
| 116 | writel(cfg, dev->regs + S5P_CITRGFMT); |
| 117 | } |
| 118 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 119 | void 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) { |
| 133 | case S5P_FIMC_RGB565: |
| 134 | case S5P_FIMC_RGB666: |
| 135 | case S5P_FIMC_RGB888: |
| 136 | cfg |= S5P_CITRGFMT_RGB; |
| 137 | break; |
| 138 | case S5P_FIMC_YCBCR420: |
| 139 | cfg |= S5P_CITRGFMT_YCBCR420; |
| 140 | break; |
| 141 | case S5P_FIMC_YCBYCR422: |
| 142 | case S5P_FIMC_YCRYCB422: |
| 143 | case S5P_FIMC_CBYCRY422: |
| 144 | case S5P_FIMC_CRYCBY422: |
| 145 | if (frame->fmt->planes_cnt == 1) |
| 146 | cfg |= S5P_CITRGFMT_YCBCR422_1P; |
| 147 | else |
| 148 | cfg |= S5P_CITRGFMT_YCBCR422; |
| 149 | break; |
| 150 | default: |
| 151 | break; |
| 152 | } |
| 153 | |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame^] | 154 | if (ctx->rotation == 90 || ctx->rotation == 270) { |
| 155 | cfg |= S5P_CITRGFMT_HSIZE(frame->height); |
| 156 | cfg |= S5P_CITRGFMT_VSIZE(frame->width); |
| 157 | } else { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 158 | |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame^] | 159 | cfg |= S5P_CITRGFMT_HSIZE(frame->width); |
| 160 | cfg |= S5P_CITRGFMT_VSIZE(frame->height); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 161 | } |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame^] | 162 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 163 | writel(cfg, dev->regs + S5P_CITRGFMT); |
| 164 | |
| 165 | cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK; |
| 166 | cfg |= (frame->width * frame->height); |
| 167 | writel(cfg, dev->regs + S5P_CITAREA); |
| 168 | } |
| 169 | |
| 170 | static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx) |
| 171 | { |
| 172 | struct fimc_dev *dev = ctx->fimc_dev; |
| 173 | struct fimc_frame *frame = &ctx->d_frame; |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame^] | 174 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 175 | |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame^] | 176 | cfg = S5P_ORIG_SIZE_HOR(frame->f_width); |
| 177 | cfg |= S5P_ORIG_SIZE_VER(frame->f_height); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 178 | writel(cfg, dev->regs + S5P_ORGOSIZE); |
| 179 | } |
| 180 | |
| 181 | void fimc_hw_set_out_dma(struct fimc_ctx *ctx) |
| 182 | { |
| 183 | u32 cfg; |
| 184 | struct fimc_dev *dev = ctx->fimc_dev; |
| 185 | struct fimc_frame *frame = &ctx->d_frame; |
| 186 | struct fimc_dma_offset *offset = &frame->dma_offset; |
| 187 | |
| 188 | /* Set the input dma offsets. */ |
| 189 | cfg = 0; |
| 190 | cfg |= S5P_CIO_OFFS_HOR(offset->y_h); |
| 191 | cfg |= S5P_CIO_OFFS_VER(offset->y_v); |
| 192 | writel(cfg, dev->regs + S5P_CIOYOFF); |
| 193 | |
| 194 | cfg = 0; |
| 195 | cfg |= S5P_CIO_OFFS_HOR(offset->cb_h); |
| 196 | cfg |= S5P_CIO_OFFS_VER(offset->cb_v); |
| 197 | writel(cfg, dev->regs + S5P_CIOCBOFF); |
| 198 | |
| 199 | cfg = 0; |
| 200 | cfg |= S5P_CIO_OFFS_HOR(offset->cr_h); |
| 201 | cfg |= S5P_CIO_OFFS_VER(offset->cr_v); |
| 202 | writel(cfg, dev->regs + S5P_CIOCROFF); |
| 203 | |
| 204 | fimc_hw_set_out_dma_size(ctx); |
| 205 | |
| 206 | /* Configure chroma components order. */ |
| 207 | cfg = readl(dev->regs + S5P_CIOCTRL); |
| 208 | |
| 209 | cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK | |
| 210 | S5P_CIOCTRL_YCBCR_PLANE_MASK); |
| 211 | |
| 212 | if (frame->fmt->planes_cnt == 1) |
| 213 | cfg |= ctx->out_order_1p; |
| 214 | else if (frame->fmt->planes_cnt == 2) |
| 215 | cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE; |
| 216 | else if (frame->fmt->planes_cnt == 3) |
| 217 | cfg |= S5P_CIOCTRL_YCBCR_3PLANE; |
| 218 | |
| 219 | writel(cfg, dev->regs + S5P_CIOCTRL); |
| 220 | } |
| 221 | |
| 222 | static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable) |
| 223 | { |
| 224 | u32 cfg = readl(dev->regs + S5P_ORGISIZE); |
| 225 | if (enable) |
| 226 | cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN; |
| 227 | else |
| 228 | cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN; |
| 229 | writel(cfg, dev->regs + S5P_ORGISIZE); |
| 230 | } |
| 231 | |
| 232 | void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable) |
| 233 | { |
| 234 | unsigned long flags; |
| 235 | u32 cfg; |
| 236 | |
| 237 | spin_lock_irqsave(&dev->slock, flags); |
| 238 | |
| 239 | cfg = readl(dev->regs + S5P_CIOCTRL); |
| 240 | if (enable) |
| 241 | cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE; |
| 242 | else |
| 243 | cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE; |
| 244 | writel(cfg, dev->regs + S5P_CIOCTRL); |
| 245 | |
| 246 | spin_unlock_irqrestore(&dev->slock, flags); |
| 247 | } |
| 248 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 249 | static void fimc_hw_set_prescaler(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 250 | { |
| 251 | struct fimc_dev *dev = ctx->fimc_dev; |
| 252 | struct fimc_scaler *sc = &ctx->scaler; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 253 | u32 cfg, shfactor; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 254 | |
| 255 | shfactor = 10 - (sc->hfactor + sc->vfactor); |
| 256 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 257 | cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 258 | cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio); |
| 259 | cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio); |
| 260 | writel(cfg, dev->regs + S5P_CISCPRERATIO); |
| 261 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 262 | cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 263 | cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height); |
| 264 | writel(cfg, dev->regs + S5P_CISCPREDST); |
| 265 | } |
| 266 | |
| 267 | void fimc_hw_set_scaler(struct fimc_ctx *ctx) |
| 268 | { |
| 269 | struct fimc_dev *dev = ctx->fimc_dev; |
| 270 | struct fimc_scaler *sc = &ctx->scaler; |
| 271 | struct fimc_frame *src_frame = &ctx->s_frame; |
| 272 | struct fimc_frame *dst_frame = &ctx->d_frame; |
| 273 | u32 cfg = 0; |
| 274 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 275 | fimc_hw_set_prescaler(ctx); |
| 276 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 277 | if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW)) |
| 278 | cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE); |
| 279 | |
| 280 | if (!sc->enabled) |
| 281 | cfg |= S5P_CISCCTRL_SCALERBYPASS; |
| 282 | |
| 283 | if (sc->scaleup_h) |
| 284 | cfg |= S5P_CISCCTRL_SCALEUP_H; |
| 285 | |
| 286 | if (sc->scaleup_v) |
| 287 | cfg |= S5P_CISCCTRL_SCALEUP_V; |
| 288 | |
| 289 | if (sc->copy_mode) |
| 290 | cfg |= S5P_CISCCTRL_ONE2ONE; |
| 291 | |
| 292 | |
| 293 | if (ctx->in_path == FIMC_DMA) { |
| 294 | if (src_frame->fmt->color == S5P_FIMC_RGB565) |
| 295 | cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565; |
| 296 | else if (src_frame->fmt->color == S5P_FIMC_RGB666) |
| 297 | cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666; |
| 298 | else if (src_frame->fmt->color == S5P_FIMC_RGB888) |
| 299 | cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888; |
| 300 | } |
| 301 | |
| 302 | if (ctx->out_path == FIMC_DMA) { |
| 303 | if (dst_frame->fmt->color == S5P_FIMC_RGB565) |
| 304 | cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565; |
| 305 | else if (dst_frame->fmt->color == S5P_FIMC_RGB666) |
| 306 | cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666; |
| 307 | else if (dst_frame->fmt->color == S5P_FIMC_RGB888) |
| 308 | cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888; |
| 309 | } else { |
| 310 | cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888; |
| 311 | |
| 312 | if (ctx->flags & FIMC_SCAN_MODE_INTERLACED) |
| 313 | cfg |= S5P_CISCCTRL_INTERLACE; |
| 314 | } |
| 315 | |
| 316 | dbg("main_hratio= 0x%X main_vratio= 0x%X", |
| 317 | sc->main_hratio, sc->main_vratio); |
| 318 | |
| 319 | cfg |= S5P_CISCCTRL_SC_HORRATIO(sc->main_hratio); |
| 320 | cfg |= S5P_CISCCTRL_SC_VERRATIO(sc->main_vratio); |
| 321 | |
| 322 | writel(cfg, dev->regs + S5P_CISCCTRL); |
| 323 | } |
| 324 | |
| 325 | void fimc_hw_en_capture(struct fimc_ctx *ctx) |
| 326 | { |
| 327 | struct fimc_dev *dev = ctx->fimc_dev; |
| 328 | u32 cfg; |
| 329 | |
| 330 | cfg = readl(dev->regs + S5P_CIIMGCPT); |
| 331 | /* One shot mode for output DMA or freerun for FIFO. */ |
| 332 | if (ctx->out_path == FIMC_DMA) |
| 333 | cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE; |
| 334 | else |
| 335 | cfg &= ~S5P_CIIMGCPT_CPT_FREN_ENABLE; |
| 336 | |
| 337 | if (ctx->scaler.enabled) |
| 338 | cfg |= S5P_CIIMGCPT_IMGCPTEN_SC; |
| 339 | |
| 340 | writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT); |
| 341 | } |
| 342 | |
| 343 | void fimc_hw_set_effect(struct fimc_ctx *ctx) |
| 344 | { |
| 345 | struct fimc_dev *dev = ctx->fimc_dev; |
| 346 | struct fimc_effect *effect = &ctx->effect; |
| 347 | u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER); |
| 348 | |
| 349 | cfg |= effect->type; |
| 350 | |
| 351 | if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) { |
| 352 | cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb); |
| 353 | cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr); |
| 354 | } |
| 355 | |
| 356 | writel(cfg, dev->regs + S5P_CIIMGEFF); |
| 357 | } |
| 358 | |
| 359 | static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx) |
| 360 | { |
| 361 | struct fimc_dev *dev = ctx->fimc_dev; |
| 362 | struct fimc_frame *frame = &ctx->s_frame; |
| 363 | u32 cfg_o = 0; |
| 364 | u32 cfg_r = 0; |
| 365 | |
| 366 | if (FIMC_LCDFIFO == ctx->out_path) |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 367 | cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 368 | |
| 369 | cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width); |
| 370 | cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height); |
| 371 | cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width); |
| 372 | cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height); |
| 373 | |
| 374 | writel(cfg_o, dev->regs + S5P_ORGISIZE); |
| 375 | writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE); |
| 376 | } |
| 377 | |
| 378 | void fimc_hw_set_in_dma(struct fimc_ctx *ctx) |
| 379 | { |
| 380 | struct fimc_dev *dev = ctx->fimc_dev; |
| 381 | struct fimc_frame *frame = &ctx->s_frame; |
| 382 | struct fimc_dma_offset *offset = &frame->dma_offset; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 383 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 384 | |
| 385 | /* Set the pixel offsets. */ |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 386 | cfg = S5P_CIO_OFFS_HOR(offset->y_h); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 387 | cfg |= S5P_CIO_OFFS_VER(offset->y_v); |
| 388 | writel(cfg, dev->regs + S5P_CIIYOFF); |
| 389 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 390 | cfg = S5P_CIO_OFFS_HOR(offset->cb_h); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 391 | cfg |= S5P_CIO_OFFS_VER(offset->cb_v); |
| 392 | writel(cfg, dev->regs + S5P_CIICBOFF); |
| 393 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 394 | cfg = S5P_CIO_OFFS_HOR(offset->cr_h); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 395 | cfg |= S5P_CIO_OFFS_VER(offset->cr_v); |
| 396 | writel(cfg, dev->regs + S5P_CIICROFF); |
| 397 | |
| 398 | /* Input original and real size. */ |
| 399 | fimc_hw_set_in_dma_size(ctx); |
| 400 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 401 | /* Use DMA autoload only in FIFO mode. */ |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 402 | fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO); |
| 403 | |
| 404 | /* Set the input DMA to process single frame only. */ |
| 405 | cfg = readl(dev->regs + S5P_MSCTRL); |
| 406 | cfg &= ~(S5P_MSCTRL_FLIP_MASK |
| 407 | | S5P_MSCTRL_INFORMAT_MASK |
| 408 | | 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 | |
| 413 | cfg |= (S5P_MSCTRL_FRAME_COUNT(1) | S5P_MSCTRL_INPUT_MEMORY); |
| 414 | |
| 415 | switch (frame->fmt->color) { |
| 416 | case S5P_FIMC_RGB565: |
| 417 | case S5P_FIMC_RGB666: |
| 418 | case S5P_FIMC_RGB888: |
| 419 | cfg |= S5P_MSCTRL_INFORMAT_RGB; |
| 420 | break; |
| 421 | case S5P_FIMC_YCBCR420: |
| 422 | cfg |= S5P_MSCTRL_INFORMAT_YCBCR420; |
| 423 | |
| 424 | if (frame->fmt->planes_cnt == 2) |
| 425 | cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE; |
| 426 | else |
| 427 | cfg |= S5P_MSCTRL_C_INT_IN_3PLANE; |
| 428 | |
| 429 | break; |
| 430 | case S5P_FIMC_YCBYCR422: |
| 431 | case S5P_FIMC_YCRYCB422: |
| 432 | case S5P_FIMC_CBYCRY422: |
| 433 | case S5P_FIMC_CRYCBY422: |
| 434 | if (frame->fmt->planes_cnt == 1) { |
| 435 | cfg |= ctx->in_order_1p |
| 436 | | S5P_MSCTRL_INFORMAT_YCBCR422_1P; |
| 437 | } else { |
| 438 | cfg |= S5P_MSCTRL_INFORMAT_YCBCR422; |
| 439 | |
| 440 | if (frame->fmt->planes_cnt == 2) |
| 441 | cfg |= ctx->in_order_2p |
| 442 | | S5P_MSCTRL_C_INT_IN_2PLANE; |
| 443 | else |
| 444 | cfg |= S5P_MSCTRL_C_INT_IN_3PLANE; |
| 445 | } |
| 446 | break; |
| 447 | default: |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Input DMA flip mode (and rotation). |
| 453 | * Do not allow simultaneous rotation and flipping. |
| 454 | */ |
| 455 | if (!ctx->rotation && ctx->out_path == FIMC_LCDFIFO) |
| 456 | cfg |= fimc_hw_get_in_flip(ctx->flip); |
| 457 | |
| 458 | writel(cfg, dev->regs + S5P_MSCTRL); |
| 459 | |
| 460 | /* Input/output DMA linear/tiled mode. */ |
| 461 | cfg = readl(dev->regs + S5P_CIDMAPARAM); |
| 462 | cfg &= ~S5P_CIDMAPARAM_TILE_MASK; |
| 463 | |
| 464 | if (tiled_fmt(ctx->s_frame.fmt)) |
| 465 | cfg |= S5P_CIDMAPARAM_R_64X32; |
| 466 | |
| 467 | if (tiled_fmt(ctx->d_frame.fmt)) |
| 468 | cfg |= S5P_CIDMAPARAM_W_64X32; |
| 469 | |
| 470 | writel(cfg, dev->regs + S5P_CIDMAPARAM); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | void fimc_hw_set_input_path(struct fimc_ctx *ctx) |
| 475 | { |
| 476 | struct fimc_dev *dev = ctx->fimc_dev; |
| 477 | |
| 478 | u32 cfg = readl(dev->regs + S5P_MSCTRL); |
| 479 | cfg &= ~S5P_MSCTRL_INPUT_MASK; |
| 480 | |
| 481 | if (ctx->in_path == FIMC_DMA) |
| 482 | cfg |= S5P_MSCTRL_INPUT_MEMORY; |
| 483 | else |
| 484 | cfg |= S5P_MSCTRL_INPUT_EXTCAM; |
| 485 | |
| 486 | writel(cfg, dev->regs + S5P_MSCTRL); |
| 487 | } |
| 488 | |
| 489 | void fimc_hw_set_output_path(struct fimc_ctx *ctx) |
| 490 | { |
| 491 | struct fimc_dev *dev = ctx->fimc_dev; |
| 492 | |
| 493 | u32 cfg = readl(dev->regs + S5P_CISCCTRL); |
| 494 | cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO; |
| 495 | if (ctx->out_path == FIMC_LCDFIFO) |
| 496 | cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO; |
| 497 | writel(cfg, dev->regs + S5P_CISCCTRL); |
| 498 | } |
| 499 | |
| 500 | void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr) |
| 501 | { |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 502 | u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 503 | cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS; |
| 504 | writel(cfg, dev->regs + S5P_CIREAL_ISIZE); |
| 505 | |
Sylwester Nawrocki | 77e6208 | 2010-09-28 05:49:11 -0300 | [diff] [blame] | 506 | writel(paddr->y, dev->regs + S5P_CIIYSA(0)); |
| 507 | writel(paddr->cb, dev->regs + S5P_CIICBSA(0)); |
| 508 | writel(paddr->cr, dev->regs + S5P_CIICRSA(0)); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 509 | |
| 510 | cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS; |
| 511 | writel(cfg, dev->regs + S5P_CIREAL_ISIZE); |
| 512 | } |
| 513 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 514 | void fimc_hw_set_output_addr(struct fimc_dev *dev, |
| 515 | struct fimc_addr *paddr, int index) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 516 | { |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 517 | int i = (index == -1) ? 0 : index; |
| 518 | do { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 519 | writel(paddr->y, dev->regs + S5P_CIOYSA(i)); |
| 520 | writel(paddr->cb, dev->regs + S5P_CIOCBSA(i)); |
| 521 | writel(paddr->cr, dev->regs + S5P_CIOCRSA(i)); |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 522 | dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X", |
| 523 | i, paddr->y, paddr->cb, paddr->cr); |
| 524 | } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 525 | } |