ima: fix bug in argument order
[sfrench/cifs-2.6.git] / drivers / media / video / omap3isp / ispccdc.h
1 /*
2  * ispccdc.h
3  *
4  * TI OMAP3 ISP - CCDC module
5  *
6  * Copyright (C) 2009-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 #ifndef OMAP3_ISP_CCDC_H
28 #define OMAP3_ISP_CCDC_H
29
30 #include <linux/omap3isp.h>
31 #include <linux/workqueue.h>
32
33 #include "ispvideo.h"
34
35 enum ccdc_input_entity {
36         CCDC_INPUT_NONE,
37         CCDC_INPUT_PARALLEL,
38         CCDC_INPUT_CSI2A,
39         CCDC_INPUT_CCP2B,
40         CCDC_INPUT_CSI2C
41 };
42
43 #define CCDC_OUTPUT_MEMORY      (1 << 0)
44 #define CCDC_OUTPUT_PREVIEW     (1 << 1)
45 #define CCDC_OUTPUT_RESIZER     (1 << 2)
46
47 #define OMAP3ISP_CCDC_NEVENTS   16
48
49 /*
50  * struct ispccdc_syncif - Structure for Sync Interface between sensor and CCDC
51  * @ccdc_mastermode: Master mode. 1 - Master, 0 - Slave.
52  * @fldstat: Field state. 0 - Odd Field, 1 - Even Field.
53  * @datsz: Data size.
54  * @fldmode: 0 - Progressive, 1 - Interlaced.
55  * @datapol: 0 - Positive, 1 - Negative.
56  * @fldpol: 0 - Positive, 1 - Negative.
57  * @hdpol: 0 - Positive, 1 - Negative.
58  * @vdpol: 0 - Positive, 1 - Negative.
59  * @fldout: 0 - Input, 1 - Output.
60  * @hs_width: Width of the Horizontal Sync pulse, used for HS/VS Output.
61  * @vs_width: Width of the Vertical Sync pulse, used for HS/VS Output.
62  * @ppln: Number of pixels per line, used for HS/VS Output.
63  * @hlprf: Number of half lines per frame, used for HS/VS Output.
64  * @bt_r656_en: 1 - Enable ITU-R BT656 mode, 0 - Sync mode.
65  */
66 struct ispccdc_syncif {
67         u8 ccdc_mastermode;
68         u8 fldstat;
69         u8 datsz;
70         u8 fldmode;
71         u8 datapol;
72         u8 fldpol;
73         u8 hdpol;
74         u8 vdpol;
75         u8 fldout;
76         u8 hs_width;
77         u8 vs_width;
78         u8 ppln;
79         u8 hlprf;
80         u8 bt_r656_en;
81 };
82
83 enum ispccdc_lsc_state {
84         LSC_STATE_STOPPED = 0,
85         LSC_STATE_STOPPING = 1,
86         LSC_STATE_RUNNING = 2,
87         LSC_STATE_RECONFIG = 3,
88 };
89
90 struct ispccdc_lsc_config_req {
91         struct list_head list;
92         struct omap3isp_ccdc_lsc_config config;
93         unsigned char enable;
94         u32 table;
95         struct iovm_struct *iovm;
96 };
97
98 /*
99  * ispccdc_lsc - CCDC LSC parameters
100  * @update_config: Set when user changes config
101  * @request_enable: Whether LSC is requested to be enabled
102  * @config: LSC config set by user
103  * @update_table: Set when user provides a new LSC table to table_new
104  * @table_new: LSC table set by user, ISP address
105  * @table_inuse: LSC table currently in use, ISP address
106  */
107 struct ispccdc_lsc {
108         enum ispccdc_lsc_state state;
109         struct work_struct table_work;
110
111         /* LSC queue of configurations */
112         spinlock_t req_lock;
113         struct ispccdc_lsc_config_req *request; /* requested configuration */
114         struct ispccdc_lsc_config_req *active;  /* active configuration */
115         struct list_head free_queue;    /* configurations for freeing */
116 };
117
118 #define CCDC_STOP_NOT_REQUESTED         0x00
119 #define CCDC_STOP_REQUEST               0x01
120 #define CCDC_STOP_EXECUTED              (0x02 | CCDC_STOP_REQUEST)
121 #define CCDC_STOP_CCDC_FINISHED         0x04
122 #define CCDC_STOP_LSC_FINISHED          0x08
123 #define CCDC_STOP_FINISHED              \
124         (CCDC_STOP_EXECUTED | CCDC_STOP_CCDC_FINISHED | CCDC_STOP_LSC_FINISHED)
125
126 #define CCDC_EVENT_VD1                  0x10
127 #define CCDC_EVENT_VD0                  0x20
128 #define CCDC_EVENT_LSC_DONE             0x40
129
130 /* Sink and source CCDC pads */
131 #define CCDC_PAD_SINK                   0
132 #define CCDC_PAD_SOURCE_OF              1
133 #define CCDC_PAD_SOURCE_VP              2
134 #define CCDC_PADS_NUM                   3
135
136 /*
137  * struct isp_ccdc_device - Structure for the CCDC module to store its own
138  *                          information
139  * @subdev: V4L2 subdevice
140  * @pads: Sink and source media entity pads
141  * @formats: Active video formats
142  * @crop: Active crop rectangle on the OF source pad
143  * @input: Active input
144  * @output: Active outputs
145  * @video_out: Output video node
146  * @alaw: A-law compression enabled (1) or disabled (0)
147  * @lpf: Low pass filter enabled (1) or disabled (0)
148  * @obclamp: Optical-black clamp enabled (1) or disabled (0)
149  * @fpc_en: Faulty pixels correction enabled (1) or disabled (0)
150  * @blcomp: Black level compensation configuration
151  * @clamp: Optical-black or digital clamp configuration
152  * @fpc: Faulty pixels correction configuration
153  * @lsc: Lens shading compensation configuration
154  * @update: Bitmask of controls to update during the next interrupt
155  * @shadow_update: Controls update in progress by userspace
156  * @syncif: Interface synchronization configuration
157  * @underrun: A buffer underrun occurred and a new buffer has been queued
158  * @state: Streaming state
159  * @lock: Serializes shadow_update with interrupt handler
160  * @wait: Wait queue used to stop the module
161  * @stopping: Stopping state
162  * @ioctl_lock: Serializes ioctl calls and LSC requests freeing
163  */
164 struct isp_ccdc_device {
165         struct v4l2_subdev subdev;
166         struct media_pad pads[CCDC_PADS_NUM];
167         struct v4l2_mbus_framefmt formats[CCDC_PADS_NUM];
168         struct v4l2_rect crop;
169
170         enum ccdc_input_entity input;
171         unsigned int output;
172         struct isp_video video_out;
173
174         unsigned int alaw:1,
175                      lpf:1,
176                      obclamp:1,
177                      fpc_en:1;
178         struct omap3isp_ccdc_blcomp blcomp;
179         struct omap3isp_ccdc_bclamp clamp;
180         struct omap3isp_ccdc_fpc fpc;
181         struct ispccdc_lsc lsc;
182         unsigned int update;
183         unsigned int shadow_update;
184
185         struct ispccdc_syncif syncif;
186
187         unsigned int underrun:1;
188         enum isp_pipeline_stream_state state;
189         spinlock_t lock;
190         wait_queue_head_t wait;
191         unsigned int stopping;
192         struct mutex ioctl_lock;
193 };
194
195 struct isp_device;
196
197 int omap3isp_ccdc_init(struct isp_device *isp);
198 void omap3isp_ccdc_cleanup(struct isp_device *isp);
199 int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
200         struct v4l2_device *vdev);
201 void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc);
202
203 int omap3isp_ccdc_busy(struct isp_ccdc_device *isp_ccdc);
204 int omap3isp_ccdc_isr(struct isp_ccdc_device *isp_ccdc, u32 events);
205 void omap3isp_ccdc_restore_context(struct isp_device *isp);
206 void omap3isp_ccdc_max_rate(struct isp_ccdc_device *ccdc,
207         unsigned int *max_rate);
208
209 #endif  /* OMAP3_ISP_CCDC_H */