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 | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 315 | const 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 | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 347 | void fimc_hw_enable_capture(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 348 | { |
| 349 | struct fimc_dev *dev = ctx->fimc_dev; |
Sylwester Nawrocki | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 350 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 351 | |
Sylwester Nawrocki | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 352 | cfg = readl(dev->regs + FIMC_REG_CIIMGCPT); |
| 353 | cfg |= FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 354 | |
| 355 | if (ctx->scaler.enabled) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 356 | cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN_SC; |
Sylwester Nawrocki | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 357 | else |
| 358 | cfg &= FIMC_REG_CIIMGCPT_IMGCPTEN_SC; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 359 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 360 | cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN; |
| 361 | writel(cfg, dev->regs + FIMC_REG_CIIMGCPT); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 362 | } |
| 363 | |
Sylwester Nawrocki | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 364 | void fimc_hw_disable_capture(struct fimc_dev *dev) |
| 365 | { |
| 366 | u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT); |
| 367 | cfg &= ~(FIMC_REG_CIIMGCPT_IMGCPTEN | |
| 368 | FIMC_REG_CIIMGCPT_IMGCPTEN_SC); |
| 369 | writel(cfg, dev->regs + FIMC_REG_CIIMGCPT); |
| 370 | } |
| 371 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 372 | void fimc_hw_set_effect(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 373 | { |
| 374 | struct fimc_dev *dev = ctx->fimc_dev; |
| 375 | struct fimc_effect *effect = &ctx->effect; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 376 | u32 cfg = 0; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 377 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 378 | if (effect->type != FIMC_REG_CIIMGEFF_FIN_BYPASS) { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 379 | cfg |= FIMC_REG_CIIMGEFF_IE_SC_AFTER | |
| 380 | FIMC_REG_CIIMGEFF_IE_ENABLE; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 381 | cfg |= effect->type; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 382 | if (effect->type == FIMC_REG_CIIMGEFF_FIN_ARBITRARY) |
| 383 | cfg |= (effect->pat_cb << 13) | effect->pat_cr; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 384 | } |
| 385 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 386 | writel(cfg, dev->regs + FIMC_REG_CIIMGEFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 387 | } |
| 388 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 389 | void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx) |
| 390 | { |
| 391 | struct fimc_dev *dev = ctx->fimc_dev; |
| 392 | struct fimc_frame *frame = &ctx->d_frame; |
| 393 | u32 cfg; |
| 394 | |
| 395 | if (!(frame->fmt->flags & FMT_HAS_ALPHA)) |
| 396 | return; |
| 397 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 398 | cfg = readl(dev->regs + FIMC_REG_CIOCTRL); |
| 399 | cfg &= ~FIMC_REG_CIOCTRL_ALPHA_OUT_MASK; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 400 | cfg |= (frame->alpha << 4); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 401 | writel(cfg, dev->regs + FIMC_REG_CIOCTRL); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 402 | } |
| 403 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 404 | static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx) |
| 405 | { |
| 406 | struct fimc_dev *dev = ctx->fimc_dev; |
| 407 | struct fimc_frame *frame = &ctx->s_frame; |
| 408 | u32 cfg_o = 0; |
| 409 | u32 cfg_r = 0; |
| 410 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 411 | if (FIMC_IO_LCDFIFO == ctx->out_path) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 412 | cfg_r |= FIMC_REG_CIREAL_ISIZE_AUTOLOAD_EN; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 413 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 414 | cfg_o |= (frame->f_height << 16) | frame->f_width; |
| 415 | cfg_r |= (frame->height << 16) | frame->width; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 416 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 417 | writel(cfg_o, dev->regs + FIMC_REG_ORGISIZE); |
| 418 | writel(cfg_r, dev->regs + FIMC_REG_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void fimc_hw_set_in_dma(struct fimc_ctx *ctx) |
| 422 | { |
| 423 | struct fimc_dev *dev = ctx->fimc_dev; |
| 424 | struct fimc_frame *frame = &ctx->s_frame; |
| 425 | struct fimc_dma_offset *offset = &frame->dma_offset; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 426 | u32 cfg; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 427 | |
| 428 | /* Set the pixel offsets. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 429 | cfg = (offset->y_v << 16) | offset->y_h; |
| 430 | writel(cfg, dev->regs + FIMC_REG_CIIYOFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 431 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 432 | cfg = (offset->cb_v << 16) | offset->cb_h; |
| 433 | writel(cfg, dev->regs + FIMC_REG_CIICBOFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 434 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 435 | cfg = (offset->cr_v << 16) | offset->cr_h; |
| 436 | writel(cfg, dev->regs + FIMC_REG_CIICROFF); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 437 | |
| 438 | /* Input original and real size. */ |
| 439 | fimc_hw_set_in_dma_size(ctx); |
| 440 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 441 | /* Use DMA autoload only in FIFO mode. */ |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 442 | fimc_hw_en_autoload(dev, ctx->out_path == FIMC_IO_LCDFIFO); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 443 | |
| 444 | /* Set the input DMA to process single frame only. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 445 | cfg = readl(dev->regs + FIMC_REG_MSCTRL); |
| 446 | cfg &= ~(FIMC_REG_MSCTRL_INFORMAT_MASK |
| 447 | | FIMC_REG_MSCTRL_IN_BURST_COUNT_MASK |
| 448 | | FIMC_REG_MSCTRL_INPUT_MASK |
| 449 | | FIMC_REG_MSCTRL_C_INT_IN_MASK |
| 450 | | FIMC_REG_MSCTRL_2P_IN_ORDER_MASK); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 451 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 452 | cfg |= (FIMC_REG_MSCTRL_IN_BURST_COUNT(4) |
| 453 | | FIMC_REG_MSCTRL_INPUT_MEMORY |
| 454 | | FIMC_REG_MSCTRL_FIFO_CTRL_FULL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 455 | |
| 456 | switch (frame->fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 457 | case FIMC_FMT_RGB565...FIMC_FMT_RGB888: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 458 | cfg |= FIMC_REG_MSCTRL_INFORMAT_RGB; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 459 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 460 | case FIMC_FMT_YCBCR420: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 461 | cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR420; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 462 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 463 | if (frame->fmt->colplanes == 2) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 464 | cfg |= ctx->in_order_2p | FIMC_REG_MSCTRL_C_INT_IN_2PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 465 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 466 | cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 467 | |
| 468 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 469 | case FIMC_FMT_YCBYCR422...FIMC_FMT_CRYCBY422: |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 470 | if (frame->fmt->colplanes == 1) { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 471 | cfg |= ctx->in_order_1p |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 472 | | FIMC_REG_MSCTRL_INFORMAT_YCBCR422_1P; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 473 | } else { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 474 | cfg |= FIMC_REG_MSCTRL_INFORMAT_YCBCR422; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 475 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 476 | if (frame->fmt->colplanes == 2) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 477 | cfg |= ctx->in_order_2p |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 478 | | FIMC_REG_MSCTRL_C_INT_IN_2PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 479 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 480 | cfg |= FIMC_REG_MSCTRL_C_INT_IN_3PLANE; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 481 | } |
| 482 | break; |
| 483 | default: |
| 484 | break; |
| 485 | } |
| 486 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 487 | writel(cfg, dev->regs + FIMC_REG_MSCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 488 | |
| 489 | /* Input/output DMA linear/tiled mode. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 490 | cfg = readl(dev->regs + FIMC_REG_CIDMAPARAM); |
| 491 | cfg &= ~FIMC_REG_CIDMAPARAM_TILE_MASK; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 492 | |
| 493 | if (tiled_fmt(ctx->s_frame.fmt)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 494 | cfg |= FIMC_REG_CIDMAPARAM_R_64X32; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 495 | |
| 496 | if (tiled_fmt(ctx->d_frame.fmt)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 497 | cfg |= FIMC_REG_CIDMAPARAM_W_64X32; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 498 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 499 | writel(cfg, dev->regs + FIMC_REG_CIDMAPARAM); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | |
| 503 | void fimc_hw_set_input_path(struct fimc_ctx *ctx) |
| 504 | { |
| 505 | struct fimc_dev *dev = ctx->fimc_dev; |
| 506 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 507 | u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL); |
| 508 | cfg &= ~FIMC_REG_MSCTRL_INPUT_MASK; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 509 | |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 510 | if (ctx->in_path == FIMC_IO_DMA) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 511 | cfg |= FIMC_REG_MSCTRL_INPUT_MEMORY; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 512 | else |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 513 | cfg |= FIMC_REG_MSCTRL_INPUT_EXTCAM; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 514 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 515 | writel(cfg, dev->regs + FIMC_REG_MSCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void fimc_hw_set_output_path(struct fimc_ctx *ctx) |
| 519 | { |
| 520 | struct fimc_dev *dev = ctx->fimc_dev; |
| 521 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 522 | u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL); |
| 523 | cfg &= ~FIMC_REG_CISCCTRL_LCDPATHEN_FIFO; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 524 | if (ctx->out_path == FIMC_IO_LCDFIFO) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 525 | cfg |= FIMC_REG_CISCCTRL_LCDPATHEN_FIFO; |
| 526 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr) |
| 530 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 531 | u32 cfg = readl(dev->regs + FIMC_REG_CIREAL_ISIZE); |
| 532 | cfg |= FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS; |
| 533 | writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 534 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 535 | writel(paddr->y, dev->regs + FIMC_REG_CIIYSA(0)); |
| 536 | writel(paddr->cb, dev->regs + FIMC_REG_CIICBSA(0)); |
| 537 | writel(paddr->cr, dev->regs + FIMC_REG_CIICRSA(0)); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 538 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 539 | cfg &= ~FIMC_REG_CIREAL_ISIZE_ADDR_CH_DIS; |
| 540 | writel(cfg, dev->regs + FIMC_REG_CIREAL_ISIZE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 541 | } |
| 542 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 543 | void fimc_hw_set_output_addr(struct fimc_dev *dev, |
| 544 | struct fimc_addr *paddr, int index) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 545 | { |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 546 | int i = (index == -1) ? 0 : index; |
| 547 | do { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 548 | writel(paddr->y, dev->regs + FIMC_REG_CIOYSA(i)); |
| 549 | writel(paddr->cb, dev->regs + FIMC_REG_CIOCBSA(i)); |
| 550 | writel(paddr->cr, dev->regs + FIMC_REG_CIOCRSA(i)); |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 551 | dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X", |
| 552 | i, paddr->y, paddr->cb, paddr->cr); |
| 553 | } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 554 | } |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 555 | |
| 556 | int fimc_hw_set_camera_polarity(struct fimc_dev *fimc, |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 557 | struct fimc_source_info *cam) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 558 | { |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 559 | u32 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 560 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 561 | cfg &= ~(FIMC_REG_CIGCTRL_INVPOLPCLK | FIMC_REG_CIGCTRL_INVPOLVSYNC | |
| 562 | FIMC_REG_CIGCTRL_INVPOLHREF | FIMC_REG_CIGCTRL_INVPOLHSYNC | |
| 563 | FIMC_REG_CIGCTRL_INVPOLFIELD); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 564 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 565 | if (cam->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 566 | cfg |= FIMC_REG_CIGCTRL_INVPOLPCLK; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 567 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 568 | if (cam->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 569 | cfg |= FIMC_REG_CIGCTRL_INVPOLVSYNC; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 570 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 571 | if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 572 | cfg |= FIMC_REG_CIGCTRL_INVPOLHREF; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 573 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 574 | if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 575 | cfg |= FIMC_REG_CIGCTRL_INVPOLHSYNC; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 576 | |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 577 | if (cam->flags & V4L2_MBUS_FIELD_EVEN_LOW) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 578 | cfg |= FIMC_REG_CIGCTRL_INVPOLFIELD; |
Sylwester Nawrocki | 12ecf56 | 2011-09-19 12:38:35 -0300 | [diff] [blame] | 579 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 580 | writel(cfg, fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 585 | struct mbus_pixfmt_desc { |
| 586 | u32 pixelcode; |
| 587 | u32 cisrcfmt; |
| 588 | u16 bus_width; |
| 589 | }; |
| 590 | |
| 591 | static const struct mbus_pixfmt_desc pix_desc[] = { |
| 592 | { V4L2_MBUS_FMT_YUYV8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCBYCR, 8 }, |
| 593 | { V4L2_MBUS_FMT_YVYU8_2X8, FIMC_REG_CISRCFMT_ORDER422_YCRYCB, 8 }, |
| 594 | { V4L2_MBUS_FMT_VYUY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CRYCBY, 8 }, |
| 595 | { V4L2_MBUS_FMT_UYVY8_2X8, FIMC_REG_CISRCFMT_ORDER422_CBYCRY, 8 }, |
| 596 | }; |
| 597 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 598 | int fimc_hw_set_camera_source(struct fimc_dev *fimc, |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 599 | struct fimc_source_info *source) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 600 | { |
| 601 | struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 602 | u32 bus_width, cfg = 0; |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 603 | int i; |
| 604 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 605 | switch (source->fimc_bus_type) { |
| 606 | case FIMC_BUS_TYPE_ITU_601: |
| 607 | case FIMC_BUS_TYPE_ITU_656: |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 608 | for (i = 0; i < ARRAY_SIZE(pix_desc); i++) { |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 609 | if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) { |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 610 | cfg = pix_desc[i].cisrcfmt; |
| 611 | bus_width = pix_desc[i].bus_width; |
| 612 | break; |
| 613 | } |
| 614 | } |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 615 | |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 616 | if (i == ARRAY_SIZE(pix_desc)) { |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 617 | v4l2_err(&fimc->vid_cap.vfd, |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 618 | "Camera color format not supported: %d\n", |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 619 | fimc->vid_cap.mf.code); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 620 | return -EINVAL; |
| 621 | } |
| 622 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 623 | if (source->fimc_bus_type == FIMC_BUS_TYPE_ITU_601) { |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 624 | if (bus_width == 8) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 625 | cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; |
Sylwester Nawrocki | 3d0ce7e | 2010-12-27 15:02:16 -0300 | [diff] [blame] | 626 | else if (bus_width == 16) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 627 | cfg |= FIMC_REG_CISRCFMT_ITU601_16BIT; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 628 | } /* else defaults to ITU-R BT.656 8-bit */ |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 629 | break; |
| 630 | case FIMC_BUS_TYPE_MIPI_CSI2: |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 631 | if (fimc_fmt_is_user_defined(f->fmt->color)) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 632 | cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 633 | break; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 634 | } |
| 635 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 636 | cfg |= (f->o_width << 16) | f->o_height; |
| 637 | writel(cfg, fimc->regs + FIMC_REG_CISRCFMT); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 638 | return 0; |
| 639 | } |
| 640 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 641 | 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] | 642 | { |
| 643 | u32 hoff2, voff2; |
| 644 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 645 | u32 cfg = readl(fimc->regs + FIMC_REG_CIWDOFST); |
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 | cfg &= ~(FIMC_REG_CIWDOFST_HOROFF_MASK | FIMC_REG_CIWDOFST_VEROFF_MASK); |
| 648 | cfg |= FIMC_REG_CIWDOFST_OFF_EN | |
| 649 | (f->offs_h << 16) | f->offs_v; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 650 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 651 | writel(cfg, fimc->regs + FIMC_REG_CIWDOFST); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 652 | |
| 653 | /* See CIWDOFSTn register description in the datasheet for details. */ |
| 654 | hoff2 = f->o_width - f->width - f->offs_h; |
| 655 | voff2 = f->o_height - f->height - f->offs_v; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 656 | cfg = (hoff2 << 16) | voff2; |
| 657 | writel(cfg, fimc->regs + FIMC_REG_CIWDOFST2); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | int fimc_hw_set_camera_type(struct fimc_dev *fimc, |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 661 | struct fimc_source_info *source) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 662 | { |
| 663 | u32 cfg, tmp; |
| 664 | struct fimc_vid_cap *vid_cap = &fimc->vid_cap; |
Sylwester Nawrocki | 20676a4 | 2012-03-21 06:21:30 -0300 | [diff] [blame] | 665 | u32 csis_data_alignment = 32; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 666 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 667 | cfg = readl(fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 668 | |
| 669 | /* Select ITU B interface, disable Writeback path and test pattern. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 670 | cfg &= ~(FIMC_REG_CIGCTRL_TESTPAT_MASK | FIMC_REG_CIGCTRL_SELCAM_ITU_A | |
| 671 | FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB | |
| 672 | FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 673 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 674 | switch (source->fimc_bus_type) { |
| 675 | case FIMC_BUS_TYPE_MIPI_CSI2: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 676 | cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 677 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 678 | if (source->mux_id == 0) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 679 | cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 680 | |
| 681 | /* TODO: add remaining supported formats. */ |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 682 | switch (vid_cap->mf.code) { |
| 683 | case V4L2_MBUS_FMT_VYUY8_2X8: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 684 | tmp = FIMC_REG_CSIIMGFMT_YCBCR422_8BIT; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 685 | break; |
| 686 | case V4L2_MBUS_FMT_JPEG_1X8: |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 687 | case V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 688 | tmp = FIMC_REG_CSIIMGFMT_USER(1); |
| 689 | cfg |= FIMC_REG_CIGCTRL_CAM_JPEG; |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 690 | break; |
| 691 | default: |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 692 | v4l2_err(&vid_cap->vfd, |
Sachin Kamat | a516d08 | 2012-06-12 03:12:26 -0300 | [diff] [blame] | 693 | "Not supported camera pixel format: %#x\n", |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 694 | vid_cap->mf.code); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 695 | return -EINVAL; |
| 696 | } |
Sylwester Nawrocki | 20676a4 | 2012-03-21 06:21:30 -0300 | [diff] [blame] | 697 | tmp |= (csis_data_alignment == 32) << 8; |
Sylwester Nawrocki | e0eec9a | 2011-02-21 12:09:01 -0300 | [diff] [blame] | 698 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 699 | writel(tmp, fimc->regs + FIMC_REG_CSIIMGFMT); |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 700 | break; |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 701 | case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656: |
| 702 | if (source->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 703 | cfg |= FIMC_REG_CIGCTRL_SELCAM_ITU_A; |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 704 | break; |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 705 | case FIMC_BUS_TYPE_LCD_WRITEBACK_A: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 706 | cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB; |
Sylwester Nawrocki | 31ce54f | 2012-07-24 12:06:26 -0300 | [diff] [blame] | 707 | break; |
| 708 | default: |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame^] | 709 | v4l2_err(&vid_cap->vfd, "Invalid FIMC bus type selected: %d\n", |
| 710 | source->fimc_bus_type); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 711 | return -EINVAL; |
| 712 | } |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 713 | writel(cfg, fimc->regs + FIMC_REG_CIGCTRL); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 714 | |
| 715 | return 0; |
| 716 | } |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 717 | |
| 718 | void fimc_hw_clear_irq(struct fimc_dev *dev) |
| 719 | { |
| 720 | u32 cfg = readl(dev->regs + FIMC_REG_CIGCTRL); |
| 721 | cfg |= FIMC_REG_CIGCTRL_IRQ_CLR; |
| 722 | writel(cfg, dev->regs + FIMC_REG_CIGCTRL); |
| 723 | } |
| 724 | |
| 725 | void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on) |
| 726 | { |
| 727 | u32 cfg = readl(dev->regs + FIMC_REG_CISCCTRL); |
| 728 | if (on) |
| 729 | cfg |= FIMC_REG_CISCCTRL_SCALERSTART; |
| 730 | else |
| 731 | cfg &= ~FIMC_REG_CISCCTRL_SCALERSTART; |
| 732 | writel(cfg, dev->regs + FIMC_REG_CISCCTRL); |
| 733 | } |
| 734 | |
| 735 | void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on) |
| 736 | { |
| 737 | u32 cfg = readl(dev->regs + FIMC_REG_MSCTRL); |
| 738 | if (on) |
| 739 | cfg |= FIMC_REG_MSCTRL_ENVID; |
| 740 | else |
| 741 | cfg &= ~FIMC_REG_MSCTRL_ENVID; |
| 742 | writel(cfg, dev->regs + FIMC_REG_MSCTRL); |
| 743 | } |
| 744 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 745 | /* Return an index to the buffer actually being written. */ |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 746 | s32 fimc_hw_get_frame_index(struct fimc_dev *dev) |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 747 | { |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 748 | s32 reg; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 749 | |
| 750 | if (dev->variant->has_cistatus2) { |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 751 | reg = readl(dev->regs + FIMC_REG_CISTATUS2) & 0x3f; |
| 752 | return reg - 1; |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | reg = readl(dev->regs + FIMC_REG_CISTATUS); |
| 756 | |
| 757 | return (reg & FIMC_REG_CISTATUS_FRAMECNT_MASK) >> |
| 758 | FIMC_REG_CISTATUS_FRAMECNT_SHIFT; |
| 759 | } |
| 760 | |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 761 | /* Return an index to the buffer being written previously. */ |
| 762 | s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev) |
| 763 | { |
| 764 | s32 reg; |
| 765 | |
| 766 | if (!dev->variant->has_cistatus2) |
| 767 | return -1; |
| 768 | |
| 769 | reg = readl(dev->regs + FIMC_REG_CISTATUS2); |
| 770 | return ((reg >> 7) & 0x3f) - 1; |
| 771 | } |
| 772 | |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 773 | /* Locking: the caller holds fimc->slock */ |
| 774 | void fimc_activate_capture(struct fimc_ctx *ctx) |
| 775 | { |
| 776 | fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled); |
Sylwester Nawrocki | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 777 | fimc_hw_enable_capture(ctx); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | void fimc_deactivate_capture(struct fimc_dev *fimc) |
| 781 | { |
| 782 | fimc_hw_en_lastirq(fimc, true); |
Sylwester Nawrocki | 35f2924 | 2012-11-22 14:01:39 -0300 | [diff] [blame] | 783 | fimc_hw_disable_capture(fimc); |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 784 | fimc_hw_enable_scaler(fimc, false); |
| 785 | fimc_hw_en_lastirq(fimc, false); |
| 786 | } |