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-v4l2.h>
35 #include <media/videobuf2-dma-contig.h>
37 #include "am437x-vpfe_regs.h"
40 VPFE_PINPOL_POSITIVE = 0,
44 enum vpfe_hw_if_type {
51 /* YCbCr - 8 bit with external sync */
53 /* YCbCr - 16 bit with external sync */
57 /* interface description */
58 struct vpfe_hw_if_param {
59 enum vpfe_hw_if_type if_type;
60 enum vpfe_pin_pol hdpol;
61 enum vpfe_pin_pol vdpol;
62 unsigned int bus_width;
65 #define VPFE_MAX_SUBDEV 1
66 #define VPFE_MAX_INPUTS 1
68 struct vpfe_std_info {
71 /* current frame format */
80 struct vpfe_subdev_info {
81 /* Sub device group id */
83 /* inputs available at the sub device */
84 struct v4l2_input inputs[VPFE_MAX_INPUTS];
85 /* Sub dev routing information for each input */
86 struct vpfe_route *routes;
87 /* check if sub dev supports routing */
89 /* ccdc bus/interface configuration */
90 struct vpfe_hw_if_param vpfe_param;
91 struct v4l2_subdev *sd;
95 /* information about each subdev */
96 struct vpfe_subdev_info sub_devs[VPFE_MAX_SUBDEV];
97 /* Flat array, arranged in groups */
98 struct v4l2_async_subdev *asd[VPFE_MAX_SUBDEV];
101 struct vpfe_cap_buffer {
102 struct vb2_v4l2_buffer vb;
103 struct list_head list;
108 CCDC_PIXFMT_YCBCR_16BIT,
109 CCDC_PIXFMT_YCBCR_8BIT,
113 CCDC_FRMFMT_PROGRESSIVE = 0,
114 CCDC_FRMFMT_INTERLACED,
117 /* PIXEL ORDER IN MEMORY from LSB to MSB */
118 /* only applicable for 8-bit input mode */
120 CCDC_PIXORDER_YCBYCR,
121 CCDC_PIXORDER_CBYCRY,
125 CCDC_BUFTYPE_FLD_INTERLEAVED,
126 CCDC_BUFTYPE_FLD_SEPARATED
130 /* returns the highest bit used for the gamma */
131 static inline u8 ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width)
136 /* returns the highest bit used for this data size */
137 static inline u8 ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz)
139 return sz == VPFE_CCDC_DATA_8BITS ? 7 : 15 - sz;
142 /* Structure for CCDC configuration parameters for raw capture mode */
143 struct ccdc_params_raw {
145 enum ccdc_pixfmt pix_fmt;
146 /* progressive or interlaced frame */
147 enum ccdc_frmfmt frm_fmt;
148 struct v4l2_rect win;
149 /* Current Format Bytes Per Pixels */
150 unsigned int bytesperpixel;
151 /* Current Format Bytes per Lines
152 * (Aligned to 32 bytes) used for HORZ_INFO
154 unsigned int bytesperline;
155 /* field id polarity */
156 enum vpfe_pin_pol fid_pol;
157 /* vertical sync polarity */
158 enum vpfe_pin_pol vd_pol;
159 /* horizontal sync polarity */
160 enum vpfe_pin_pol hd_pol;
161 /* interleaved or separated fields */
162 enum ccdc_buftype buf_type;
164 * enable to store the image in inverse
165 * order in memory(bottom to top)
167 unsigned char image_invert_enable;
168 /* configurable parameters */
169 struct vpfe_ccdc_config_params_raw config_params;
172 struct ccdc_params_ycbcr {
174 enum ccdc_pixfmt pix_fmt;
175 /* progressive or interlaced frame */
176 enum ccdc_frmfmt frm_fmt;
177 struct v4l2_rect win;
178 /* Current Format Bytes Per Pixels */
179 unsigned int bytesperpixel;
180 /* Current Format Bytes per Lines
181 * (Aligned to 32 bytes) used for HORZ_INFO
183 unsigned int bytesperline;
184 /* field id polarity */
185 enum vpfe_pin_pol fid_pol;
186 /* vertical sync polarity */
187 enum vpfe_pin_pol vd_pol;
188 /* horizontal sync polarity */
189 enum vpfe_pin_pol hd_pol;
190 /* enable BT.656 embedded sync mode */
192 /* cb:y:cr:y or y:cb:y:cr in memory */
193 enum ccdc_pixorder pix_order;
194 /* interleaved or separated fields */
195 enum ccdc_buftype buf_type;
199 * CCDC operational configuration
202 /* CCDC interface type */
203 enum vpfe_hw_if_type if_type;
204 /* Raw Bayer configuration */
205 struct ccdc_params_raw bayer;
206 /* YCbCr configuration */
207 struct ccdc_params_ycbcr ycbcr;
208 /* ccdc base address */
209 void __iomem *base_addr;
213 struct ccdc_config ccdc_cfg;
214 u32 ccdc_ctx[VPFE_REG_END / sizeof(u32)];
218 /* V4l2 specific parameters */
219 /* Identifies video device for this channel */
220 struct video_device video_dev;
222 struct v4l2_subdev **sd;
224 struct vpfe_config *cfg;
226 struct v4l2_device v4l2_dev;
229 /* subdevice async Notifier */
230 struct v4l2_async_notifier notifier;
231 /* Indicates id of the field which is being displayed */
234 /* current interface type */
235 struct vpfe_hw_if_param vpfe_if_params;
236 /* ptr to currently selected sub device */
237 struct vpfe_subdev_info *current_subdev;
238 /* current input at the sub device */
240 /* Keeps track of the information about the standard */
241 struct vpfe_std_info std_info;
242 /* std index into std table */
244 /* IRQs used when CCDC output to SDRAM */
246 /* Pointer pointing to current v4l2_buffer */
247 struct vpfe_cap_buffer *cur_frm;
248 /* Pointer pointing to next v4l2_buffer */
249 struct vpfe_cap_buffer *next_frm;
250 /* Used to store pixel format */
251 struct v4l2_format fmt;
252 /* Used to store current bytes per pixel based on current format */
255 * used when IMP is chained to store the crop window which
256 * is different from the image window
258 struct v4l2_rect crop;
259 /* Buffer queue used in video-buf */
260 struct vb2_queue buffer_queue;
261 /* Queue of filled frames */
262 struct list_head dma_queue;
263 /* IRQ lock for DMA queue */
264 spinlock_t dma_queue_lock;
265 /* lock used to access this structure */
268 * offset where second field starts from the starting of the
269 * buffer for field separated YCbCr formats
272 struct vpfe_ccdc ccdc;
275 #endif /* AM437X_VPFE_H */