2 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
4 * Benoit Parrot <bparrot@ti.com>
5 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include <linux/am437x-vpfe.h>
25 #include <linux/clk.h>
26 #include <linux/device.h>
28 #include <linux/i2c.h>
29 #include <linux/videodev2.h>
31 #include <media/v4l2-dev.h>
32 #include <media/v4l2-device.h>
33 #include <media/v4l2-ioctl.h>
34 #include <media/videobuf2-dma-contig.h>
36 #include "am437x-vpfe_regs.h"
39 VPFE_PINPOL_POSITIVE = 0,
43 enum vpfe_hw_if_type {
50 /* YCbCr - 8 bit with external sync */
52 /* YCbCr - 16 bit with external sync */
56 /* interface description */
57 struct vpfe_hw_if_param {
58 enum vpfe_hw_if_type if_type;
59 enum vpfe_pin_pol hdpol;
60 enum vpfe_pin_pol vdpol;
61 unsigned int bus_width;
64 #define VPFE_MAX_SUBDEV 1
65 #define VPFE_MAX_INPUTS 1
67 struct vpfe_pixel_format {
68 struct v4l2_fmtdesc fmtdesc;
73 struct vpfe_std_info {
76 /* current frame format */
85 struct vpfe_subdev_info {
86 /* Sub device group id */
88 /* inputs available at the sub device */
89 struct v4l2_input inputs[VPFE_MAX_INPUTS];
90 /* Sub dev routing information for each input */
91 struct vpfe_route *routes;
92 /* check if sub dev supports routing */
94 /* ccdc bus/interface configuration */
95 struct vpfe_hw_if_param vpfe_param;
96 struct v4l2_subdev *sd;
100 /* information about each subdev */
101 struct vpfe_subdev_info sub_devs[VPFE_MAX_SUBDEV];
102 /* Flat array, arranged in groups */
103 struct v4l2_async_subdev *asd[VPFE_MAX_SUBDEV];
106 struct vpfe_cap_buffer {
107 struct vb2_buffer vb;
108 struct list_head list;
113 CCDC_PIXFMT_YCBCR_16BIT,
114 CCDC_PIXFMT_YCBCR_8BIT,
118 CCDC_FRMFMT_PROGRESSIVE = 0,
119 CCDC_FRMFMT_INTERLACED,
122 /* PIXEL ORDER IN MEMORY from LSB to MSB */
123 /* only applicable for 8-bit input mode */
125 CCDC_PIXORDER_YCBYCR,
126 CCDC_PIXORDER_CBYCRY,
130 CCDC_BUFTYPE_FLD_INTERLEAVED,
131 CCDC_BUFTYPE_FLD_SEPARATED
135 /* returns the highest bit used for the gamma */
136 static inline u8 ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width)
141 /* returns the highest bit used for this data size */
142 static inline u8 ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz)
144 return sz == VPFE_CCDC_DATA_8BITS ? 7 : 15 - sz;
147 /* Structure for CCDC configuration parameters for raw capture mode */
148 struct ccdc_params_raw {
150 enum ccdc_pixfmt pix_fmt;
151 /* progressive or interlaced frame */
152 enum ccdc_frmfmt frm_fmt;
153 struct v4l2_rect win;
154 /* Current Format Bytes Per Pixels */
155 unsigned int bytesperpixel;
156 /* Current Format Bytes per Lines
157 * (Aligned to 32 bytes) used for HORZ_INFO
159 unsigned int bytesperline;
160 /* field id polarity */
161 enum vpfe_pin_pol fid_pol;
162 /* vertical sync polarity */
163 enum vpfe_pin_pol vd_pol;
164 /* horizontal sync polarity */
165 enum vpfe_pin_pol hd_pol;
166 /* interleaved or separated fields */
167 enum ccdc_buftype buf_type;
169 * enable to store the image in inverse
170 * order in memory(bottom to top)
172 unsigned char image_invert_enable;
173 /* configurable parameters */
174 struct vpfe_ccdc_config_params_raw config_params;
177 struct ccdc_params_ycbcr {
179 enum ccdc_pixfmt pix_fmt;
180 /* progressive or interlaced frame */
181 enum ccdc_frmfmt frm_fmt;
182 struct v4l2_rect win;
183 /* Current Format Bytes Per Pixels */
184 unsigned int bytesperpixel;
185 /* Current Format Bytes per Lines
186 * (Aligned to 32 bytes) used for HORZ_INFO
188 unsigned int bytesperline;
189 /* field id polarity */
190 enum vpfe_pin_pol fid_pol;
191 /* vertical sync polarity */
192 enum vpfe_pin_pol vd_pol;
193 /* horizontal sync polarity */
194 enum vpfe_pin_pol hd_pol;
195 /* enable BT.656 embedded sync mode */
197 /* cb:y:cr:y or y:cb:y:cr in memory */
198 enum ccdc_pixorder pix_order;
199 /* interleaved or separated fields */
200 enum ccdc_buftype buf_type;
204 * CCDC operational configuration
207 /* CCDC interface type */
208 enum vpfe_hw_if_type if_type;
209 /* Raw Bayer configuration */
210 struct ccdc_params_raw bayer;
211 /* YCbCr configuration */
212 struct ccdc_params_ycbcr ycbcr;
213 /* ccdc base address */
214 void __iomem *base_addr;
218 struct ccdc_config ccdc_cfg;
219 u32 ccdc_ctx[VPFE_REG_END / sizeof(u32)];
223 /* V4l2 specific parameters */
224 /* Identifies video device for this channel */
225 struct video_device video_dev;
227 struct v4l2_subdev **sd;
229 struct vpfe_config *cfg;
231 struct v4l2_device v4l2_dev;
234 /* subdevice async Notifier */
235 struct v4l2_async_notifier notifier;
236 /* Indicates id of the field which is being displayed */
239 /* current interface type */
240 struct vpfe_hw_if_param vpfe_if_params;
241 /* ptr to currently selected sub device */
242 struct vpfe_subdev_info *current_subdev;
243 /* current input at the sub device */
245 /* Keeps track of the information about the standard */
246 struct vpfe_std_info std_info;
247 /* std index into std table */
249 /* IRQs used when CCDC output to SDRAM */
251 /* Pointer pointing to current v4l2_buffer */
252 struct vpfe_cap_buffer *cur_frm;
253 /* Pointer pointing to next v4l2_buffer */
254 struct vpfe_cap_buffer *next_frm;
255 /* Used to store pixel format */
256 struct v4l2_format fmt;
257 /* Used to store current bytes per pixel based on current format */
260 * used when IMP is chained to store the crop window which
261 * is different from the image window
263 struct v4l2_rect crop;
264 /* Buffer queue used in video-buf */
265 struct vb2_queue buffer_queue;
266 /* Allocator-specific contexts for each plane */
267 struct vb2_alloc_ctx *alloc_ctx;
268 /* Queue of filled frames */
269 struct list_head dma_queue;
270 /* IRQ lock for DMA queue */
271 spinlock_t dma_queue_lock;
272 /* lock used to access this structure */
275 * offset where second field starts from the starting of the
276 * buffer for field separated YCbCr formats
279 struct vpfe_ccdc ccdc;
282 #endif /* AM437X_VPFE_H */