Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Register interface file for Samsung Camera Interface (FIMC) driver |
| 3 | * |
Sylwester Nawrocki | 0c9204d | 2012-04-25 06:55:42 -0300 | [diff] [blame] | 4 | * Copyright (C) 2010 - 2012 Samsung Electronics Co., Ltd. |
| 5 | * Sylwester Nawrocki, <s.nawrocki@samsung.com> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/delay.h> |
Sylwester Nawrocki | df7e09a | 2010-12-27 14:42:15 -0300 | [diff] [blame] | 14 | #include <media/s5p_fimc.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 15 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 16 | #include "fimc-reg.h" |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 17 | #include "fimc-core.h" |
| 18 | |
| 19 | |
| 20 | void fimc_hw_reset(struct fimc_dev *dev) |
| 21 | { |
| 22 | u32 cfg; |
| 23 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 24 | cfg = readl(dev->regs + FIMC_REG_CISRCFMT); |
| 25 | cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; |
| 26 | writel(cfg, dev->regs + FIMC_REG_CISRCFMT); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 27 | |
| 28 | /* Software reset. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 29 | cfg = readl(dev->regs + FIMC_REG_CIGCTRL); |
| 30 | cfg |= (FIMC_REG_CIGCTRL_SWRST | FIMC_REG_CIGCTRL_IRQ_LEVEL); |
| 31 | writel(cfg, dev->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 32 | udelay(10); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 33 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 34 | cfg = readl(dev->regs + FIMC_REG_CIGCTRL); |
| 35 | cfg &= ~FIMC_REG_CIGCTRL_SWRST; |
| 36 | writel(cfg, dev->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 2c1bb62 | 2011-10-05 14:20:45 -0300 | [diff] [blame] | 37 | |
| 38 | if (dev->variant->out_buf_count > 4) |
| 39 | fimc_hw_set_dma_seq(dev, 0xF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 40 | } |
| 41 | |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 42 | static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 43 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 44 | u32 flip = FIMC_REG_MSCTRL_FLIP_NORMAL; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 45 | |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 46 | if (ctx->hflip) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 47 | flip = FIMC_REG_MSCTRL_FLIP_Y_MIRROR; |
Sylwester Nawrocki | 1bc05e7 | 2012-11-26 11:08:26 -0300 | [diff] [blame^] | 48 | if (ctx->vflip) |
| 49 | flip = FIMC_REG_MSCTRL_FLIP_X_MIRROR; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 50 | |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 51 | if (ctx->rotation <= 90) |
| 52 | return flip; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 53 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 54 | return (flip ^ FIMC_REG_MSCTRL_FLIP_180) & FIMC_REG_MSCTRL_FLIP_180; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 55 | } |
| 56 | |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 57 | static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 58 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 59 | u32 flip = FIMC_REG_CITRGFMT_FLIP_NORMAL; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 60 | |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 61 | if (ctx->hflip) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 62 | flip |= FIMC_REG_CITRGFMT_FLIP_Y_MIRROR; |
Sylwester Nawrocki | 1bc05e7 | 2012-11-26 11:08:26 -0300 | [diff] [blame^] | 63 | if (ctx->vflip) |
| 64 | flip |= FIMC_REG_CITRGFMT_FLIP_X_MIRROR; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 65 | |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 66 | if (ctx->rotation <= 90) |
| 67 | return flip; |
| 68 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 69 | return (flip ^ FIMC_REG_CITRGFMT_FLIP_180) & FIMC_REG_CITRGFMT_FLIP_180; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 70 | } |
| 71 | |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 72 | void fimc_hw_set_rotation(struct fimc_ctx *ctx) |
| 73 | { |
| 74 | u32 cfg, flip; |
| 75 | struct fimc_dev *dev = ctx->fimc_dev; |
| 76 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 77 | cfg = readl(dev->regs + FIMC_REG_CITRGFMT); |
| 78 | cfg &= ~(FIMC_REG_CITRGFMT_INROT90 | FIMC_REG_CITRGFMT_OUTROT90 | |
| 79 | FIMC_REG_CITRGFMT_FLIP_180); |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * The input and output rotator cannot work simultaneously. |
| 83 | * Use the output rotator in output DMA mode or the input rotator |
| 84 | * in direct fifo output mode. |
| 85 | */ |
| 86 | if (ctx->rotation == 90 || ctx->rotation == 270) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 87 | if (ctx->out_path == FIMC_IO_LCDFIFO) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 88 | cfg |= FIMC_REG_CITRGFMT_INROT90; |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 89 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 90 | cfg |= FIMC_REG_CITRGFMT_OUTROT90; |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 91 | } |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 92 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 93 | if (ctx->out_path == FIMC_IO_DMA) { |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 94 | cfg |= fimc_hw_get_target_flip(ctx); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 95 | writel(cfg, dev->regs + FIMC_REG_CITRGFMT); |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 96 | } else { |
| 97 | /* LCD FIFO path */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 98 | flip = readl(dev->regs + FIMC_REG_MSCTRL); |
| 99 | flip &= ~FIMC_REG_MSCTRL_FLIP_MASK; |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 100 | flip |= fimc_hw_get_in_flip(ctx); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 101 | writel(flip, dev->regs + FIMC_REG_MSCTRL); |
Sylwester Nawrocki | ac75934 | 2010-12-27 14:47:32 -0300 | [diff] [blame] | 102 | } |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 103 | } |
| 104 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 105 | void fimc_hw_set_target_format(struct fimc_ctx *ctx) |
| 106 | { |
| 107 | u32 cfg; |
| 108 | struct fimc_dev *dev = ctx->fimc_dev; |
| 109 | struct fimc_frame *frame = &ctx->d_frame; |
| 110 | |
| 111 | dbg("w= %d, h= %d color: %d", frame->width, |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 112 | frame->height, frame->fmt->color); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 113 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 114 | cfg = readl(dev->regs + FIMC_REG_CITRGFMT); |
| 115 | cfg &= ~(FIMC_REG_CITRGFMT_FMT_MASK | FIMC_REG_CITRGFMT_HSIZE_MASK | |
| 116 | FIMC_REG_CITRGFMT_VSIZE_MASK); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 117 | |
| 118 | switch (frame->fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 119 | case FIMC_FMT_RGB444...FIMC_FMT_RGB888: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 120 | cfg |= FIMC_REG_CITRGFMT_RGB; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 121 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 122 | case FIMC_FMT_YCBCR420: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 123 | cfg |= FIMC_REG_CITRGFMT_YCBCR420; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 124 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 125 | case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422: |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 126 | if (frame->fmt->colplanes == 1) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 127 | cfg |= FIMC_REG_CITRGFMT_YCBCR422_1P; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 128 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 129 | cfg |= FIMC_REG_CITRGFMT_YCBCR422; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 130 | break; |
| 131 | default: |
| 132 | break; |
| 133 | } |
| 134 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 135 | if (ctx->rotation == 90 || ctx->rotation == 270) |
| 136 | cfg |= (frame->height << 16) | frame->width; |
| 137 | else |
| 138 | cfg |= (frame->width << 16) | frame->height; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 139 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 140 | writel(cfg, dev->regs + FIMC_REG_CITRGFMT); |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 141 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 142 | cfg = readl(dev->regs + FIMC_REG_CITAREA); |
| 143 | cfg &= ~FIMC_REG_CITAREA_MASK; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 144 | cfg |= (frame->width * frame->height); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 145 | writel(cfg, dev->regs + FIMC_REG_CITAREA); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx) |
| 149 | { |
| 150 | struct fimc_dev *dev = ctx->fimc_dev; |
| 151 | struct fimc_frame *frame = &ctx->d_frame; |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 152 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 153 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 154 | cfg = (frame->f_height << 16) | frame->f_width; |
| 155 | writel(cfg, dev->regs + FIMC_REG_ORGOSIZE); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 156 | |
| 157 | /* Select color space conversion equation (HD/SD size).*/ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 158 | cfg = readl(dev->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 159 | if (frame->f_width >= 1280) /* HD */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 160 | cfg |= FIMC_REG_CIGCTRL_CSC_ITU601_709; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 161 | else /* SD */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 162 | cfg &= ~FIMC_REG_CIGCTRL_CSC_ITU601_709; |
| 163 | writel(cfg, dev->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 164 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void fimc_hw_set_out_dma(struct fimc_ctx *ctx) |
| 168 | { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 169 | struct fimc_dev *dev = ctx->fimc_dev; |
| 170 | struct fimc_frame *frame = &ctx->d_frame; |
| 171 | struct fimc_dma_offset *offset = &frame->dma_offset; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 172 | struct fimc_fmt *fmt = frame->fmt; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 173 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 174 | |
| 175 | /* Set the input dma offsets. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 176 | cfg = (offset->y_v << 16) | offset->y_h; |
| 177 | writel(cfg, dev->regs + FIMC_REG_CIOYOFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 178 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 179 | cfg = (offset->cb_v << 16) | offset->cb_h; |
| 180 | writel(cfg, dev->regs + FIMC_REG_CIOCBOFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 181 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 182 | cfg = (offset->cr_v << 16) | offset->cr_h; |
| 183 | writel(cfg, dev->regs + FIMC_REG_CIOCROFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 184 | |
| 185 | fimc_hw_set_out_dma_size(ctx); |
| 186 | |
| 187 | /* Configure chroma components order. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 188 | cfg = readl(dev->regs + FIMC_REG_CIOCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 189 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 190 | cfg &= ~(FIMC_REG_CIOCTRL_ORDER2P_MASK | |
| 191 | FIMC_REG_CIOCTRL_ORDER422_MASK | |
| 192 | FIMC_REG_CIOCTRL_YCBCR_PLANE_MASK | |
| 193 | FIMC_REG_CIOCTRL_RGB16FMT_MASK); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 194 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 195 | if (fmt->colplanes == 1) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 196 | cfg |= ctx->out_order_1p; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 197 | else if (fmt->colplanes == 2) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 198 | cfg |= ctx->out_order_2p | FIMC_REG_CIOCTRL_YCBCR_2PLANE; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 199 | else if (fmt->colplanes == 3) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 200 | cfg |= FIMC_REG_CIOCTRL_YCBCR_3PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 201 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 202 | if (fmt->color == FIMC_FMT_RGB565) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 203 | cfg |= FIMC_REG_CIOCTRL_RGB565; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 204 | else if (fmt->color == FIMC_FMT_RGB555) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 205 | cfg |= FIMC_REG_CIOCTRL_ARGB1555; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 206 | else if (fmt->color == FIMC_FMT_RGB444) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 207 | cfg |= FIMC_REG_CIOCTRL_ARGB4444; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 208 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 209 | writel(cfg, dev->regs + FIMC_REG_CIOCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable) |
| 213 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 214 | u32 cfg = readl(dev->regs + FIMC_REG_ORGISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 215 | if (enable) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 216 | cfg |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 217 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 218 | cfg &= ~FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN; |
| 219 | writel(cfg, dev->regs + FIMC_REG_ORGISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable) |
| 223 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 224 | u32 cfg = readl(dev->regs + FIMC_REG_CIOCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 225 | if (enable) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 226 | cfg |= FIMC_REG_CIOCTRL_LASTIRQ_ENABLE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 227 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 228 | cfg &= ~FIMC_REG_CIOCTRL_LASTIRQ_ENABLE; |
| 229 | writel(cfg, dev->regs + FIMC_REG_CIOCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 230 | } |
| 231 | |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 232 | void fimc_hw_set_prescaler(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 233 | { |
| 234 | struct fimc_dev *dev = ctx->fimc_dev; |
| 235 | struct fimc_scaler *sc = &ctx->scaler; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 236 | u32 cfg, shfactor; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 237 | |
| 238 | shfactor = 10 - (sc->hfactor + sc->vfactor); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 239 | cfg = shfactor << 28; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 240 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 241 | cfg |= (sc->pre_hratio << 16) | sc->pre_vratio; |
| 242 | writel(cfg, dev->regs + FIMC_REG_CISCPRERATIO); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 243 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 244 | cfg = (sc->pre_dst_width << 16) | sc->pre_dst_height; |
| 245 | writel(cfg, dev->regs + FIMC_REG_CISCPREDST); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 246 | } |
| 247 | |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 248 | static void fimc_hw_set_scaler(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 249 | { |
| 250 | struct fimc_dev *dev = ctx->fimc_dev; |
| 251 | struct fimc_scaler *sc = &ctx->scaler; |
| 252 | struct fimc_frame *src_frame = &ctx->s_frame; |
| 253 | struct fimc_frame *dst_frame = &ctx->d_frame; |
Sylwester Nawrocki | 2c1bb62 | 2011-10-05 14:20:45 -0300 | [diff] [blame] | 254 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 255 | u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL); |
Sylwester Nawrocki | 2c1bb62 | 2011-10-05 14:20:45 -0300 | [diff] [blame] | 256 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 257 | cfg &= ~(FIMC_REG_CISCCTRL_CSCR2Y_WIDE | FIMC_REG_CISCCTRL_CSCY2R_WIDE | |
| 258 | FIMC_REG_CISCCTRL_SCALEUP_H | FIMC_REG_CISCCTRL_SCALEUP_V | |
| 259 | FIMC_REG_CISCCTRL_SCALERBYPASS | FIMC_REG_CISCCTRL_ONE2ONE | |
| 260 | FIMC_REG_CISCCTRL_INRGB_FMT_MASK | FIMC_REG_CISCCTRL_OUTRGB_FMT_MASK | |
| 261 | FIMC_REG_CISCCTRL_INTERLACE | FIMC_REG_CISCCTRL_RGB_EXT); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 262 | |
| 263 | if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 264 | cfg |= (FIMC_REG_CISCCTRL_CSCR2Y_WIDE | |
| 265 | FIMC_REG_CISCCTRL_CSCY2R_WIDE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 266 | |
| 267 | if (!sc->enabled) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 268 | cfg |= FIMC_REG_CISCCTRL_SCALERBYPASS; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 269 | |
| 270 | if (sc->scaleup_h) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 271 | cfg |= FIMC_REG_CISCCTRL_SCALEUP_H; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 272 | |
| 273 | if (sc->scaleup_v) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 274 | cfg |= FIMC_REG_CISCCTRL_SCALEUP_V; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 275 | |
| 276 | if (sc->copy_mode) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 277 | cfg |= FIMC_REG_CISCCTRL_ONE2ONE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 278 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 279 | if (ctx->in_path == FIMC_IO_DMA) { |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 280 | switch (src_frame->fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 281 | case FIMC_FMT_RGB565: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 282 | cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB565; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 283 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 284 | case FIMC_FMT_RGB666: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 285 | cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB666; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 286 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 287 | case FIMC_FMT_RGB888: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 288 | cfg |= FIMC_REG_CISCCTRL_INRGB_FMT_RGB888; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 289 | break; |
| 290 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 291 | } |
| 292 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 293 | if (ctx->out_path == FIMC_IO_DMA) { |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 294 | u32 color = dst_frame->fmt->color; |
| 295 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 296 | if (color >= FIMC_FMT_RGB444 && color <= FIMC_FMT_RGB565) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 297 | cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB565; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 298 | else if (color == FIMC_FMT_RGB666) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 299 | cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB666; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 300 | else if (color == FIMC_FMT_RGB888) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 301 | cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB888; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 302 | } else { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 303 | cfg |= FIMC_REG_CISCCTRL_OUTRGB_FMT_RGB888; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 304 | |
| 305 | if (ctx->flags & FIMC_SCAN_MODE_INTERLACED) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 306 | cfg |= FIMC_REG_CISCCTRL_INTERLACE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 307 | } |
| 308 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 309 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void fimc_hw_set_mainscaler(struct fimc_ctx *ctx) |
| 313 | { |
| 314 | struct fimc_dev *dev = ctx->fimc_dev; |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 315 | struct fimc_variant *variant = dev->variant; |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 316 | struct fimc_scaler *sc = &ctx->scaler; |
| 317 | u32 cfg; |
| 318 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 319 | dbg("main_hratio= 0x%X main_vratio= 0x%X", |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 320 | sc->main_hratio, sc->main_vratio); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 321 | |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 322 | fimc_hw_set_scaler(ctx); |
| 323 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 324 | cfg = readl(dev->regs + FIMC_REG_CISCCTRL); |
| 325 | cfg &= ~(FIMC_REG_CISCCTRL_MHRATIO_MASK | |
| 326 | FIMC_REG_CISCCTRL_MVRATIO_MASK); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 327 | |
Sylwester Nawrocki | 70f66ea | 2010-12-28 11:37:55 -0300 | [diff] [blame] | 328 | if (variant->has_mainscaler_ext) { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 329 | cfg |= FIMC_REG_CISCCTRL_MHRATIO_EXT(sc->main_hratio); |
| 330 | cfg |= FIMC_REG_CISCCTRL_MVRATIO_EXT(sc->main_vratio); |
| 331 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 332 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 333 | cfg = readl(dev->regs + FIMC_REG_CIEXTEN); |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 334 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 335 | cfg &= ~(FIMC_REG_CIEXTEN_MVRATIO_EXT_MASK | |
| 336 | FIMC_REG_CIEXTEN_MHRATIO_EXT_MASK); |
| 337 | cfg |= FIMC_REG_CIEXTEN_MHRATIO_EXT(sc->main_hratio); |
| 338 | cfg |= FIMC_REG_CIEXTEN_MVRATIO_EXT(sc->main_vratio); |
| 339 | writel(cfg, dev->regs + FIMC_REG_CIEXTEN); |
Sylwester Nawrocki | 70f66ea | 2010-12-28 11:37:55 -0300 | [diff] [blame] | 340 | } else { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 341 | cfg |= FIMC_REG_CISCCTRL_MHRATIO(sc->main_hratio); |
| 342 | cfg |= FIMC_REG_CISCCTRL_MVRATIO(sc->main_vratio); |
| 343 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
Sylwester Nawrocki | 70f66ea | 2010-12-28 11:37:55 -0300 | [diff] [blame] | 344 | } |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 345 | } |
| 346 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 347 | void fimc_hw_en_capture(struct fimc_ctx *ctx) |
| 348 | { |
| 349 | struct fimc_dev *dev = ctx->fimc_dev; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 350 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 351 | u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 352 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 353 | if (ctx->out_path == FIMC_IO_DMA) { |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 354 | /* one shot mode */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 355 | cfg |= FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE | |
| 356 | FIMC_REG_CIIMGCPT_IMGCPTEN; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 357 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 358 | /* Continuous frame capture mode (freerun). */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 359 | cfg &= ~(FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE | |
| 360 | FIMC_REG_CIIMGCPT_CPT_FRMOD_CNT); |
| 361 | cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 362 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 363 | |
| 364 | if (ctx->scaler.enabled) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 365 | cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN_SC; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 366 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 367 | cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN; |
| 368 | writel(cfg, dev->regs + FIMC_REG_CIIMGCPT); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 369 | } |
| 370 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 371 | void fimc_hw_set_effect(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 372 | { |
| 373 | struct fimc_dev *dev = ctx->fimc_dev; |
| 374 | struct fimc_effect *effect = &ctx->effect; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 375 | u32 cfg = 0; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 376 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 377 | if (effect->type != FIMC_REG_CIIMGEFF_FIN_BYPASS) { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 378 | cfg |= FIMC_REG_CIIMGEFF_IE_SC_AFTER | |
| 379 | FIMC_REG_CIIMGEFF_IE_ENABLE; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 380 | cfg |= effect->type; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 381 | if (effect->type == FIMC_REG_CIIMGEFF_FIN_ARBITRARY) |
| 382 | cfg |= (effect->pat_cb << 13) | effect->pat_cr; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 383 | } |
| 384 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 385 | writel(cfg, dev->regs + FIMC_REG_CIIMGEFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 386 | } |
| 387 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 388 | void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx) |
| 389 | { |
| 390 | struct fimc_dev *dev = ctx->fimc_dev; |
| 391 | struct fimc_frame *frame = &ctx->d_frame; |
| 392 | u32 cfg; |
| 393 | |
| 394 | if (!(frame->fmt->flags & FMT_HAS_ALPHA)) |
| 395 | return; |
| 396 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 397 | cfg = readl(dev->regs + FIMC_REG_CIOCTRL); |
| 398 | cfg &= ~FIMC_REG_CIOCTRL_ALPHA_OUT_MASK; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 399 | cfg |= (frame->alpha << 4); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 400 | writel(cfg, dev->regs + FIMC_REG_CIOCTRL); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 401 | } |
| 402 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 403 | static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx) |
| 404 | { |
| 405 | struct fimc_dev *dev = ctx->fimc_dev; |
| 406 | struct fimc_frame *frame = &ctx->s_frame; |
| 407 | u32 cfg_o = 0; |
| 408 | u32 cfg_r = 0; |
| 409 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 410 | if (FIMC_IO_LCDFIFO == ctx->out_path) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 411 | cfg_r |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 412 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 413 | cfg_o |= (frame->f_height << 16) | frame->f_width; |
| 414 | cfg_r |= (frame->height << 16) | frame->width; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 415 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 416 | writel(cfg_o, dev->regs + FIMC_REG_ORGISIZE); |
| 417 | writel(cfg_r, dev->regs + FIMC_REG_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void fimc_hw_set_in_dma(struct fimc_ctx *ctx) |
| 421 | { |
| 422 | struct fimc_dev *dev = ctx->fimc_dev; |
| 423 | struct fimc_frame *frame = &ctx->s_frame; |
| 424 | struct fimc_dma_offset *offset = &frame->dma_offset; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 425 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 426 | |
| 427 | /* Set the pixel offsets. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 428 | cfg = (offset->y_v << 16) | offset->y_h; |
| 429 | writel(cfg, dev->regs + FIMC_REG_CIIYOFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 430 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 431 | cfg = (offset->cb_v << 16) | offset->cb_h; |
| 432 | writel(cfg, dev->regs + FIMC_REG_CIICBOFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 433 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 434 | cfg = (offset->cr_v << 16) | offset->cr_h; |
| 435 | writel(cfg, dev->regs + FIMC_REG_CIICROFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 436 | |
| 437 | /* Input original and real size. */ |
| 438 | fimc_hw_set_in_dma_size(ctx); |
| 439 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 440 | /* Use DMA autoload only in FIFO mode. */ |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 441 | fimc_hw_en_autoload(dev, ctx->out_path == FIMC_IO_LCDFIFO); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 442 | |
| 443 | /* Set the input DMA to process single frame only. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 444 | cfg = readl(dev->regs + FIMC_REG_MSCTRL); |
| 445 | cfg &= ~(FIMC_REG_MSCTRL_INFORMAT_MASK |
| 446 | | FIMC_REG_MSCTRL_IN_BURST_COUNT_MASK |
| 447 | | FIMC_REG_MSCTRL_INPUT_MASK |
| 448 | | FIMC_REG_MSCTRL_C_INT_IN_MASK |
| 449 | | FIMC_REG_MSCTRL_2P_IN_ORDER_MASK); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 450 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 451 | cfg |= (FIMC_REG_MSCTRL_IN_BURST_COUNT(4) |
| 452 | | FIMC_REG_MSCTRL_INPUT_MEMORY |
| 453 | | FIMC_REG_MSCTRL_FIFO_CTRL_FULL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 454 | |
| 455 | switch (frame->fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 456 | case FIMC_FMT_RGB565...FIMC_FMT_RGB888: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 457 | cfg |= FIMC_REG_MSCTRL_INFORMAT_RGB; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 458 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 459 | case FIMC_FMT_YCBCR420: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 460 | cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR420; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 461 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 462 | if (frame->fmt->colplanes == 2) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 463 | cfg |= ctx->in_order_2p | FIMC_REG_MSCTRL_C_INT_IN_2PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 464 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 465 | cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 466 | |
| 467 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 468 | case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422: |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 469 | if (frame->fmt->colplanes == 1) { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 470 | cfg |= ctx->in_order_1p |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 471 | | FIMC_REG_MSCTRL_INFORMAT_YCBCR422_1P; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 472 | } else { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 473 | cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR422; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 474 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 475 | if (frame->fmt->colplanes == 2) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 476 | cfg |= ctx->in_order_2p |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 477 | | FIMC_REG_MSCTRL_C_INT_IN_2PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 478 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 479 | cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 480 | } |
| 481 | break; |
| 482 | default: |
| 483 | break; |
| 484 | } |
| 485 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 486 | writel(cfg, dev->regs + FIMC_REG_MSCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 487 | |
| 488 | /* Input/output DMA linear/tiled mode. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 489 | cfg = readl(dev->regs + FIMC_REG_CIDMAPARAM); |
| 490 | cfg &= ~FIMC_REG_CIDMAPARAM_TILE_MASK; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 491 | |
| 492 | if (tiled_fmt(ctx->s_frame.fmt)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 493 | cfg |= FIMC_REG_CIDMAPARAM_R_64X32; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 494 | |
| 495 | if (tiled_fmt(ctx->d_frame.fmt)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 496 | cfg |= FIMC_REG_CIDMAPARAM_W_64X32; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 497 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 498 | writel(cfg, dev->regs + FIMC_REG_CIDMAPARAM); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
| 502 | void fimc_hw_set_input_path(struct fimc_ctx *ctx) |
| 503 | { |
| 504 | struct fimc_dev *dev = ctx->fimc_dev; |
| 505 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 506 | u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL); |
| 507 | cfg &= ~FIMC_REG_MSCTRL_INPUT_MASK; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 508 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 509 | if (ctx->in_path == FIMC_IO_DMA) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 510 | cfg |= FIMC_REG_MSCTRL_INPUT_MEMORY; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 511 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 512 | cfg |= FIMC_REG_MSCTRL_INPUT_EXTCAM; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 513 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 514 | writel(cfg, dev->regs + FIMC_REG_MSCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | void fimc_hw_set_output_path(struct fimc_ctx *ctx) |
| 518 | { |
| 519 | struct fimc_dev *dev = ctx->fimc_dev; |
| 520 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 521 | u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL); |
| 522 | cfg &= ~FIMC_REG_CISCCTRL_LCDPATHEN_FIFO; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 523 | if (ctx->out_path == FIMC_IO_LCDFIFO) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 524 | cfg |= FIMC_REG_CISCCTRL_LCDPATHEN_FIFO; |
| 525 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr) |
| 529 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 530 | u32 cfg = readl(dev->regs + FIMC_REG_CIREAL_ISIZE); |
| 531 | cfg |= FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS; |
| 532 | writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 533 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 534 | writel(paddr->y, dev->regs + FIMC_REG_CIIYSA(0)); |
| 535 | writel(paddr->cb, dev->regs + FIMC_REG_CIICBSA(0)); |
| 536 | writel(paddr->cr, dev->regs + FIMC_REG_CIICRSA(0)); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 537 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 538 | cfg &= ~FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS; |
| 539 | writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 540 | } |
| 541 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 542 | void fimc_hw_set_output_addr(struct fimc_dev *dev, |
| 543 | struct fimc_addr *paddr, int index) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 544 | { |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 545 | int i = (index == -1) ? 0 : index; |
| 546 | do { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 547 | writel(paddr->y, dev->regs + FIMC_REG_CIOYSA(i)); |
| 548 | writel(paddr->cb, dev->regs + FIMC_REG_CIOCBSA(i)); |
| 549 | writel(paddr->cr, dev->regs + FIMC_REG_CIOCRSA(i)); |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 550 | dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X", |
| 551 | i, paddr->y, paddr->cb, paddr->cr); |
| 552 | } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 553 | } |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 554 | |
| 555 | int fimc_hw_set_camera_polarity(struct fimc_dev *fimc, |
Sylwester Nawrocki | df7e09a | 2010-12-27 14:42:15 -0300 | [diff] [blame] | 556 | struct s5p_fimc_isp_info *cam) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 557 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 558 | u32 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 559 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 560 | cfg &= ~(FIMC_REG_CIGCTRL_INVPOLPCLK | FIMC_REG_CIGCTRL_INVPOLVSYNC | |
| 561 | FIMC_REG_CIGCTRL_INVPOLHREF | FIMC_REG_CIGCTRL_INVPOLHSYNC | |
| 562 | FIMC_REG_CIGCTRL_INVPOLFIELD); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 563 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 564 | if (cam->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 565 | cfg |= FIMC_REG_CIGCTRL_INVPOLPCLK; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 566 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 567 | if (cam->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 568 | cfg |= FIMC_REG_CIGCTRL_INVPOLVSYNC; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 569 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 570 | if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 571 | cfg |= FIMC_REG_CIGCTRL_INVPOLHREF; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 572 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 573 | if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 574 | cfg |= FIMC_REG_CIGCTRL_INVPOLHSYNC; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 575 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 576 | if (cam->flags & V4L2_MBUS_FIELD_EVEN_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 577 | cfg |= FIMC_REG_CIGCTRL_INVPOLFIELD; |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 578 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 579 | writel(cfg, fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 584 | struct mbus_pixfmt_desc { |
| 585 | u32 pixelcode; |
| 586 | u32 cisrcfmt; |
| 587 | u16 bus_width; |
| 588 | }; |
| 589 | |
| 590 | static const struct mbus_pixfmt_desc pix_desc[] = { |
| 591 | { V4L2_MBUS_FMT_YUYV8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCBYCR, 8 }, |
| 592 | { V4L2_MBUS_FMT_YVYU8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCRYCB, 8 }, |
| 593 | { V4L2_MBUS_FMT_VYUY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CRYCBY, 8 }, |
| 594 | { V4L2_MBUS_FMT_UYVY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CBYCRY, 8 }, |
| 595 | }; |
| 596 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 597 | int fimc_hw_set_camera_source(struct fimc_dev *fimc, |
Sylwester Nawrocki | df7e09a | 2010-12-27 14:42:15 -0300 | [diff] [blame] | 598 | struct s5p_fimc_isp_info *cam) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 599 | { |
| 600 | struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; |
| 601 | u32 cfg = 0; |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 602 | u32 bus_width; |
| 603 | int i; |
| 604 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 605 | if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) { |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 606 | for (i = 0; i < ARRAY_SIZE(pix_desc); i++) { |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 607 | if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) { |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 608 | cfg = pix_desc[i].cisrcfmt; |
| 609 | bus_width = pix_desc[i].bus_width; |
| 610 | break; |
| 611 | } |
| 612 | } |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 613 | |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 614 | if (i == ARRAY_SIZE(pix_desc)) { |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 615 | v4l2_err(&fimc->vid_cap.vfd, |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 616 | "Camera color format not supported: %d\n", |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 617 | fimc->vid_cap.mf.code); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 618 | return -EINVAL; |
| 619 | } |
| 620 | |
| 621 | if (cam->bus_type == FIMC_ITU_601) { |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 622 | if (bus_width == 8) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 623 | cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 624 | else if (bus_width == 16) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 625 | cfg |= FIMC_REG_CISRCFMT_ITU601_16BIT; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 626 | } /* else defaults to ITU-R BT.656 8-bit */ |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 627 | } else if (cam->bus_type == FIMC_MIPI_CSI2) { |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 628 | if (fimc_fmt_is_user_defined(f->fmt->color)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 629 | cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 630 | } |
| 631 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 632 | cfg |= (f->o_width << 16) | f->o_height; |
| 633 | writel(cfg, fimc->regs + FIMC_REG_CISRCFMT); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 634 | return 0; |
| 635 | } |
| 636 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 637 | void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 638 | { |
| 639 | u32 hoff2, voff2; |
| 640 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 641 | u32 cfg = readl(fimc->regs + FIMC_REG_CIWDOFST); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 642 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 643 | cfg &= ~(FIMC_REG_CIWDOFST_HOROFF_MASK | FIMC_REG_CIWDOFST_VEROFF_MASK); |
| 644 | cfg |= FIMC_REG_CIWDOFST_OFF_EN | |
| 645 | (f->offs_h << 16) | f->offs_v; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 646 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 647 | writel(cfg, fimc->regs + FIMC_REG_CIWDOFST); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 648 | |
| 649 | /* See CIWDOFSTn register description in the datasheet for details. */ |
| 650 | hoff2 = f->o_width - f->width - f->offs_h; |
| 651 | voff2 = f->o_height - f->height - f->offs_v; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 652 | cfg = (hoff2 << 16) | voff2; |
| 653 | writel(cfg, fimc->regs + FIMC_REG_CIWDOFST2); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | int fimc_hw_set_camera_type(struct fimc_dev *fimc, |
Sylwester Nawrocki | df7e09a | 2010-12-27 14:42:15 -0300 | [diff] [blame] | 657 | struct s5p_fimc_isp_info *cam) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 658 | { |
| 659 | u32 cfg, tmp; |
| 660 | struct fimc_vid_cap *vid_cap = &fimc->vid_cap; |
Sylwester Nawrocki | 20676a4 | 2012-03-21 06:21:30 -0300 | [diff] [blame] | 661 | u32 csis_data_alignment = 32; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 662 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 663 | cfg = readl(fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 664 | |
| 665 | /* Select ITU B interface, disable Writeback path and test pattern. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 666 | cfg &= ~(FIMC_REG_CIGCTRL_TESTPAT_MASK | FIMC_REG_CIGCTRL_SELCAM_ITU_A | |
| 667 | FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB | |
| 668 | FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 669 | |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 670 | switch (cam->bus_type) { |
| 671 | case FIMC_MIPI_CSI2: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 672 | cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 673 | |
| 674 | if (cam->mux_id == 0) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 675 | cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 676 | |
| 677 | /* TODO: add remaining supported formats. */ |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 678 | switch (vid_cap->mf.code) { |
| 679 | case V4L2_MBUS_FMT_VYUY8_2X8: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 680 | tmp = FIMC_REG_CSIIMGFMT_YCBCR422_8BIT; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 681 | break; |
| 682 | case V4L2_MBUS_FMT_JPEG_1X8: |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 683 | case V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 684 | tmp = FIMC_REG_CSIIMGFMT_USER(1); |
| 685 | cfg |= FIMC_REG_CIGCTRL_CAM_JPEG; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 686 | break; |
| 687 | default: |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 688 | v4l2_err(&vid_cap->vfd, |
Sachin Kamat | a516d08 | 2012-06-12 03:12:26 -0300 | [diff] [blame] | 689 | "Not supported camera pixel format: %#x\n", |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 690 | vid_cap->mf.code); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 691 | return -EINVAL; |
| 692 | } |
Sylwester Nawrocki | 20676a4 | 2012-03-21 06:21:30 -0300 | [diff] [blame] | 693 | tmp |= (csis_data_alignment == 32) << 8; |
Sylwester Nawrocki | e0eec9a | 2011-02-21 12:09:01 -0300 | [diff] [blame] | 694 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 695 | writel(tmp, fimc->regs + FIMC_REG_CSIIMGFMT); |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 696 | break; |
| 697 | case FIMC_ITU_601...FIMC_ITU_656: |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 698 | if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 699 | cfg |= FIMC_REG_CIGCTRL_SELCAM_ITU_A; |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 700 | break; |
| 701 | case FIMC_LCD_WB: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 702 | cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB; |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 703 | break; |
| 704 | default: |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 705 | v4l2_err(&vid_cap->vfd, "Invalid camera bus type selected\n"); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | } |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 708 | writel(cfg, fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 709 | |
| 710 | return 0; |
| 711 | } |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 712 | |
| 713 | void fimc_hw_clear_irq(struct fimc_dev *dev) |
| 714 | { |
| 715 | u32 cfg = readl(dev->regs + FIMC_REG_CIGCTRL); |
| 716 | cfg |= FIMC_REG_CIGCTRL_IRQ_CLR; |
| 717 | writel(cfg, dev->regs + FIMC_REG_CIGCTRL); |
| 718 | } |
| 719 | |
| 720 | void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on) |
| 721 | { |
| 722 | u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL); |
| 723 | if (on) |
| 724 | cfg |= FIMC_REG_CISCCTRL_SCALERSTART; |
| 725 | else |
| 726 | cfg &= ~FIMC_REG_CISCCTRL_SCALERSTART; |
| 727 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
| 728 | } |
| 729 | |
| 730 | void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on) |
| 731 | { |
| 732 | u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL); |
| 733 | if (on) |
| 734 | cfg |= FIMC_REG_MSCTRL_ENVID; |
| 735 | else |
| 736 | cfg &= ~FIMC_REG_MSCTRL_ENVID; |
| 737 | writel(cfg, dev->regs + FIMC_REG_MSCTRL); |
| 738 | } |
| 739 | |
| 740 | void fimc_hw_dis_capture(struct fimc_dev *dev) |
| 741 | { |
| 742 | u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT); |
| 743 | cfg &= ~(FIMC_REG_CIIMGCPT_IMGCPTEN | FIMC_REG_CIIMGCPT_IMGCPTEN_SC); |
| 744 | writel(cfg, dev->regs + FIMC_REG_CIIMGCPT); |
| 745 | } |
| 746 | |
| 747 | /* Return an index to the buffer actually being written. */ |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 748 | s32 fimc_hw_get_frame_index(struct fimc_dev *dev) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 749 | { |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 750 | s32 reg; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 751 | |
| 752 | if (dev->variant->has_cistatus2) { |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 753 | reg = readl(dev->regs + FIMC_REG_CISTATUS2) & 0x3f; |
| 754 | return reg - 1; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | reg = readl(dev->regs + FIMC_REG_CISTATUS); |
| 758 | |
| 759 | return (reg & FIMC_REG_CISTATUS_FRAMECNT_MASK) >> |
| 760 | FIMC_REG_CISTATUS_FRAMECNT_SHIFT; |
| 761 | } |
| 762 | |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 763 | /* Return an index to the buffer being written previously. */ |
| 764 | s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev) |
| 765 | { |
| 766 | s32 reg; |
| 767 | |
| 768 | if (!dev->variant->has_cistatus2) |
| 769 | return -1; |
| 770 | |
| 771 | reg = readl(dev->regs + FIMC_REG_CISTATUS2); |
| 772 | return ((reg >> 7) & 0x3f) - 1; |
| 773 | } |
| 774 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 775 | /* Locking: the caller holds fimc->slock */ |
| 776 | void fimc_activate_capture(struct fimc_ctx *ctx) |
| 777 | { |
| 778 | fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled); |
| 779 | fimc_hw_en_capture(ctx); |
| 780 | } |
| 781 | |
| 782 | void fimc_deactivate_capture(struct fimc_dev *fimc) |
| 783 | { |
| 784 | fimc_hw_en_lastirq(fimc, true); |
| 785 | fimc_hw_dis_capture(fimc); |
| 786 | fimc_hw_enable_scaler(fimc, false); |
| 787 | fimc_hw_en_lastirq(fimc, false); |
| 788 | } |