blob: 9a8628417b509b0209ee589523dca937fff68068 [file] [log] [blame]
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001/*
2 * isppreview.c
3 *
4 * TI OMAP3 ISP driver - Preview module
5 *
6 * Copyright (C) 2010 Nokia Corporation
7 * Copyright (C) 2009 Texas Instruments, Inc.
8 *
9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10 * Sakari Ailus <sakari.ailus@iki.fi>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
25 */
26
27#include <linux/device.h>
28#include <linux/mm.h>
29#include <linux/module.h>
30#include <linux/mutex.h>
31#include <linux/uaccess.h>
32
33#include "isp.h"
34#include "ispreg.h"
35#include "isppreview.h"
36
Lucas De Marchi25985ed2011-03-30 22:57:33 -030037/* Default values in Office Fluorescent Light for RGBtoRGB Blending */
Laurent Pinchartde1135d2011-02-12 18:05:06 -030038static struct omap3isp_prev_rgbtorgb flr_rgb2rgb = {
39 { /* RGB-RGB Matrix */
40 {0x01E2, 0x0F30, 0x0FEE},
41 {0x0F9B, 0x01AC, 0x0FB9},
42 {0x0FE0, 0x0EC0, 0x0260}
43 }, /* RGB Offset */
44 {0x0000, 0x0000, 0x0000}
45};
46
Lucas De Marchi25985ed2011-03-30 22:57:33 -030047/* Default values in Office Fluorescent Light for RGB to YUV Conversion*/
Laurent Pinchartde1135d2011-02-12 18:05:06 -030048static struct omap3isp_prev_csc flr_prev_csc = {
49 { /* CSC Coef Matrix */
50 {66, 129, 25},
51 {-38, -75, 112},
52 {112, -94 , -18}
53 }, /* CSC Offset */
54 {0x0, 0x0, 0x0}
55};
56
Lucas De Marchi25985ed2011-03-30 22:57:33 -030057/* Default values in Office Fluorescent Light for CFA Gradient*/
Laurent Pinchartde1135d2011-02-12 18:05:06 -030058#define FLR_CFA_GRADTHRS_HORZ 0x28
59#define FLR_CFA_GRADTHRS_VERT 0x28
60
Lucas De Marchi25985ed2011-03-30 22:57:33 -030061/* Default values in Office Fluorescent Light for Chroma Suppression*/
Laurent Pinchartde1135d2011-02-12 18:05:06 -030062#define FLR_CSUP_GAIN 0x0D
63#define FLR_CSUP_THRES 0xEB
64
Lucas De Marchi25985ed2011-03-30 22:57:33 -030065/* Default values in Office Fluorescent Light for Noise Filter*/
Laurent Pinchartde1135d2011-02-12 18:05:06 -030066#define FLR_NF_STRGTH 0x03
67
68/* Default values for White Balance */
69#define FLR_WBAL_DGAIN 0x100
70#define FLR_WBAL_COEF 0x20
71
Lucas De Marchi25985ed2011-03-30 22:57:33 -030072/* Default values in Office Fluorescent Light for Black Adjustment*/
Laurent Pinchartde1135d2011-02-12 18:05:06 -030073#define FLR_BLKADJ_BLUE 0x0
74#define FLR_BLKADJ_GREEN 0x0
75#define FLR_BLKADJ_RED 0x0
76
77#define DEF_DETECT_CORRECT_VAL 0xe
78
Laurent Pinchart1f69fd92011-09-21 20:05:45 -030079/*
80 * Margins and image size limits.
81 *
82 * The preview engine crops several rows and columns internally depending on
83 * which filters are enabled. To avoid format changes when the filters are
84 * enabled or disabled (which would prevent them from being turned on or off
85 * during streaming), the driver assumes all the filters are enabled when
86 * computing sink crop and source format limits.
87 *
88 * If a filter is disabled, additional cropping is automatically added at the
89 * preview engine input by the driver to avoid overflow at line and frame end.
90 * This is completely transparent for applications.
91 *
92 * Median filter 4 pixels
93 * Noise filter,
94 * Faulty pixels correction 4 pixels, 4 lines
95 * CFA filter 4 pixels, 4 lines in Bayer mode
96 * 2 lines in other modes
97 * Color suppression 2 pixels
98 * or luma enhancement
99 * -------------------------------------------------------------
100 * Maximum total 14 pixels, 8 lines
101 *
102 * The color suppression and luma enhancement filters are applied after bayer to
103 * YUV conversion. They thus can crop one pixel on the left and one pixel on the
104 * right side of the image without changing the color pattern. When both those
105 * filters are disabled, the driver must crop the two pixels on the same side of
106 * the image to avoid changing the bayer pattern. The left margin is thus set to
107 * 8 pixels and the right margin to 6 pixels.
108 */
109
110#define PREV_MARGIN_LEFT 8
111#define PREV_MARGIN_RIGHT 6
112#define PREV_MARGIN_TOP 4
113#define PREV_MARGIN_BOTTOM 4
114
Laurent Pinchart059dc1d2011-10-03 07:56:15 -0300115#define PREV_MIN_IN_WIDTH 64
116#define PREV_MIN_IN_HEIGHT 8
117#define PREV_MAX_IN_HEIGHT 16384
118
Laurent Pinchartec0cae72011-10-03 07:56:15 -0300119#define PREV_MIN_OUT_WIDTH 0
120#define PREV_MIN_OUT_HEIGHT 0
121#define PREV_MAX_OUT_WIDTH_REV_1 1280
122#define PREV_MAX_OUT_WIDTH_REV_2 3300
123#define PREV_MAX_OUT_WIDTH_REV_15 4096
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300124
125/*
126 * Coeficient Tables for the submodules in Preview.
127 * Array is initialised with the values from.the tables text file.
128 */
129
130/*
131 * CFA Filter Coefficient Table
132 *
133 */
134static u32 cfa_coef_table[] = {
135#include "cfa_coef_table.h"
136};
137
138/*
139 * Default Gamma Correction Table - All components
140 */
141static u32 gamma_table[] = {
142#include "gamma_table.h"
143};
144
145/*
146 * Noise Filter Threshold table
147 */
148static u32 noise_filter_table[] = {
149#include "noise_filter_table.h"
150};
151
152/*
153 * Luminance Enhancement Table
154 */
155static u32 luma_enhance_table[] = {
156#include "luma_enhance_table.h"
157};
158
159/*
Laurent Pinchart7bec7ef2012-07-06 09:07:33 -0300160 * preview_config_luma_enhancement - Configure the Luminance Enhancement table
161 */
162static void
163preview_config_luma_enhancement(struct isp_prev_device *prev,
164 const struct prev_params *params)
165{
166 struct isp_device *isp = to_isp_device(prev);
167 const struct omap3isp_prev_luma *yt = &params->luma;
168 unsigned int i;
169
170 isp_reg_writel(isp, ISPPRV_YENH_TABLE_ADDR,
171 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
172 for (i = 0; i < OMAP3ISP_PREV_YENH_TBL_SIZE; i++) {
173 isp_reg_writel(isp, yt->table[i],
174 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_DATA);
175 }
176}
177
178/*
179 * preview_enable_luma_enhancement - Enable/disable Luminance Enhancement
180 */
181static void
182preview_enable_luma_enhancement(struct isp_prev_device *prev, bool enable)
183{
184 struct isp_device *isp = to_isp_device(prev);
185
186 if (enable)
187 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
188 ISPPRV_PCR_YNENHEN);
189 else
190 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
191 ISPPRV_PCR_YNENHEN);
192}
193
194/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300195 * preview_enable_invalaw - Enable/disable Inverse A-Law decompression
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300196 */
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300197static void preview_enable_invalaw(struct isp_prev_device *prev, bool enable)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300198{
199 struct isp_device *isp = to_isp_device(prev);
200
201 if (enable)
202 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
203 ISPPRV_PCR_WIDTH | ISPPRV_PCR_INVALAW);
204 else
205 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
206 ISPPRV_PCR_WIDTH | ISPPRV_PCR_INVALAW);
207}
208
209/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300210 * preview_config_hmed - Configure the Horizontal Median Filter
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300211 */
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300212static void preview_config_hmed(struct isp_prev_device *prev,
213 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300214{
215 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300216 const struct omap3isp_prev_hmed *hmed = &params->hmed;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300217
218 isp_reg_writel(isp, (hmed->odddist == 1 ? 0 : ISPPRV_HMED_ODDDIST) |
219 (hmed->evendist == 1 ? 0 : ISPPRV_HMED_EVENDIST) |
220 (hmed->thres << ISPPRV_HMED_THRESHOLD_SHIFT),
221 OMAP3_ISP_IOMEM_PREV, ISPPRV_HMED);
222}
223
224/*
Laurent Pinchart7bec7ef2012-07-06 09:07:33 -0300225 * preview_enable_hmed - Enable/disable the Horizontal Median Filter
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300226 */
Laurent Pinchart7bec7ef2012-07-06 09:07:33 -0300227static void preview_enable_hmed(struct isp_prev_device *prev, bool enable)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300228{
229 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300230
Laurent Pinchart7bec7ef2012-07-06 09:07:33 -0300231 if (enable)
232 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
233 ISPPRV_PCR_HMEDEN);
234 else
235 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
236 ISPPRV_PCR_HMEDEN);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300237}
238
239/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300240 * preview_config_cfa - Configure CFA Interpolation
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300241 */
242static void
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300243preview_config_cfa(struct isp_prev_device *prev,
244 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300245{
246 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300247 const struct omap3isp_prev_cfa *cfa = &params->cfa;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300248 unsigned int i;
249
250 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
251 ISPPRV_PCR_CFAFMT_MASK,
252 cfa->format << ISPPRV_PCR_CFAFMT_SHIFT);
253
254 isp_reg_writel(isp,
255 (cfa->gradthrs_vert << ISPPRV_CFA_GRADTH_VER_SHIFT) |
256 (cfa->gradthrs_horz << ISPPRV_CFA_GRADTH_HOR_SHIFT),
257 OMAP3_ISP_IOMEM_PREV, ISPPRV_CFA);
258
259 isp_reg_writel(isp, ISPPRV_CFA_TABLE_ADDR,
260 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
261
262 for (i = 0; i < OMAP3ISP_PREV_CFA_TBL_SIZE; i++) {
263 isp_reg_writel(isp, cfa->table[i],
264 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_DATA);
265 }
266}
267
268/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300269 * preview_config_chroma_suppression - Configure Chroma Suppression
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300270 */
271static void
272preview_config_chroma_suppression(struct isp_prev_device *prev,
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300273 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300274{
275 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300276 const struct omap3isp_prev_csup *cs = &params->csup;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300277
278 isp_reg_writel(isp,
279 cs->gain | (cs->thres << ISPPRV_CSUP_THRES_SHIFT) |
280 (cs->hypf_en << ISPPRV_CSUP_HPYF_SHIFT),
281 OMAP3_ISP_IOMEM_PREV, ISPPRV_CSUP);
282}
283
284/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300285 * preview_enable_chroma_suppression - Enable/disable Chrominance Suppression
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300286 */
287static void
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300288preview_enable_chroma_suppression(struct isp_prev_device *prev, bool enable)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300289{
290 struct isp_device *isp = to_isp_device(prev);
291
292 if (enable)
293 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
294 ISPPRV_PCR_SUPEN);
295 else
296 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
297 ISPPRV_PCR_SUPEN);
298}
299
300/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300301 * preview_config_whitebalance - Configure White Balance parameters
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300302 *
303 * Coefficient matrix always with default values.
304 */
305static void
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300306preview_config_whitebalance(struct isp_prev_device *prev,
307 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300308{
309 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300310 const struct omap3isp_prev_wbal *wbal = &params->wbal;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300311 u32 val;
312
313 isp_reg_writel(isp, wbal->dgain, OMAP3_ISP_IOMEM_PREV, ISPPRV_WB_DGAIN);
314
315 val = wbal->coef0 << ISPPRV_WBGAIN_COEF0_SHIFT;
316 val |= wbal->coef1 << ISPPRV_WBGAIN_COEF1_SHIFT;
317 val |= wbal->coef2 << ISPPRV_WBGAIN_COEF2_SHIFT;
318 val |= wbal->coef3 << ISPPRV_WBGAIN_COEF3_SHIFT;
319 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_WBGAIN);
320
321 isp_reg_writel(isp,
322 ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N0_0_SHIFT |
323 ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N0_1_SHIFT |
324 ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N0_2_SHIFT |
325 ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N0_3_SHIFT |
326 ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N1_0_SHIFT |
327 ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N1_1_SHIFT |
328 ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N1_2_SHIFT |
329 ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N1_3_SHIFT |
330 ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N2_0_SHIFT |
331 ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N2_1_SHIFT |
332 ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N2_2_SHIFT |
333 ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N2_3_SHIFT |
334 ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N3_0_SHIFT |
335 ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N3_1_SHIFT |
336 ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N3_2_SHIFT |
337 ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N3_3_SHIFT,
338 OMAP3_ISP_IOMEM_PREV, ISPPRV_WBSEL);
339}
340
341/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300342 * preview_config_blkadj - Configure Black Adjustment
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300343 */
344static void
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300345preview_config_blkadj(struct isp_prev_device *prev,
346 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300347{
348 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300349 const struct omap3isp_prev_blkadj *blkadj = &params->blkadj;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300350
351 isp_reg_writel(isp, (blkadj->blue << ISPPRV_BLKADJOFF_B_SHIFT) |
352 (blkadj->green << ISPPRV_BLKADJOFF_G_SHIFT) |
353 (blkadj->red << ISPPRV_BLKADJOFF_R_SHIFT),
354 OMAP3_ISP_IOMEM_PREV, ISPPRV_BLKADJOFF);
355}
356
357/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300358 * preview_config_rgb_blending - Configure RGB-RGB Blending
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300359 */
360static void
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300361preview_config_rgb_blending(struct isp_prev_device *prev,
362 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300363{
364 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300365 const struct omap3isp_prev_rgbtorgb *rgbrgb = &params->rgb2rgb;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300366 u32 val;
367
368 val = (rgbrgb->matrix[0][0] & 0xfff) << ISPPRV_RGB_MAT1_MTX_RR_SHIFT;
369 val |= (rgbrgb->matrix[0][1] & 0xfff) << ISPPRV_RGB_MAT1_MTX_GR_SHIFT;
370 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT1);
371
372 val = (rgbrgb->matrix[0][2] & 0xfff) << ISPPRV_RGB_MAT2_MTX_BR_SHIFT;
373 val |= (rgbrgb->matrix[1][0] & 0xfff) << ISPPRV_RGB_MAT2_MTX_RG_SHIFT;
374 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT2);
375
376 val = (rgbrgb->matrix[1][1] & 0xfff) << ISPPRV_RGB_MAT3_MTX_GG_SHIFT;
377 val |= (rgbrgb->matrix[1][2] & 0xfff) << ISPPRV_RGB_MAT3_MTX_BG_SHIFT;
378 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT3);
379
380 val = (rgbrgb->matrix[2][0] & 0xfff) << ISPPRV_RGB_MAT4_MTX_RB_SHIFT;
381 val |= (rgbrgb->matrix[2][1] & 0xfff) << ISPPRV_RGB_MAT4_MTX_GB_SHIFT;
382 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT4);
383
384 val = (rgbrgb->matrix[2][2] & 0xfff) << ISPPRV_RGB_MAT5_MTX_BB_SHIFT;
385 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT5);
386
387 val = (rgbrgb->offset[0] & 0x3ff) << ISPPRV_RGB_OFF1_MTX_OFFR_SHIFT;
388 val |= (rgbrgb->offset[1] & 0x3ff) << ISPPRV_RGB_OFF1_MTX_OFFG_SHIFT;
389 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_OFF1);
390
391 val = (rgbrgb->offset[2] & 0x3ff) << ISPPRV_RGB_OFF2_MTX_OFFB_SHIFT;
392 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_OFF2);
393}
394
395/*
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300396 * preview_config_csc - Configure Color Space Conversion (RGB to YCbYCr)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300397 */
398static void
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300399preview_config_csc(struct isp_prev_device *prev,
400 const struct prev_params *params)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300401{
402 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300403 const struct omap3isp_prev_csc *csc = &params->csc;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300404 u32 val;
405
406 val = (csc->matrix[0][0] & 0x3ff) << ISPPRV_CSC0_RY_SHIFT;
407 val |= (csc->matrix[0][1] & 0x3ff) << ISPPRV_CSC0_GY_SHIFT;
408 val |= (csc->matrix[0][2] & 0x3ff) << ISPPRV_CSC0_BY_SHIFT;
409 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC0);
410
411 val = (csc->matrix[1][0] & 0x3ff) << ISPPRV_CSC1_RCB_SHIFT;
412 val |= (csc->matrix[1][1] & 0x3ff) << ISPPRV_CSC1_GCB_SHIFT;
413 val |= (csc->matrix[1][2] & 0x3ff) << ISPPRV_CSC1_BCB_SHIFT;
414 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC1);
415
416 val = (csc->matrix[2][0] & 0x3ff) << ISPPRV_CSC2_RCR_SHIFT;
417 val |= (csc->matrix[2][1] & 0x3ff) << ISPPRV_CSC2_GCR_SHIFT;
418 val |= (csc->matrix[2][2] & 0x3ff) << ISPPRV_CSC2_BCR_SHIFT;
419 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC2);
420
421 val = (csc->offset[0] & 0xff) << ISPPRV_CSC_OFFSET_Y_SHIFT;
422 val |= (csc->offset[1] & 0xff) << ISPPRV_CSC_OFFSET_CB_SHIFT;
423 val |= (csc->offset[2] & 0xff) << ISPPRV_CSC_OFFSET_CR_SHIFT;
424 isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC_OFFSET);
425}
426
427/*
Laurent Pinchart7bec7ef2012-07-06 09:07:33 -0300428 * preview_config_yc_range - Configure the max and min Y and C values
429 */
430static void
431preview_config_yc_range(struct isp_prev_device *prev,
432 const struct prev_params *params)
433{
434 struct isp_device *isp = to_isp_device(prev);
435 const struct omap3isp_prev_yclimit *yc = &params->yclimit;
436
437 isp_reg_writel(isp,
438 yc->maxC << ISPPRV_SETUP_YC_MAXC_SHIFT |
439 yc->maxY << ISPPRV_SETUP_YC_MAXY_SHIFT |
440 yc->minC << ISPPRV_SETUP_YC_MINC_SHIFT |
441 yc->minY << ISPPRV_SETUP_YC_MINY_SHIFT,
442 OMAP3_ISP_IOMEM_PREV, ISPPRV_SETUP_YC);
443}
444
445/*
446 * preview_config_dcor - Configure Couplet Defect Correction
447 */
448static void
449preview_config_dcor(struct isp_prev_device *prev,
450 const struct prev_params *params)
451{
452 struct isp_device *isp = to_isp_device(prev);
453 const struct omap3isp_prev_dcor *dcor = &params->dcor;
454
455 isp_reg_writel(isp, dcor->detect_correct[0],
456 OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR0);
457 isp_reg_writel(isp, dcor->detect_correct[1],
458 OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR1);
459 isp_reg_writel(isp, dcor->detect_correct[2],
460 OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR2);
461 isp_reg_writel(isp, dcor->detect_correct[3],
462 OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR3);
463 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
464 ISPPRV_PCR_DCCOUP,
465 dcor->couplet_mode_en ? ISPPRV_PCR_DCCOUP : 0);
466}
467
468/*
469 * preview_enable_dcor - Enable/disable Couplet Defect Correction
470 */
471static void preview_enable_dcor(struct isp_prev_device *prev, bool enable)
472{
473 struct isp_device *isp = to_isp_device(prev);
474
475 if (enable)
476 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
477 ISPPRV_PCR_DCOREN);
478 else
479 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
480 ISPPRV_PCR_DCOREN);
481}
482
483/*
484 * preview_enable_gammabypass - Enable/disable Gamma Bypass
485 *
486 * When gamma bypass is enabled, the output of the gamma correction is the 8 MSB
487 * of the 10-bit input .
488 */
489static void
490preview_enable_gammabypass(struct isp_prev_device *prev, bool enable)
491{
492 struct isp_device *isp = to_isp_device(prev);
493
494 if (enable)
495 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
496 ISPPRV_PCR_GAMMA_BYPASS);
497 else
498 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
499 ISPPRV_PCR_GAMMA_BYPASS);
500}
501
502/*
503 * preview_enable_drkframe_capture - Enable/disable Dark Frame Capture
504 */
505static void
506preview_enable_drkframe_capture(struct isp_prev_device *prev, bool enable)
507{
508 struct isp_device *isp = to_isp_device(prev);
509
510 if (enable)
511 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
512 ISPPRV_PCR_DRKFCAP);
513 else
514 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
515 ISPPRV_PCR_DRKFCAP);
516}
517
518/*
519 * preview_enable_drkframe - Enable/disable Dark Frame Subtraction
520 */
521static void preview_enable_drkframe(struct isp_prev_device *prev, bool enable)
522{
523 struct isp_device *isp = to_isp_device(prev);
524
525 if (enable)
526 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
527 ISPPRV_PCR_DRKFEN);
528 else
529 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
530 ISPPRV_PCR_DRKFEN);
531}
532
533/*
534 * preview_config_noisefilter - Configure the Noise Filter
535 */
536static void
537preview_config_noisefilter(struct isp_prev_device *prev,
538 const struct prev_params *params)
539{
540 struct isp_device *isp = to_isp_device(prev);
541 const struct omap3isp_prev_nf *nf = &params->nf;
542 unsigned int i;
543
544 isp_reg_writel(isp, nf->spread, OMAP3_ISP_IOMEM_PREV, ISPPRV_NF);
545 isp_reg_writel(isp, ISPPRV_NF_TABLE_ADDR,
546 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
547 for (i = 0; i < OMAP3ISP_PREV_NF_TBL_SIZE; i++) {
548 isp_reg_writel(isp, nf->table[i],
549 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_DATA);
550 }
551}
552
553/*
554 * preview_enable_noisefilter - Enable/disable the Noise Filter
555 */
556static void
557preview_enable_noisefilter(struct isp_prev_device *prev, bool enable)
558{
559 struct isp_device *isp = to_isp_device(prev);
560
561 if (enable)
562 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
563 ISPPRV_PCR_NFEN);
564 else
565 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
566 ISPPRV_PCR_NFEN);
567}
568
569/*
570 * preview_config_gammacorrn - Configure the Gamma Correction tables
571 */
572static void
573preview_config_gammacorrn(struct isp_prev_device *prev,
574 const struct prev_params *params)
575{
576 struct isp_device *isp = to_isp_device(prev);
577 const struct omap3isp_prev_gtables *gt = &params->gamma;
578 unsigned int i;
579
580 isp_reg_writel(isp, ISPPRV_REDGAMMA_TABLE_ADDR,
581 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
582 for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++)
583 isp_reg_writel(isp, gt->red[i], OMAP3_ISP_IOMEM_PREV,
584 ISPPRV_SET_TBL_DATA);
585
586 isp_reg_writel(isp, ISPPRV_GREENGAMMA_TABLE_ADDR,
587 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
588 for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++)
589 isp_reg_writel(isp, gt->green[i], OMAP3_ISP_IOMEM_PREV,
590 ISPPRV_SET_TBL_DATA);
591
592 isp_reg_writel(isp, ISPPRV_BLUEGAMMA_TABLE_ADDR,
593 OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
594 for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++)
595 isp_reg_writel(isp, gt->blue[i], OMAP3_ISP_IOMEM_PREV,
596 ISPPRV_SET_TBL_DATA);
597}
598
599/*
600 * preview_config_contrast - Configure the Contrast
601 *
602 * Value should be programmed before enabling the module.
603 */
604static void
605preview_config_contrast(struct isp_prev_device *prev,
606 const struct prev_params *params)
607{
608 struct isp_device *isp = to_isp_device(prev);
609
610 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT,
611 0xff << ISPPRV_CNT_BRT_CNT_SHIFT,
612 params->contrast << ISPPRV_CNT_BRT_CNT_SHIFT);
613}
614
615/*
616 * preview_config_brightness - Configure the Brightness
617 */
618static void
619preview_config_brightness(struct isp_prev_device *prev,
620 const struct prev_params *params)
621{
622 struct isp_device *isp = to_isp_device(prev);
623
624 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT,
625 0xff << ISPPRV_CNT_BRT_BRT_SHIFT,
626 params->brightness << ISPPRV_CNT_BRT_BRT_SHIFT);
627}
628
629/*
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300630 * preview_update_contrast - Updates the contrast.
631 * @contrast: Pointer to hold the current programmed contrast value.
632 *
633 * Value should be programmed before enabling the module.
634 */
635static void
636preview_update_contrast(struct isp_prev_device *prev, u8 contrast)
637{
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300638 struct prev_params *params;
639 unsigned long flags;
640
641 spin_lock_irqsave(&prev->params.lock, flags);
642 params = (prev->params.active & OMAP3ISP_PREV_CONTRAST)
643 ? &prev->params.params[0] : &prev->params.params[1];
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300644
645 if (params->contrast != (contrast * ISPPRV_CONTRAST_UNITS)) {
646 params->contrast = contrast * ISPPRV_CONTRAST_UNITS;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300647 params->update |= OMAP3ISP_PREV_CONTRAST;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300648 }
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300649 spin_unlock_irqrestore(&prev->params.lock, flags);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300650}
651
652/*
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300653 * preview_update_brightness - Updates the brightness in preview module.
654 * @brightness: Pointer to hold the current programmed brightness value.
655 *
656 */
657static void
658preview_update_brightness(struct isp_prev_device *prev, u8 brightness)
659{
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300660 struct prev_params *params;
661 unsigned long flags;
662
663 spin_lock_irqsave(&prev->params.lock, flags);
664 params = (prev->params.active & OMAP3ISP_PREV_BRIGHTNESS)
665 ? &prev->params.params[0] : &prev->params.params[1];
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300666
667 if (params->brightness != (brightness * ISPPRV_BRIGHT_UNITS)) {
668 params->brightness = brightness * ISPPRV_BRIGHT_UNITS;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300669 params->update |= OMAP3ISP_PREV_BRIGHTNESS;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300670 }
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300671 spin_unlock_irqrestore(&prev->params.lock, flags);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300672}
673
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300674static u32
675preview_params_lock(struct isp_prev_device *prev, u32 update, bool shadow)
676{
677 u32 active = prev->params.active;
678
679 if (shadow) {
680 /* Mark all shadow parameters we are going to touch as busy. */
681 prev->params.params[0].busy |= ~active & update;
682 prev->params.params[1].busy |= active & update;
683 } else {
684 /* Mark all active parameters we are going to touch as busy. */
685 update = (prev->params.params[0].update & active)
686 | (prev->params.params[1].update & ~active);
687
688 prev->params.params[0].busy |= active & update;
689 prev->params.params[1].busy |= ~active & update;
690 }
691
692 return update;
693}
694
695static void
696preview_params_unlock(struct isp_prev_device *prev, u32 update, bool shadow)
697{
698 u32 active = prev->params.active;
699
700 if (shadow) {
701 /* Set the update flag for shadow parameters that have been
702 * updated and clear the busy flag for all shadow parameters.
703 */
704 prev->params.params[0].update |= (~active & update);
705 prev->params.params[1].update |= (active & update);
706 prev->params.params[0].busy &= active;
707 prev->params.params[1].busy &= ~active;
708 } else {
709 /* Clear the update flag for active parameters that have been
710 * applied and the busy flag for all active parameters.
711 */
712 prev->params.params[0].update &= ~(active & update);
713 prev->params.params[1].update &= ~(~active & update);
714 prev->params.params[0].busy &= ~active;
715 prev->params.params[1].busy &= active;
716 }
717}
718
719static void preview_params_switch(struct isp_prev_device *prev)
720{
721 u32 to_switch;
722
723 /* Switch active parameters with updated shadow parameters when the
724 * shadow parameter has been updated and neither the active not the
725 * shadow parameter is busy.
726 */
727 to_switch = (prev->params.params[0].update & ~prev->params.active)
728 | (prev->params.params[1].update & prev->params.active);
729 to_switch &= ~(prev->params.params[0].busy |
730 prev->params.params[1].busy);
731 if (to_switch == 0)
732 return;
733
734 prev->params.active ^= to_switch;
735
736 /* Remove the update flag for the shadow copy of parameters we have
737 * switched.
738 */
739 prev->params.params[0].update &= ~(~prev->params.active & to_switch);
740 prev->params.params[1].update &= ~(prev->params.active & to_switch);
741}
742
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300743/* preview parameters update structure */
744struct preview_update {
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300745 void (*config)(struct isp_prev_device *, const struct prev_params *);
746 void (*enable)(struct isp_prev_device *, bool);
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300747 unsigned int param_offset;
748 unsigned int param_size;
749 unsigned int config_offset;
Laurent Pinchart3108e022012-04-05 12:38:23 -0300750 bool skip;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300751};
752
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300753/* Keep the array indexed by the OMAP3ISP_PREV_* bit number. */
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300754static const struct preview_update update_attrs[] = {
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300755 /* OMAP3ISP_PREV_LUMAENH */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300756 preview_config_luma_enhancement,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300757 preview_enable_luma_enhancement,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300758 offsetof(struct prev_params, luma),
759 FIELD_SIZEOF(struct prev_params, luma),
760 offsetof(struct omap3isp_prev_update_config, luma),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300761 }, /* OMAP3ISP_PREV_INVALAW */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300762 NULL,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300763 preview_enable_invalaw,
764 }, /* OMAP3ISP_PREV_HRZ_MED */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300765 preview_config_hmed,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300766 preview_enable_hmed,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300767 offsetof(struct prev_params, hmed),
768 FIELD_SIZEOF(struct prev_params, hmed),
769 offsetof(struct omap3isp_prev_update_config, hmed),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300770 }, /* OMAP3ISP_PREV_CFA */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300771 preview_config_cfa,
Laurent Pinchartb2da46e2012-04-19 13:38:29 -0300772 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300773 offsetof(struct prev_params, cfa),
774 FIELD_SIZEOF(struct prev_params, cfa),
775 offsetof(struct omap3isp_prev_update_config, cfa),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300776 }, /* OMAP3ISP_PREV_CHROMA_SUPP */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300777 preview_config_chroma_suppression,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300778 preview_enable_chroma_suppression,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300779 offsetof(struct prev_params, csup),
780 FIELD_SIZEOF(struct prev_params, csup),
781 offsetof(struct omap3isp_prev_update_config, csup),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300782 }, /* OMAP3ISP_PREV_WB */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300783 preview_config_whitebalance,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300784 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300785 offsetof(struct prev_params, wbal),
786 FIELD_SIZEOF(struct prev_params, wbal),
787 offsetof(struct omap3isp_prev_update_config, wbal),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300788 }, /* OMAP3ISP_PREV_BLKADJ */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300789 preview_config_blkadj,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300790 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300791 offsetof(struct prev_params, blkadj),
792 FIELD_SIZEOF(struct prev_params, blkadj),
793 offsetof(struct omap3isp_prev_update_config, blkadj),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300794 }, /* OMAP3ISP_PREV_RGB2RGB */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300795 preview_config_rgb_blending,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300796 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300797 offsetof(struct prev_params, rgb2rgb),
798 FIELD_SIZEOF(struct prev_params, rgb2rgb),
799 offsetof(struct omap3isp_prev_update_config, rgb2rgb),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300800 }, /* OMAP3ISP_PREV_COLOR_CONV */ {
Laurent Pinchart61738502012-04-17 13:05:12 -0300801 preview_config_csc,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300802 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300803 offsetof(struct prev_params, csc),
804 FIELD_SIZEOF(struct prev_params, csc),
805 offsetof(struct omap3isp_prev_update_config, csc),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300806 }, /* OMAP3ISP_PREV_YC_LIMIT */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300807 preview_config_yc_range,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300808 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300809 offsetof(struct prev_params, yclimit),
810 FIELD_SIZEOF(struct prev_params, yclimit),
811 offsetof(struct omap3isp_prev_update_config, yclimit),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300812 }, /* OMAP3ISP_PREV_DEFECT_COR */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300813 preview_config_dcor,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300814 preview_enable_dcor,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300815 offsetof(struct prev_params, dcor),
816 FIELD_SIZEOF(struct prev_params, dcor),
817 offsetof(struct omap3isp_prev_update_config, dcor),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300818 }, /* OMAP3ISP_PREV_GAMMABYPASS */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300819 NULL,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300820 preview_enable_gammabypass,
821 }, /* OMAP3ISP_PREV_DRK_FRM_CAPTURE */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300822 NULL,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300823 preview_enable_drkframe_capture,
824 }, /* OMAP3ISP_PREV_DRK_FRM_SUBTRACT */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300825 NULL,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300826 preview_enable_drkframe,
827 }, /* OMAP3ISP_PREV_LENS_SHADING */ {
Laurent Pinchartfbabfa82012-07-06 08:26:57 -0300828 NULL,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300829 preview_enable_drkframe,
830 }, /* OMAP3ISP_PREV_NF */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300831 preview_config_noisefilter,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300832 preview_enable_noisefilter,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300833 offsetof(struct prev_params, nf),
834 FIELD_SIZEOF(struct prev_params, nf),
835 offsetof(struct omap3isp_prev_update_config, nf),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300836 }, /* OMAP3ISP_PREV_GAMMA */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300837 preview_config_gammacorrn,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300838 NULL,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300839 offsetof(struct prev_params, gamma),
840 FIELD_SIZEOF(struct prev_params, gamma),
841 offsetof(struct omap3isp_prev_update_config, gamma),
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300842 }, /* OMAP3ISP_PREV_CONTRAST */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300843 preview_config_contrast,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300844 NULL,
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300845 0, 0, 0, true,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300846 }, /* OMAP3ISP_PREV_BRIGHTNESS */ {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300847 preview_config_brightness,
Laurent Pinchartbac387e2012-04-09 09:25:34 -0300848 NULL,
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300849 0, 0, 0, true,
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300850 },
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300851};
852
853/*
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300854 * preview_config - Copy and update local structure with userspace preview
855 * configuration.
856 * @prev: ISP preview engine
857 * @cfg: Configuration
858 *
859 * Return zero if success or -EFAULT if the configuration can't be copied from
860 * userspace.
861 */
862static int preview_config(struct isp_prev_device *prev,
863 struct omap3isp_prev_update_config *cfg)
864{
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300865 unsigned long flags;
866 unsigned int i;
867 int rval = 0;
868 u32 update;
869 u32 active;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300870
Laurent Pinchartf22926e2012-03-26 10:24:50 -0300871 if (cfg->update == 0)
872 return 0;
873
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300874 /* Mark the shadow parameters we're going to update as busy. */
875 spin_lock_irqsave(&prev->params.lock, flags);
876 preview_params_lock(prev, cfg->update, true);
877 active = prev->params.active;
878 spin_unlock_irqrestore(&prev->params.lock, flags);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300879
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300880 update = 0;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300881
882 for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300883 const struct preview_update *attr = &update_attrs[i];
884 struct prev_params *params;
885 unsigned int bit = 1 << i;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300886
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300887 if (attr->skip || !(cfg->update & bit))
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300888 continue;
889
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300890 params = &prev->params.params[!!(active & bit)];
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300891
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300892 if (cfg->flag & bit) {
893 void __user *from = *(void * __user *)
894 ((void *)cfg + attr->config_offset);
895 void *to = (void *)params + attr->param_offset;
896 size_t size = attr->param_size;
897
898 if (to && from && size) {
899 if (copy_from_user(to, from, size)) {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300900 rval = -EFAULT;
901 break;
902 }
903 }
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300904 params->features |= bit;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300905 } else {
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300906 params->features &= ~bit;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300907 }
908
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300909 update |= bit;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300910 }
911
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300912 spin_lock_irqsave(&prev->params.lock, flags);
913 preview_params_unlock(prev, update, true);
914 preview_params_switch(prev);
915 spin_unlock_irqrestore(&prev->params.lock, flags);
916
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300917 return rval;
918}
919
920/*
921 * preview_setup_hw - Setup preview registers and/or internal memory
922 * @prev: pointer to preview private structure
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300923 * @update: Bitmask of parameters to setup
924 * @active: Bitmask of parameters active in set 0
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300925 * Note: can be called from interrupt context
926 * Return none
927 */
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300928static void preview_setup_hw(struct isp_prev_device *prev, u32 update,
929 u32 active)
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300930{
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300931 unsigned int i;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300932 u32 features;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300933
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300934 if (update == 0)
Laurent Pinchartf22926e2012-03-26 10:24:50 -0300935 return;
936
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300937 features = (prev->params.params[0].features & active)
938 | (prev->params.params[1].features & ~active);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300939
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300940 for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
941 const struct preview_update *attr = &update_attrs[i];
942 struct prev_params *params;
943 unsigned int bit = 1 << i;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300944
945 if (!(update & bit))
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300946 continue;
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300947
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300948 params = &prev->params.params[!(active & bit)];
949
Laurent Pinchart7ed5de92012-04-05 13:51:17 -0300950 if (params->features & bit) {
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300951 if (attr->config)
952 attr->config(prev, params);
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300953 if (attr->enable)
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300954 attr->enable(prev, true);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300955 } else {
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300956 if (attr->enable)
Laurent Pinchart6f1dd562012-07-06 08:43:27 -0300957 attr->enable(prev, false);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300958 }
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300959 }
960}
961
962/*
963 * preview_config_ycpos - Configure byte layout of YUV image.
964 * @mode: Indicates the required byte layout.
965 */
966static void
967preview_config_ycpos(struct isp_prev_device *prev,
968 enum v4l2_mbus_pixelcode pixelcode)
969{
970 struct isp_device *isp = to_isp_device(prev);
971 enum preview_ycpos_mode mode;
972
973 switch (pixelcode) {
974 case V4L2_MBUS_FMT_YUYV8_1X16:
975 mode = YCPOS_CrYCbY;
976 break;
977 case V4L2_MBUS_FMT_UYVY8_1X16:
978 mode = YCPOS_YCrYCb;
979 break;
980 default:
981 return;
982 }
983
984 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
985 ISPPRV_PCR_YCPOS_CrYCbY,
986 mode << ISPPRV_PCR_YCPOS_SHIFT);
987}
988
989/*
990 * preview_config_averager - Enable / disable / configure averager
991 * @average: Average value to be configured.
992 */
993static void preview_config_averager(struct isp_prev_device *prev, u8 average)
994{
995 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300996 struct prev_params *params;
Laurent Pinchartde1135d2011-02-12 18:05:06 -0300997 int reg = 0;
998
Laurent Pinchartb0b29e12012-03-26 10:24:50 -0300999 params = (prev->params.active & OMAP3ISP_PREV_CFA)
1000 ? &prev->params.params[0] : &prev->params.params[1];
1001
1002 if (params->cfa.format == OMAP3ISP_CFAFMT_BAYER)
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001003 reg = ISPPRV_AVE_EVENDIST_2 << ISPPRV_AVE_EVENDIST_SHIFT |
1004 ISPPRV_AVE_ODDDIST_2 << ISPPRV_AVE_ODDDIST_SHIFT |
1005 average;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001006 else if (params->cfa.format == OMAP3ISP_CFAFMT_RGBFOVEON)
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001007 reg = ISPPRV_AVE_EVENDIST_3 << ISPPRV_AVE_EVENDIST_SHIFT |
1008 ISPPRV_AVE_ODDDIST_3 << ISPPRV_AVE_ODDDIST_SHIFT |
1009 average;
1010 isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_PREV, ISPPRV_AVE);
1011}
1012
1013/*
Laurent Pinchartb2da46e2012-04-19 13:38:29 -03001014 * preview_config_input_format - Configure the input format
1015 * @prev: The preview engine
1016 * @format: Format on the preview engine sink pad
1017 *
1018 * Enable CFA interpolation for Bayer formats and disable it for greyscale
1019 * formats.
1020 */
1021static void preview_config_input_format(struct isp_prev_device *prev,
1022 const struct v4l2_mbus_framefmt *format)
1023{
1024 struct isp_device *isp = to_isp_device(prev);
1025
1026 if (format->code != V4L2_MBUS_FMT_Y10_1X10)
1027 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1028 ISPPRV_PCR_CFAEN);
1029 else
1030 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1031 ISPPRV_PCR_CFAEN);
1032}
1033
1034/*
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001035 * preview_config_input_size - Configure the input frame size
1036 *
1037 * The preview engine crops several rows and columns internally depending on
1038 * which processing blocks are enabled. The driver assumes all those blocks are
1039 * enabled when reporting source pad formats to userspace. If this assumption is
1040 * not true, rows and columns must be manually cropped at the preview engine
1041 * input to avoid overflows at the end of lines and frames.
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001042 *
1043 * See the explanation at the PREV_MARGIN_* definitions for more details.
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001044 */
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001045static void preview_config_input_size(struct isp_prev_device *prev, u32 active)
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001046{
Laurent Pinchartb2da46e2012-04-19 13:38:29 -03001047 const struct v4l2_mbus_framefmt *format = &prev->formats[PREV_PAD_SINK];
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001048 struct isp_device *isp = to_isp_device(prev);
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001049 unsigned int sph = prev->crop.left;
1050 unsigned int eph = prev->crop.left + prev->crop.width - 1;
1051 unsigned int slv = prev->crop.top;
1052 unsigned int elv = prev->crop.top + prev->crop.height - 1;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001053 u32 features;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001054
Laurent Pinchart71031802012-07-05 14:31:33 -03001055 if (format->code != V4L2_MBUS_FMT_Y10_1X10) {
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001056 sph -= 2;
1057 eph += 2;
1058 slv -= 2;
1059 elv += 2;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001060 }
Laurent Pinchartb2da46e2012-04-19 13:38:29 -03001061
1062 features = (prev->params.params[0].features & active)
1063 | (prev->params.params[1].features & ~active);
1064
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001065 if (features & (OMAP3ISP_PREV_DEFECT_COR | OMAP3ISP_PREV_NF)) {
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001066 sph -= 2;
1067 eph += 2;
1068 slv -= 2;
1069 elv += 2;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001070 }
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001071 if (features & OMAP3ISP_PREV_HRZ_MED) {
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001072 sph -= 2;
1073 eph += 2;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001074 }
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001075 if (features & (OMAP3ISP_PREV_CHROMA_SUPP | OMAP3ISP_PREV_LUMAENH))
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001076 sph -= 2;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001077
1078 isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph,
1079 OMAP3_ISP_IOMEM_PREV, ISPPRV_HORZ_INFO);
1080 isp_reg_writel(isp, (slv << ISPPRV_VERT_INFO_SLV_SHIFT) | elv,
1081 OMAP3_ISP_IOMEM_PREV, ISPPRV_VERT_INFO);
1082}
1083
1084/*
1085 * preview_config_inlineoffset - Configures the Read address line offset.
1086 * @prev: Preview module
1087 * @offset: Line offset
1088 *
1089 * According to the TRM, the line offset must be aligned on a 32 bytes boundary.
1090 * However, a hardware bug requires the memory start address to be aligned on a
1091 * 64 bytes boundary, so the offset probably should be aligned on 64 bytes as
1092 * well.
1093 */
1094static void
1095preview_config_inlineoffset(struct isp_prev_device *prev, u32 offset)
1096{
1097 struct isp_device *isp = to_isp_device(prev);
1098
1099 isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV,
1100 ISPPRV_RADR_OFFSET);
1101}
1102
1103/*
1104 * preview_set_inaddr - Sets memory address of input frame.
1105 * @addr: 32bit memory address aligned on 32byte boundary.
1106 *
1107 * Configures the memory address from which the input frame is to be read.
1108 */
1109static void preview_set_inaddr(struct isp_prev_device *prev, u32 addr)
1110{
1111 struct isp_device *isp = to_isp_device(prev);
1112
1113 isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_RSDR_ADDR);
1114}
1115
1116/*
1117 * preview_config_outlineoffset - Configures the Write address line offset.
1118 * @offset: Line Offset for the preview output.
1119 *
1120 * The offset must be a multiple of 32 bytes.
1121 */
1122static void preview_config_outlineoffset(struct isp_prev_device *prev,
1123 u32 offset)
1124{
1125 struct isp_device *isp = to_isp_device(prev);
1126
1127 isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV,
1128 ISPPRV_WADD_OFFSET);
1129}
1130
1131/*
1132 * preview_set_outaddr - Sets the memory address to store output frame
1133 * @addr: 32bit memory address aligned on 32byte boundary.
1134 *
1135 * Configures the memory address to which the output frame is written.
1136 */
1137static void preview_set_outaddr(struct isp_prev_device *prev, u32 addr)
1138{
1139 struct isp_device *isp = to_isp_device(prev);
1140
1141 isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_WSDR_ADDR);
1142}
1143
1144static void preview_adjust_bandwidth(struct isp_prev_device *prev)
1145{
1146 struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity);
1147 struct isp_device *isp = to_isp_device(prev);
1148 const struct v4l2_mbus_framefmt *ifmt = &prev->formats[PREV_PAD_SINK];
1149 unsigned long l3_ick = pipe->l3_ick;
1150 struct v4l2_fract *timeperframe;
1151 unsigned int cycles_per_frame;
1152 unsigned int requests_per_frame;
1153 unsigned int cycles_per_request;
1154 unsigned int minimum;
1155 unsigned int maximum;
1156 unsigned int value;
1157
1158 if (prev->input != PREVIEW_INPUT_MEMORY) {
1159 isp_reg_clr(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
1160 ISPSBL_SDR_REQ_PRV_EXP_MASK);
1161 return;
1162 }
1163
1164 /* Compute the minimum number of cycles per request, based on the
1165 * pipeline maximum data rate. This is an absolute lower bound if we
1166 * don't want SBL overflows, so round the value up.
1167 */
1168 cycles_per_request = div_u64((u64)l3_ick / 2 * 256 + pipe->max_rate - 1,
1169 pipe->max_rate);
1170 minimum = DIV_ROUND_UP(cycles_per_request, 32);
1171
1172 /* Compute the maximum number of cycles per request, based on the
1173 * requested frame rate. This is a soft upper bound to achieve a frame
1174 * rate equal or higher than the requested value, so round the value
1175 * down.
1176 */
1177 timeperframe = &pipe->max_timeperframe;
1178
1179 requests_per_frame = DIV_ROUND_UP(ifmt->width * 2, 256) * ifmt->height;
1180 cycles_per_frame = div_u64((u64)l3_ick * timeperframe->numerator,
1181 timeperframe->denominator);
1182 cycles_per_request = cycles_per_frame / requests_per_frame;
1183
1184 maximum = cycles_per_request / 32;
1185
1186 value = max(minimum, maximum);
1187
1188 dev_dbg(isp->dev, "%s: cycles per request = %u\n", __func__, value);
1189 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
1190 ISPSBL_SDR_REQ_PRV_EXP_MASK,
1191 value << ISPSBL_SDR_REQ_PRV_EXP_SHIFT);
1192}
1193
1194/*
1195 * omap3isp_preview_busy - Gets busy state of preview module.
1196 */
1197int omap3isp_preview_busy(struct isp_prev_device *prev)
1198{
1199 struct isp_device *isp = to_isp_device(prev);
1200
1201 return isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR)
1202 & ISPPRV_PCR_BUSY;
1203}
1204
1205/*
1206 * omap3isp_preview_restore_context - Restores the values of preview registers
1207 */
1208void omap3isp_preview_restore_context(struct isp_device *isp)
1209{
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001210 struct isp_prev_device *prev = &isp->isp_prev;
1211 const u32 update = OMAP3ISP_PREV_FEATURES_END - 1;
1212
1213 prev->params.params[0].update = prev->params.active & update;
1214 prev->params.params[1].update = ~prev->params.active & update;
1215
1216 preview_setup_hw(prev, update, prev->params.active);
1217
1218 prev->params.params[0].update = 0;
1219 prev->params.params[1].update = 0;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001220}
1221
1222/*
1223 * preview_print_status - Dump preview module registers to the kernel log
1224 */
1225#define PREV_PRINT_REGISTER(isp, name)\
1226 dev_dbg(isp->dev, "###PRV " #name "=0x%08x\n", \
1227 isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_##name))
1228
1229static void preview_print_status(struct isp_prev_device *prev)
1230{
1231 struct isp_device *isp = to_isp_device(prev);
1232
1233 dev_dbg(isp->dev, "-------------Preview Register dump----------\n");
1234
1235 PREV_PRINT_REGISTER(isp, PCR);
1236 PREV_PRINT_REGISTER(isp, HORZ_INFO);
1237 PREV_PRINT_REGISTER(isp, VERT_INFO);
1238 PREV_PRINT_REGISTER(isp, RSDR_ADDR);
1239 PREV_PRINT_REGISTER(isp, RADR_OFFSET);
1240 PREV_PRINT_REGISTER(isp, DSDR_ADDR);
1241 PREV_PRINT_REGISTER(isp, DRKF_OFFSET);
1242 PREV_PRINT_REGISTER(isp, WSDR_ADDR);
1243 PREV_PRINT_REGISTER(isp, WADD_OFFSET);
1244 PREV_PRINT_REGISTER(isp, AVE);
1245 PREV_PRINT_REGISTER(isp, HMED);
1246 PREV_PRINT_REGISTER(isp, NF);
1247 PREV_PRINT_REGISTER(isp, WB_DGAIN);
1248 PREV_PRINT_REGISTER(isp, WBGAIN);
1249 PREV_PRINT_REGISTER(isp, WBSEL);
1250 PREV_PRINT_REGISTER(isp, CFA);
1251 PREV_PRINT_REGISTER(isp, BLKADJOFF);
1252 PREV_PRINT_REGISTER(isp, RGB_MAT1);
1253 PREV_PRINT_REGISTER(isp, RGB_MAT2);
1254 PREV_PRINT_REGISTER(isp, RGB_MAT3);
1255 PREV_PRINT_REGISTER(isp, RGB_MAT4);
1256 PREV_PRINT_REGISTER(isp, RGB_MAT5);
1257 PREV_PRINT_REGISTER(isp, RGB_OFF1);
1258 PREV_PRINT_REGISTER(isp, RGB_OFF2);
1259 PREV_PRINT_REGISTER(isp, CSC0);
1260 PREV_PRINT_REGISTER(isp, CSC1);
1261 PREV_PRINT_REGISTER(isp, CSC2);
1262 PREV_PRINT_REGISTER(isp, CSC_OFFSET);
1263 PREV_PRINT_REGISTER(isp, CNT_BRT);
1264 PREV_PRINT_REGISTER(isp, CSUP);
1265 PREV_PRINT_REGISTER(isp, SETUP_YC);
1266 PREV_PRINT_REGISTER(isp, SET_TBL_ADDR);
1267 PREV_PRINT_REGISTER(isp, CDC_THR0);
1268 PREV_PRINT_REGISTER(isp, CDC_THR1);
1269 PREV_PRINT_REGISTER(isp, CDC_THR2);
1270 PREV_PRINT_REGISTER(isp, CDC_THR3);
1271
1272 dev_dbg(isp->dev, "--------------------------------------------\n");
1273}
1274
1275/*
1276 * preview_init_params - init image processing parameters.
1277 * @prev: pointer to previewer private structure
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001278 */
1279static void preview_init_params(struct isp_prev_device *prev)
1280{
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001281 struct prev_params *params;
1282 unsigned int i;
1283
1284 spin_lock_init(&prev->params.lock);
1285
1286 prev->params.active = ~0;
1287 prev->params.params[0].busy = 0;
1288 prev->params.params[0].update = OMAP3ISP_PREV_FEATURES_END - 1;
1289 prev->params.params[1].busy = 0;
1290 prev->params.params[1].update = 0;
1291
1292 params = &prev->params.params[0];
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001293
1294 /* Init values */
1295 params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS;
1296 params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001297 params->cfa.format = OMAP3ISP_CFAFMT_BAYER;
1298 memcpy(params->cfa.table, cfa_coef_table,
1299 sizeof(params->cfa.table));
1300 params->cfa.gradthrs_horz = FLR_CFA_GRADTHRS_HORZ;
1301 params->cfa.gradthrs_vert = FLR_CFA_GRADTHRS_VERT;
1302 params->csup.gain = FLR_CSUP_GAIN;
1303 params->csup.thres = FLR_CSUP_THRES;
1304 params->csup.hypf_en = 0;
1305 memcpy(params->luma.table, luma_enhance_table,
1306 sizeof(params->luma.table));
1307 params->nf.spread = FLR_NF_STRGTH;
1308 memcpy(params->nf.table, noise_filter_table, sizeof(params->nf.table));
1309 params->dcor.couplet_mode_en = 1;
1310 for (i = 0; i < OMAP3ISP_PREV_DETECT_CORRECT_CHANNELS; i++)
1311 params->dcor.detect_correct[i] = DEF_DETECT_CORRECT_VAL;
1312 memcpy(params->gamma.blue, gamma_table, sizeof(params->gamma.blue));
1313 memcpy(params->gamma.green, gamma_table, sizeof(params->gamma.green));
1314 memcpy(params->gamma.red, gamma_table, sizeof(params->gamma.red));
1315 params->wbal.dgain = FLR_WBAL_DGAIN;
1316 params->wbal.coef0 = FLR_WBAL_COEF;
1317 params->wbal.coef1 = FLR_WBAL_COEF;
1318 params->wbal.coef2 = FLR_WBAL_COEF;
1319 params->wbal.coef3 = FLR_WBAL_COEF;
Laurent Pinchart9b001842012-04-05 13:51:17 -03001320 params->blkadj.red = FLR_BLKADJ_RED;
1321 params->blkadj.green = FLR_BLKADJ_GREEN;
1322 params->blkadj.blue = FLR_BLKADJ_BLUE;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001323 params->rgb2rgb = flr_rgb2rgb;
Laurent Pinchart9b001842012-04-05 13:51:17 -03001324 params->csc = flr_prev_csc;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001325 params->yclimit.minC = ISPPRV_YC_MIN;
1326 params->yclimit.maxC = ISPPRV_YC_MAX;
1327 params->yclimit.minY = ISPPRV_YC_MIN;
1328 params->yclimit.maxY = ISPPRV_YC_MAX;
1329
Laurent Pinchart3108e022012-04-05 12:38:23 -03001330 params->features = OMAP3ISP_PREV_CFA | OMAP3ISP_PREV_DEFECT_COR
1331 | OMAP3ISP_PREV_NF | OMAP3ISP_PREV_GAMMA
1332 | OMAP3ISP_PREV_BLKADJ | OMAP3ISP_PREV_YC_LIMIT
1333 | OMAP3ISP_PREV_RGB2RGB | OMAP3ISP_PREV_COLOR_CONV
1334 | OMAP3ISP_PREV_WB | OMAP3ISP_PREV_BRIGHTNESS
1335 | OMAP3ISP_PREV_CONTRAST;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001336}
1337
1338/*
1339 * preview_max_out_width - Handle previewer hardware ouput limitations
1340 * @isp_revision : ISP revision
1341 * returns maximum width output for current isp revision
1342 */
1343static unsigned int preview_max_out_width(struct isp_prev_device *prev)
1344{
1345 struct isp_device *isp = to_isp_device(prev);
1346
1347 switch (isp->revision) {
1348 case ISP_REVISION_1_0:
Laurent Pinchartec0cae72011-10-03 07:56:15 -03001349 return PREV_MAX_OUT_WIDTH_REV_1;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001350
1351 case ISP_REVISION_2_0:
1352 default:
Laurent Pinchartec0cae72011-10-03 07:56:15 -03001353 return PREV_MAX_OUT_WIDTH_REV_2;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001354
1355 case ISP_REVISION_15_0:
Laurent Pinchartec0cae72011-10-03 07:56:15 -03001356 return PREV_MAX_OUT_WIDTH_REV_15;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001357 }
1358}
1359
1360static void preview_configure(struct isp_prev_device *prev)
1361{
1362 struct isp_device *isp = to_isp_device(prev);
1363 struct v4l2_mbus_framefmt *format;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001364 unsigned long flags;
1365 u32 update;
1366 u32 active;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001367
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001368 spin_lock_irqsave(&prev->params.lock, flags);
1369 /* Mark all active parameters we are going to touch as busy. */
1370 update = preview_params_lock(prev, 0, false);
1371 active = prev->params.active;
1372 spin_unlock_irqrestore(&prev->params.lock, flags);
1373
1374 preview_setup_hw(prev, update, active);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001375
1376 if (prev->output & PREVIEW_OUTPUT_MEMORY)
1377 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1378 ISPPRV_PCR_SDRPORT);
1379 else
1380 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1381 ISPPRV_PCR_SDRPORT);
1382
1383 if (prev->output & PREVIEW_OUTPUT_RESIZER)
1384 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1385 ISPPRV_PCR_RSZPORT);
1386 else
1387 isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1388 ISPPRV_PCR_RSZPORT);
1389
1390 /* PREV_PAD_SINK */
1391 format = &prev->formats[PREV_PAD_SINK];
1392
1393 preview_adjust_bandwidth(prev);
1394
Laurent Pinchartb2da46e2012-04-19 13:38:29 -03001395 preview_config_input_format(prev, format);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001396 preview_config_input_size(prev, active);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001397
1398 if (prev->input == PREVIEW_INPUT_CCDC)
1399 preview_config_inlineoffset(prev, 0);
1400 else
1401 preview_config_inlineoffset(prev,
1402 ALIGN(format->width, 0x20) * 2);
1403
1404 /* PREV_PAD_SOURCE */
1405 format = &prev->formats[PREV_PAD_SOURCE];
1406
1407 if (prev->output & PREVIEW_OUTPUT_MEMORY)
1408 preview_config_outlineoffset(prev,
1409 ALIGN(format->width, 0x10) * 2);
1410
Laurent Pincharte4bc6272011-09-21 07:54:44 -03001411 preview_config_averager(prev, 0);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001412 preview_config_ycpos(prev, format->code);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001413
1414 spin_lock_irqsave(&prev->params.lock, flags);
1415 preview_params_unlock(prev, update, false);
1416 spin_unlock_irqrestore(&prev->params.lock, flags);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001417}
1418
1419/* -----------------------------------------------------------------------------
1420 * Interrupt handling
1421 */
1422
1423static void preview_enable_oneshot(struct isp_prev_device *prev)
1424{
1425 struct isp_device *isp = to_isp_device(prev);
1426
1427 /* The PCR.SOURCE bit is automatically reset to 0 when the PCR.ENABLE
1428 * bit is set. As the preview engine is used in single-shot mode, we
1429 * need to set PCR.SOURCE before enabling the preview engine.
1430 */
1431 if (prev->input == PREVIEW_INPUT_MEMORY)
1432 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1433 ISPPRV_PCR_SOURCE);
1434
1435 isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
1436 ISPPRV_PCR_EN | ISPPRV_PCR_ONESHOT);
1437}
1438
1439void omap3isp_preview_isr_frame_sync(struct isp_prev_device *prev)
1440{
1441 /*
1442 * If ISP_VIDEO_DMAQUEUE_QUEUED is set, DMA queue had an underrun
1443 * condition, the module was paused and now we have a buffer queued
1444 * on the output again. Restart the pipeline if running in continuous
1445 * mode.
1446 */
1447 if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS &&
1448 prev->video_out.dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED) {
1449 preview_enable_oneshot(prev);
1450 isp_video_dmaqueue_flags_clr(&prev->video_out);
1451 }
1452}
1453
1454static void preview_isr_buffer(struct isp_prev_device *prev)
1455{
1456 struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity);
1457 struct isp_buffer *buffer;
1458 int restart = 0;
1459
1460 if (prev->input == PREVIEW_INPUT_MEMORY) {
Laurent Pinchart875e2e32011-12-07 08:34:50 -03001461 buffer = omap3isp_video_buffer_next(&prev->video_in);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001462 if (buffer != NULL)
1463 preview_set_inaddr(prev, buffer->isp_addr);
1464 pipe->state |= ISP_PIPELINE_IDLE_INPUT;
1465 }
1466
1467 if (prev->output & PREVIEW_OUTPUT_MEMORY) {
Laurent Pinchart875e2e32011-12-07 08:34:50 -03001468 buffer = omap3isp_video_buffer_next(&prev->video_out);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001469 if (buffer != NULL) {
1470 preview_set_outaddr(prev, buffer->isp_addr);
1471 restart = 1;
1472 }
1473 pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
1474 }
1475
1476 switch (prev->state) {
1477 case ISP_PIPELINE_STREAM_SINGLESHOT:
1478 if (isp_pipeline_ready(pipe))
1479 omap3isp_pipeline_set_stream(pipe,
1480 ISP_PIPELINE_STREAM_SINGLESHOT);
1481 break;
1482
1483 case ISP_PIPELINE_STREAM_CONTINUOUS:
1484 /* If an underrun occurs, the video queue operation handler will
1485 * restart the preview engine. Otherwise restart it immediately.
1486 */
1487 if (restart)
1488 preview_enable_oneshot(prev);
1489 break;
1490
1491 case ISP_PIPELINE_STREAM_STOPPED:
1492 default:
1493 return;
1494 }
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001495}
1496
1497/*
1498 * omap3isp_preview_isr - ISP preview engine interrupt handler
1499 *
1500 * Manage the preview engine video buffers and configure shadowed registers.
1501 */
1502void omap3isp_preview_isr(struct isp_prev_device *prev)
1503{
1504 unsigned long flags;
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001505 u32 update;
1506 u32 active;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001507
1508 if (omap3isp_module_sync_is_stopping(&prev->wait, &prev->stopping))
1509 return;
1510
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001511 spin_lock_irqsave(&prev->params.lock, flags);
1512 preview_params_switch(prev);
1513 update = preview_params_lock(prev, 0, false);
1514 active = prev->params.active;
1515 spin_unlock_irqrestore(&prev->params.lock, flags);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001516
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001517 preview_setup_hw(prev, update, active);
1518 preview_config_input_size(prev, active);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001519
1520 if (prev->input == PREVIEW_INPUT_MEMORY ||
1521 prev->output & PREVIEW_OUTPUT_MEMORY)
1522 preview_isr_buffer(prev);
1523 else if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS)
1524 preview_enable_oneshot(prev);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03001525
1526 spin_lock_irqsave(&prev->params.lock, flags);
1527 preview_params_unlock(prev, update, false);
1528 spin_unlock_irqrestore(&prev->params.lock, flags);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001529}
1530
1531/* -----------------------------------------------------------------------------
1532 * ISP video operations
1533 */
1534
1535static int preview_video_queue(struct isp_video *video,
1536 struct isp_buffer *buffer)
1537{
1538 struct isp_prev_device *prev = &video->isp->isp_prev;
1539
1540 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1541 preview_set_inaddr(prev, buffer->isp_addr);
1542
1543 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1544 preview_set_outaddr(prev, buffer->isp_addr);
1545
1546 return 0;
1547}
1548
1549static const struct isp_video_operations preview_video_ops = {
1550 .queue = preview_video_queue,
1551};
1552
1553/* -----------------------------------------------------------------------------
1554 * V4L2 subdev operations
1555 */
1556
1557/*
1558 * preview_s_ctrl - Handle set control subdev method
1559 * @ctrl: pointer to v4l2 control structure
1560 */
1561static int preview_s_ctrl(struct v4l2_ctrl *ctrl)
1562{
1563 struct isp_prev_device *prev =
1564 container_of(ctrl->handler, struct isp_prev_device, ctrls);
1565
1566 switch (ctrl->id) {
1567 case V4L2_CID_BRIGHTNESS:
1568 preview_update_brightness(prev, ctrl->val);
1569 break;
1570 case V4L2_CID_CONTRAST:
1571 preview_update_contrast(prev, ctrl->val);
1572 break;
1573 }
1574
1575 return 0;
1576}
1577
1578static const struct v4l2_ctrl_ops preview_ctrl_ops = {
1579 .s_ctrl = preview_s_ctrl,
1580};
1581
1582/*
1583 * preview_ioctl - Handle preview module private ioctl's
1584 * @prev: pointer to preview context structure
1585 * @cmd: configuration command
1586 * @arg: configuration argument
1587 * return -EINVAL or zero on success
1588 */
1589static long preview_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1590{
1591 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1592
1593 switch (cmd) {
1594 case VIDIOC_OMAP3ISP_PRV_CFG:
1595 return preview_config(prev, arg);
1596
1597 default:
1598 return -ENOIOCTLCMD;
1599 }
1600}
1601
1602/*
1603 * preview_set_stream - Enable/Disable streaming on preview subdev
1604 * @sd : pointer to v4l2 subdev structure
1605 * @enable: 1 == Enable, 0 == Disable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001606 * return -EINVAL or zero on success
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001607 */
1608static int preview_set_stream(struct v4l2_subdev *sd, int enable)
1609{
1610 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1611 struct isp_video *video_out = &prev->video_out;
1612 struct isp_device *isp = to_isp_device(prev);
1613 struct device *dev = to_device(prev);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001614
1615 if (prev->state == ISP_PIPELINE_STREAM_STOPPED) {
1616 if (enable == ISP_PIPELINE_STREAM_STOPPED)
1617 return 0;
1618
1619 omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_PREVIEW);
1620 preview_configure(prev);
1621 atomic_set(&prev->stopping, 0);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001622 preview_print_status(prev);
1623 }
1624
1625 switch (enable) {
1626 case ISP_PIPELINE_STREAM_CONTINUOUS:
1627 if (prev->output & PREVIEW_OUTPUT_MEMORY)
1628 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
1629
1630 if (video_out->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED ||
1631 !(prev->output & PREVIEW_OUTPUT_MEMORY))
1632 preview_enable_oneshot(prev);
1633
1634 isp_video_dmaqueue_flags_clr(video_out);
1635 break;
1636
1637 case ISP_PIPELINE_STREAM_SINGLESHOT:
1638 if (prev->input == PREVIEW_INPUT_MEMORY)
1639 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_READ);
1640 if (prev->output & PREVIEW_OUTPUT_MEMORY)
1641 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
1642
1643 preview_enable_oneshot(prev);
1644 break;
1645
1646 case ISP_PIPELINE_STREAM_STOPPED:
1647 if (omap3isp_module_sync_idle(&sd->entity, &prev->wait,
1648 &prev->stopping))
1649 dev_dbg(dev, "%s: stop timeout.\n", sd->name);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001650 omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_READ);
1651 omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
1652 omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_PREVIEW);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001653 isp_video_dmaqueue_flags_clr(video_out);
1654 break;
1655 }
1656
1657 prev->state = enable;
1658 return 0;
1659}
1660
1661static struct v4l2_mbus_framefmt *
1662__preview_get_format(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
1663 unsigned int pad, enum v4l2_subdev_format_whence which)
1664{
1665 if (which == V4L2_SUBDEV_FORMAT_TRY)
1666 return v4l2_subdev_get_try_format(fh, pad);
1667 else
1668 return &prev->formats[pad];
1669}
1670
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001671static struct v4l2_rect *
1672__preview_get_crop(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
1673 enum v4l2_subdev_format_whence which)
1674{
1675 if (which == V4L2_SUBDEV_FORMAT_TRY)
1676 return v4l2_subdev_get_try_crop(fh, PREV_PAD_SINK);
1677 else
1678 return &prev->crop;
1679}
1680
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001681/* previewer format descriptions */
1682static const unsigned int preview_input_fmts[] = {
Laurent Pinchartb2da46e2012-04-19 13:38:29 -03001683 V4L2_MBUS_FMT_Y10_1X10,
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001684 V4L2_MBUS_FMT_SGRBG10_1X10,
1685 V4L2_MBUS_FMT_SRGGB10_1X10,
1686 V4L2_MBUS_FMT_SBGGR10_1X10,
1687 V4L2_MBUS_FMT_SGBRG10_1X10,
1688};
1689
1690static const unsigned int preview_output_fmts[] = {
1691 V4L2_MBUS_FMT_UYVY8_1X16,
1692 V4L2_MBUS_FMT_YUYV8_1X16,
1693};
1694
1695/*
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001696 * preview_try_format - Validate a format
1697 * @prev: ISP preview engine
1698 * @fh: V4L2 subdev file handle
1699 * @pad: pad number
1700 * @fmt: format to be validated
1701 * @which: try/active format selector
1702 *
1703 * Validate and adjust the given format for the given pad based on the preview
1704 * engine limits and the format and crop rectangles on other pads.
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001705 */
1706static void preview_try_format(struct isp_prev_device *prev,
1707 struct v4l2_subdev_fh *fh, unsigned int pad,
1708 struct v4l2_mbus_framefmt *fmt,
1709 enum v4l2_subdev_format_whence which)
1710{
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001711 enum v4l2_mbus_pixelcode pixelcode;
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001712 struct v4l2_rect *crop;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001713 unsigned int i;
1714
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001715 switch (pad) {
1716 case PREV_PAD_SINK:
1717 /* When reading data from the CCDC, the input size has already
1718 * been mangled by the CCDC output pad so it can be accepted
1719 * as-is.
1720 *
1721 * When reading data from memory, clamp the requested width and
1722 * height. The TRM doesn't specify a minimum input height, make
1723 * sure we got enough lines to enable the noise filter and color
1724 * filter array interpolation.
1725 */
1726 if (prev->input == PREVIEW_INPUT_MEMORY) {
Laurent Pinchart059dc1d2011-10-03 07:56:15 -03001727 fmt->width = clamp_t(u32, fmt->width, PREV_MIN_IN_WIDTH,
1728 preview_max_out_width(prev));
1729 fmt->height = clamp_t(u32, fmt->height,
1730 PREV_MIN_IN_HEIGHT,
1731 PREV_MAX_IN_HEIGHT);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001732 }
1733
1734 fmt->colorspace = V4L2_COLORSPACE_SRGB;
1735
1736 for (i = 0; i < ARRAY_SIZE(preview_input_fmts); i++) {
1737 if (fmt->code == preview_input_fmts[i])
1738 break;
1739 }
1740
1741 /* If not found, use SGRBG10 as default */
1742 if (i >= ARRAY_SIZE(preview_input_fmts))
1743 fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;
1744 break;
1745
1746 case PREV_PAD_SOURCE:
1747 pixelcode = fmt->code;
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001748 *fmt = *__preview_get_format(prev, fh, PREV_PAD_SINK, which);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001749
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001750 switch (pixelcode) {
1751 case V4L2_MBUS_FMT_YUYV8_1X16:
1752 case V4L2_MBUS_FMT_UYVY8_1X16:
1753 fmt->code = pixelcode;
1754 break;
1755
1756 default:
1757 fmt->code = V4L2_MBUS_FMT_YUYV8_1X16;
1758 break;
1759 }
1760
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001761 /* The preview module output size is configurable through the
1762 * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). This
1763 * is not supported yet, hardcode the output size to the crop
1764 * rectangle size.
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001765 */
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001766 crop = __preview_get_crop(prev, fh, which);
1767 fmt->width = crop->width;
1768 fmt->height = crop->height;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001769
1770 fmt->colorspace = V4L2_COLORSPACE_JPEG;
1771 break;
1772 }
1773
1774 fmt->field = V4L2_FIELD_NONE;
1775}
1776
1777/*
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001778 * preview_try_crop - Validate a crop rectangle
1779 * @prev: ISP preview engine
1780 * @sink: format on the sink pad
1781 * @crop: crop rectangle to be validated
1782 *
1783 * The preview engine crops lines and columns for its internal operation,
1784 * depending on which filters are enabled. Enforce minimum crop margins to
1785 * handle that transparently for userspace.
1786 *
1787 * See the explanation at the PREV_MARGIN_* definitions for more details.
1788 */
1789static void preview_try_crop(struct isp_prev_device *prev,
1790 const struct v4l2_mbus_framefmt *sink,
1791 struct v4l2_rect *crop)
1792{
1793 unsigned int left = PREV_MARGIN_LEFT;
1794 unsigned int right = sink->width - PREV_MARGIN_RIGHT;
1795 unsigned int top = PREV_MARGIN_TOP;
1796 unsigned int bottom = sink->height - PREV_MARGIN_BOTTOM;
1797
1798 /* When processing data on-the-fly from the CCDC, at least 2 pixels must
1799 * be cropped from the left and right sides of the image. As we don't
1800 * know which filters will be enabled, increase the left and right
1801 * margins by two.
1802 */
1803 if (prev->input == PREVIEW_INPUT_CCDC) {
1804 left += 2;
1805 right -= 2;
1806 }
1807
1808 /* Restrict left/top to even values to keep the Bayer pattern. */
1809 crop->left &= ~1;
1810 crop->top &= ~1;
1811
1812 crop->left = clamp_t(u32, crop->left, left, right - PREV_MIN_OUT_WIDTH);
1813 crop->top = clamp_t(u32, crop->top, top, bottom - PREV_MIN_OUT_HEIGHT);
1814 crop->width = clamp_t(u32, crop->width, PREV_MIN_OUT_WIDTH,
1815 right - crop->left);
1816 crop->height = clamp_t(u32, crop->height, PREV_MIN_OUT_HEIGHT,
1817 bottom - crop->top);
1818}
1819
1820/*
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001821 * preview_enum_mbus_code - Handle pixel format enumeration
1822 * @sd : pointer to v4l2 subdev structure
1823 * @fh : V4L2 subdev file handle
1824 * @code : pointer to v4l2_subdev_mbus_code_enum structure
1825 * return -EINVAL or zero on success
1826 */
1827static int preview_enum_mbus_code(struct v4l2_subdev *sd,
1828 struct v4l2_subdev_fh *fh,
1829 struct v4l2_subdev_mbus_code_enum *code)
1830{
1831 switch (code->pad) {
1832 case PREV_PAD_SINK:
1833 if (code->index >= ARRAY_SIZE(preview_input_fmts))
1834 return -EINVAL;
1835
1836 code->code = preview_input_fmts[code->index];
1837 break;
1838 case PREV_PAD_SOURCE:
1839 if (code->index >= ARRAY_SIZE(preview_output_fmts))
1840 return -EINVAL;
1841
1842 code->code = preview_output_fmts[code->index];
1843 break;
1844 default:
1845 return -EINVAL;
1846 }
1847
1848 return 0;
1849}
1850
1851static int preview_enum_frame_size(struct v4l2_subdev *sd,
1852 struct v4l2_subdev_fh *fh,
1853 struct v4l2_subdev_frame_size_enum *fse)
1854{
1855 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1856 struct v4l2_mbus_framefmt format;
1857
1858 if (fse->index != 0)
1859 return -EINVAL;
1860
1861 format.code = fse->code;
1862 format.width = 1;
1863 format.height = 1;
1864 preview_try_format(prev, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
1865 fse->min_width = format.width;
1866 fse->min_height = format.height;
1867
1868 if (format.code != fse->code)
1869 return -EINVAL;
1870
1871 format.code = fse->code;
1872 format.width = -1;
1873 format.height = -1;
1874 preview_try_format(prev, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
1875 fse->max_width = format.width;
1876 fse->max_height = format.height;
1877
1878 return 0;
1879}
1880
1881/*
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001882 * preview_get_selection - Retrieve a selection rectangle on a pad
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001883 * @sd: ISP preview V4L2 subdevice
1884 * @fh: V4L2 subdev file handle
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001885 * @sel: Selection rectangle
1886 *
1887 * The only supported rectangles are the crop rectangles on the sink pad.
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001888 *
1889 * Return 0 on success or a negative error code otherwise.
1890 */
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001891static int preview_get_selection(struct v4l2_subdev *sd,
1892 struct v4l2_subdev_fh *fh,
1893 struct v4l2_subdev_selection *sel)
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001894{
1895 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1896 struct v4l2_mbus_framefmt *format;
1897
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001898 if (sel->pad != PREV_PAD_SINK)
1899 return -EINVAL;
1900
1901 switch (sel->target) {
Sakari Ailus5689b282012-05-18 09:31:18 -03001902 case V4L2_SEL_TGT_CROP_BOUNDS:
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001903 sel->r.left = 0;
1904 sel->r.top = 0;
1905 sel->r.width = INT_MAX;
1906 sel->r.height = INT_MAX;
1907
1908 format = __preview_get_format(prev, fh, PREV_PAD_SINK,
1909 sel->which);
1910 preview_try_crop(prev, format, &sel->r);
1911 break;
1912
Sakari Ailus5689b282012-05-18 09:31:18 -03001913 case V4L2_SEL_TGT_CROP:
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001914 sel->r = *__preview_get_crop(prev, fh, sel->which);
1915 break;
1916
1917 default:
1918 return -EINVAL;
1919 }
1920
1921 return 0;
1922}
1923
1924/*
1925 * preview_set_selection - Set a selection rectangle on a pad
1926 * @sd: ISP preview V4L2 subdevice
1927 * @fh: V4L2 subdev file handle
1928 * @sel: Selection rectangle
1929 *
1930 * The only supported rectangle is the actual crop rectangle on the sink pad.
1931 *
1932 * Return 0 on success or a negative error code otherwise.
1933 */
1934static int preview_set_selection(struct v4l2_subdev *sd,
1935 struct v4l2_subdev_fh *fh,
1936 struct v4l2_subdev_selection *sel)
1937{
1938 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1939 struct v4l2_mbus_framefmt *format;
1940
Sakari Ailus5689b282012-05-18 09:31:18 -03001941 if (sel->target != V4L2_SEL_TGT_CROP ||
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001942 sel->pad != PREV_PAD_SINK)
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001943 return -EINVAL;
1944
1945 /* The crop rectangle can't be changed while streaming. */
1946 if (prev->state != ISP_PIPELINE_STREAM_STOPPED)
1947 return -EBUSY;
1948
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001949 /* Modifying the crop rectangle always changes the format on the source
1950 * pad. If the KEEP_CONFIG flag is set, just return the current crop
1951 * rectangle.
1952 */
Sakari Ailus563df3d2012-06-13 16:01:10 -03001953 if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001954 sel->r = *__preview_get_crop(prev, fh, sel->which);
1955 return 0;
1956 }
1957
1958 format = __preview_get_format(prev, fh, PREV_PAD_SINK, sel->which);
1959 preview_try_crop(prev, format, &sel->r);
1960 *__preview_get_crop(prev, fh, sel->which) = sel->r;
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001961
1962 /* Update the source format. */
Laurent Pinchart684c8e22012-04-20 05:47:49 -03001963 format = __preview_get_format(prev, fh, PREV_PAD_SOURCE, sel->which);
1964 preview_try_format(prev, fh, PREV_PAD_SOURCE, format, sel->which);
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03001965
1966 return 0;
1967}
1968
1969/*
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001970 * preview_get_format - Handle get format by pads subdev method
1971 * @sd : pointer to v4l2 subdev structure
1972 * @fh : V4L2 subdev file handle
1973 * @fmt: pointer to v4l2 subdev format structure
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001974 * return -EINVAL or zero on success
Laurent Pinchartde1135d2011-02-12 18:05:06 -03001975 */
1976static int preview_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1977 struct v4l2_subdev_format *fmt)
1978{
1979 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1980 struct v4l2_mbus_framefmt *format;
1981
1982 format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
1983 if (format == NULL)
1984 return -EINVAL;
1985
1986 fmt->format = *format;
1987 return 0;
1988}
1989
1990/*
1991 * preview_set_format - Handle set format by pads subdev method
1992 * @sd : pointer to v4l2 subdev structure
1993 * @fh : V4L2 subdev file handle
1994 * @fmt: pointer to v4l2 subdev format structure
1995 * return -EINVAL or zero on success
1996 */
1997static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1998 struct v4l2_subdev_format *fmt)
1999{
2000 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
2001 struct v4l2_mbus_framefmt *format;
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03002002 struct v4l2_rect *crop;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002003
2004 format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
2005 if (format == NULL)
2006 return -EINVAL;
2007
2008 preview_try_format(prev, fh, fmt->pad, &fmt->format, fmt->which);
2009 *format = fmt->format;
2010
2011 /* Propagate the format from sink to source */
2012 if (fmt->pad == PREV_PAD_SINK) {
Laurent Pinchart1f69fd92011-09-21 20:05:45 -03002013 /* Reset the crop rectangle. */
2014 crop = __preview_get_crop(prev, fh, fmt->which);
2015 crop->left = 0;
2016 crop->top = 0;
2017 crop->width = fmt->format.width;
2018 crop->height = fmt->format.height;
2019
2020 preview_try_crop(prev, &fmt->format, crop);
2021
2022 /* Update the source format. */
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002023 format = __preview_get_format(prev, fh, PREV_PAD_SOURCE,
2024 fmt->which);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002025 preview_try_format(prev, fh, PREV_PAD_SOURCE, format,
2026 fmt->which);
2027 }
2028
2029 return 0;
2030}
2031
2032/*
2033 * preview_init_formats - Initialize formats on all pads
2034 * @sd: ISP preview V4L2 subdevice
2035 * @fh: V4L2 subdev file handle
2036 *
2037 * Initialize all pad formats with default values. If fh is not NULL, try
2038 * formats are initialized on the file handle. Otherwise active formats are
2039 * initialized on the device.
2040 */
2041static int preview_init_formats(struct v4l2_subdev *sd,
2042 struct v4l2_subdev_fh *fh)
2043{
2044 struct v4l2_subdev_format format;
2045
2046 memset(&format, 0, sizeof(format));
2047 format.pad = PREV_PAD_SINK;
2048 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
2049 format.format.code = V4L2_MBUS_FMT_SGRBG10_1X10;
2050 format.format.width = 4096;
2051 format.format.height = 4096;
2052 preview_set_format(sd, fh, &format);
2053
2054 return 0;
2055}
2056
2057/* subdev core operations */
2058static const struct v4l2_subdev_core_ops preview_v4l2_core_ops = {
2059 .ioctl = preview_ioctl,
2060};
2061
2062/* subdev video operations */
2063static const struct v4l2_subdev_video_ops preview_v4l2_video_ops = {
2064 .s_stream = preview_set_stream,
2065};
2066
2067/* subdev pad operations */
2068static const struct v4l2_subdev_pad_ops preview_v4l2_pad_ops = {
2069 .enum_mbus_code = preview_enum_mbus_code,
2070 .enum_frame_size = preview_enum_frame_size,
2071 .get_fmt = preview_get_format,
2072 .set_fmt = preview_set_format,
Laurent Pinchart684c8e22012-04-20 05:47:49 -03002073 .get_selection = preview_get_selection,
2074 .set_selection = preview_set_selection,
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002075};
2076
2077/* subdev operations */
2078static const struct v4l2_subdev_ops preview_v4l2_ops = {
2079 .core = &preview_v4l2_core_ops,
2080 .video = &preview_v4l2_video_ops,
2081 .pad = &preview_v4l2_pad_ops,
2082};
2083
2084/* subdev internal operations */
2085static const struct v4l2_subdev_internal_ops preview_v4l2_internal_ops = {
2086 .open = preview_init_formats,
2087};
2088
2089/* -----------------------------------------------------------------------------
2090 * Media entity operations
2091 */
2092
2093/*
2094 * preview_link_setup - Setup previewer connections.
2095 * @entity : Pointer to media entity structure
2096 * @local : Pointer to local pad array
2097 * @remote : Pointer to remote pad array
2098 * @flags : Link flags
2099 * return -EINVAL or zero on success
2100 */
2101static int preview_link_setup(struct media_entity *entity,
2102 const struct media_pad *local,
2103 const struct media_pad *remote, u32 flags)
2104{
2105 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
2106 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
2107
2108 switch (local->index | media_entity_type(remote->entity)) {
2109 case PREV_PAD_SINK | MEDIA_ENT_T_DEVNODE:
2110 /* read from memory */
2111 if (flags & MEDIA_LNK_FL_ENABLED) {
2112 if (prev->input == PREVIEW_INPUT_CCDC)
2113 return -EBUSY;
2114 prev->input = PREVIEW_INPUT_MEMORY;
2115 } else {
2116 if (prev->input == PREVIEW_INPUT_MEMORY)
2117 prev->input = PREVIEW_INPUT_NONE;
2118 }
2119 break;
2120
2121 case PREV_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
2122 /* read from ccdc */
2123 if (flags & MEDIA_LNK_FL_ENABLED) {
2124 if (prev->input == PREVIEW_INPUT_MEMORY)
2125 return -EBUSY;
2126 prev->input = PREVIEW_INPUT_CCDC;
2127 } else {
2128 if (prev->input == PREVIEW_INPUT_CCDC)
2129 prev->input = PREVIEW_INPUT_NONE;
2130 }
2131 break;
2132
2133 /*
2134 * The ISP core doesn't support pipelines with multiple video outputs.
2135 * Revisit this when it will be implemented, and return -EBUSY for now.
2136 */
2137
2138 case PREV_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
2139 /* write to memory */
2140 if (flags & MEDIA_LNK_FL_ENABLED) {
2141 if (prev->output & ~PREVIEW_OUTPUT_MEMORY)
2142 return -EBUSY;
2143 prev->output |= PREVIEW_OUTPUT_MEMORY;
2144 } else {
2145 prev->output &= ~PREVIEW_OUTPUT_MEMORY;
2146 }
2147 break;
2148
2149 case PREV_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
2150 /* write to resizer */
2151 if (flags & MEDIA_LNK_FL_ENABLED) {
2152 if (prev->output & ~PREVIEW_OUTPUT_RESIZER)
2153 return -EBUSY;
2154 prev->output |= PREVIEW_OUTPUT_RESIZER;
2155 } else {
2156 prev->output &= ~PREVIEW_OUTPUT_RESIZER;
2157 }
2158 break;
2159
2160 default:
2161 return -EINVAL;
2162 }
2163
2164 return 0;
2165}
2166
2167/* media operations */
2168static const struct media_entity_operations preview_media_ops = {
2169 .link_setup = preview_link_setup,
Sakari Ailus20d4ab72012-01-11 13:27:02 -03002170 .link_validate = v4l2_subdev_link_validate,
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002171};
2172
Laurent Pinchart39099d02011-09-22 16:59:26 -03002173void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
2174{
2175 v4l2_device_unregister_subdev(&prev->subdev);
2176 omap3isp_video_unregister(&prev->video_in);
2177 omap3isp_video_unregister(&prev->video_out);
2178}
2179
2180int omap3isp_preview_register_entities(struct isp_prev_device *prev,
2181 struct v4l2_device *vdev)
2182{
2183 int ret;
2184
2185 /* Register the subdev and video nodes. */
2186 ret = v4l2_device_register_subdev(vdev, &prev->subdev);
2187 if (ret < 0)
2188 goto error;
2189
2190 ret = omap3isp_video_register(&prev->video_in, vdev);
2191 if (ret < 0)
2192 goto error;
2193
2194 ret = omap3isp_video_register(&prev->video_out, vdev);
2195 if (ret < 0)
2196 goto error;
2197
2198 return 0;
2199
2200error:
2201 omap3isp_preview_unregister_entities(prev);
2202 return ret;
2203}
2204
2205/* -----------------------------------------------------------------------------
2206 * ISP previewer initialisation and cleanup
2207 */
2208
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002209/*
Laurent Pinchart39099d02011-09-22 16:59:26 -03002210 * preview_init_entities - Initialize subdev and media entity.
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002211 * @prev : Pointer to preview structure
2212 * return -ENOMEM or zero on success
2213 */
2214static int preview_init_entities(struct isp_prev_device *prev)
2215{
2216 struct v4l2_subdev *sd = &prev->subdev;
2217 struct media_pad *pads = prev->pads;
2218 struct media_entity *me = &sd->entity;
2219 int ret;
2220
2221 prev->input = PREVIEW_INPUT_NONE;
2222
2223 v4l2_subdev_init(sd, &preview_v4l2_ops);
2224 sd->internal_ops = &preview_v4l2_internal_ops;
2225 strlcpy(sd->name, "OMAP3 ISP preview", sizeof(sd->name));
2226 sd->grp_id = 1 << 16; /* group ID for isp subdevs */
2227 v4l2_set_subdevdata(sd, prev);
2228 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2229
2230 v4l2_ctrl_handler_init(&prev->ctrls, 2);
2231 v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_BRIGHTNESS,
2232 ISPPRV_BRIGHT_LOW, ISPPRV_BRIGHT_HIGH,
2233 ISPPRV_BRIGHT_STEP, ISPPRV_BRIGHT_DEF);
2234 v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_CONTRAST,
2235 ISPPRV_CONTRAST_LOW, ISPPRV_CONTRAST_HIGH,
2236 ISPPRV_CONTRAST_STEP, ISPPRV_CONTRAST_DEF);
2237 v4l2_ctrl_handler_setup(&prev->ctrls);
2238 sd->ctrl_handler = &prev->ctrls;
2239
2240 pads[PREV_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
2241 pads[PREV_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
2242
2243 me->ops = &preview_media_ops;
2244 ret = media_entity_init(me, PREV_PADS_NUM, pads, 0);
2245 if (ret < 0)
2246 return ret;
2247
2248 preview_init_formats(sd, NULL);
2249
2250 /* According to the OMAP34xx TRM, video buffers need to be aligned on a
2251 * 32 bytes boundary. However, an undocumented hardware bug requires a
2252 * 64 bytes boundary at the preview engine input.
2253 */
2254 prev->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
2255 prev->video_in.ops = &preview_video_ops;
2256 prev->video_in.isp = to_isp_device(prev);
2257 prev->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
2258 prev->video_in.bpl_alignment = 64;
2259 prev->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2260 prev->video_out.ops = &preview_video_ops;
2261 prev->video_out.isp = to_isp_device(prev);
2262 prev->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
2263 prev->video_out.bpl_alignment = 32;
2264
2265 ret = omap3isp_video_init(&prev->video_in, "preview");
2266 if (ret < 0)
Laurent Pinchart9b6390b2011-09-22 17:10:30 -03002267 goto error_video_in;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002268
2269 ret = omap3isp_video_init(&prev->video_out, "preview");
2270 if (ret < 0)
Laurent Pinchart9b6390b2011-09-22 17:10:30 -03002271 goto error_video_out;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002272
2273 /* Connect the video nodes to the previewer subdev. */
2274 ret = media_entity_create_link(&prev->video_in.video.entity, 0,
2275 &prev->subdev.entity, PREV_PAD_SINK, 0);
2276 if (ret < 0)
Laurent Pinchart9b6390b2011-09-22 17:10:30 -03002277 goto error_link;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002278
2279 ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
2280 &prev->video_out.video.entity, 0, 0);
2281 if (ret < 0)
Laurent Pinchart9b6390b2011-09-22 17:10:30 -03002282 goto error_link;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002283
2284 return 0;
Laurent Pinchart9b6390b2011-09-22 17:10:30 -03002285
2286error_link:
2287 omap3isp_video_cleanup(&prev->video_out);
2288error_video_out:
2289 omap3isp_video_cleanup(&prev->video_in);
2290error_video_in:
2291 media_entity_cleanup(&prev->subdev.entity);
2292 return ret;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002293}
2294
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002295/*
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03002296 * omap3isp_preview_init - Previewer initialization.
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002297 * @dev : Pointer to ISP device
2298 * return -ENOMEM or zero on success
2299 */
2300int omap3isp_preview_init(struct isp_device *isp)
2301{
2302 struct isp_prev_device *prev = &isp->isp_prev;
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002303
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002304 init_waitqueue_head(&prev->wait);
Laurent Pinchartb0b29e12012-03-26 10:24:50 -03002305
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002306 preview_init_params(prev);
2307
Laurent Pinchart9b6390b2011-09-22 17:10:30 -03002308 return preview_init_entities(prev);
Laurent Pinchartde1135d2011-02-12 18:05:06 -03002309}
Laurent Pinchart39099d02011-09-22 16:59:26 -03002310
2311void omap3isp_preview_cleanup(struct isp_device *isp)
2312{
2313 struct isp_prev_device *prev = &isp->isp_prev;
2314
2315 v4l2_ctrl_handler_free(&prev->ctrls);
2316 omap3isp_video_cleanup(&prev->video_in);
2317 omap3isp_video_cleanup(&prev->video_out);
2318 media_entity_cleanup(&prev->subdev.entity);
2319}