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_pixel_format
{
69 struct v4l2_fmtdesc fmtdesc
;
74 struct vpfe_std_info
{
77 /* current frame format */
86 struct vpfe_subdev_info
{
87 /* Sub device group id */
89 /* inputs available at the sub device */
90 struct v4l2_input inputs
[VPFE_MAX_INPUTS
];
91 /* Sub dev routing information for each input */
92 struct vpfe_route
*routes
;
93 /* check if sub dev supports routing */
95 /* ccdc bus/interface configuration */
96 struct vpfe_hw_if_param vpfe_param
;
97 struct v4l2_subdev
*sd
;
101 /* information about each subdev */
102 struct vpfe_subdev_info sub_devs
[VPFE_MAX_SUBDEV
];
103 /* Flat array, arranged in groups */
104 struct v4l2_async_subdev
*asd
[VPFE_MAX_SUBDEV
];
107 struct vpfe_cap_buffer
{
108 struct vb2_v4l2_buffer vb
;
109 struct list_head list
;
114 CCDC_PIXFMT_YCBCR_16BIT
,
115 CCDC_PIXFMT_YCBCR_8BIT
,
119 CCDC_FRMFMT_PROGRESSIVE
= 0,
120 CCDC_FRMFMT_INTERLACED
,
123 /* PIXEL ORDER IN MEMORY from LSB to MSB */
124 /* only applicable for 8-bit input mode */
126 CCDC_PIXORDER_YCBYCR
,
127 CCDC_PIXORDER_CBYCRY
,
131 CCDC_BUFTYPE_FLD_INTERLEAVED
,
132 CCDC_BUFTYPE_FLD_SEPARATED
136 /* returns the highest bit used for the gamma */
137 static inline u8
ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width
)
142 /* returns the highest bit used for this data size */
143 static inline u8
ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz
)
145 return sz
== VPFE_CCDC_DATA_8BITS
? 7 : 15 - sz
;
148 /* Structure for CCDC configuration parameters for raw capture mode */
149 struct ccdc_params_raw
{
151 enum ccdc_pixfmt pix_fmt
;
152 /* progressive or interlaced frame */
153 enum ccdc_frmfmt frm_fmt
;
154 struct v4l2_rect win
;
155 /* Current Format Bytes Per Pixels */
156 unsigned int bytesperpixel
;
157 /* Current Format Bytes per Lines
158 * (Aligned to 32 bytes) used for HORZ_INFO
160 unsigned int bytesperline
;
161 /* field id polarity */
162 enum vpfe_pin_pol fid_pol
;
163 /* vertical sync polarity */
164 enum vpfe_pin_pol vd_pol
;
165 /* horizontal sync polarity */
166 enum vpfe_pin_pol hd_pol
;
167 /* interleaved or separated fields */
168 enum ccdc_buftype buf_type
;
170 * enable to store the image in inverse
171 * order in memory(bottom to top)
173 unsigned char image_invert_enable
;
174 /* configurable parameters */
175 struct vpfe_ccdc_config_params_raw config_params
;
178 struct ccdc_params_ycbcr
{
180 enum ccdc_pixfmt pix_fmt
;
181 /* progressive or interlaced frame */
182 enum ccdc_frmfmt frm_fmt
;
183 struct v4l2_rect win
;
184 /* Current Format Bytes Per Pixels */
185 unsigned int bytesperpixel
;
186 /* Current Format Bytes per Lines
187 * (Aligned to 32 bytes) used for HORZ_INFO
189 unsigned int bytesperline
;
190 /* field id polarity */
191 enum vpfe_pin_pol fid_pol
;
192 /* vertical sync polarity */
193 enum vpfe_pin_pol vd_pol
;
194 /* horizontal sync polarity */
195 enum vpfe_pin_pol hd_pol
;
196 /* enable BT.656 embedded sync mode */
198 /* cb:y:cr:y or y:cb:y:cr in memory */
199 enum ccdc_pixorder pix_order
;
200 /* interleaved or separated fields */
201 enum ccdc_buftype buf_type
;
205 * CCDC operational configuration
208 /* CCDC interface type */
209 enum vpfe_hw_if_type if_type
;
210 /* Raw Bayer configuration */
211 struct ccdc_params_raw bayer
;
212 /* YCbCr configuration */
213 struct ccdc_params_ycbcr ycbcr
;
214 /* ccdc base address */
215 void __iomem
*base_addr
;
219 struct ccdc_config ccdc_cfg
;
220 u32 ccdc_ctx
[VPFE_REG_END
/ sizeof(u32
)];
224 /* V4l2 specific parameters */
225 /* Identifies video device for this channel */
226 struct video_device video_dev
;
228 struct v4l2_subdev
**sd
;
230 struct vpfe_config
*cfg
;
232 struct v4l2_device v4l2_dev
;
235 /* subdevice async Notifier */
236 struct v4l2_async_notifier notifier
;
237 /* Indicates id of the field which is being displayed */
240 /* current interface type */
241 struct vpfe_hw_if_param vpfe_if_params
;
242 /* ptr to currently selected sub device */
243 struct vpfe_subdev_info
*current_subdev
;
244 /* current input at the sub device */
246 /* Keeps track of the information about the standard */
247 struct vpfe_std_info std_info
;
248 /* std index into std table */
250 /* IRQs used when CCDC output to SDRAM */
252 /* Pointer pointing to current v4l2_buffer */
253 struct vpfe_cap_buffer
*cur_frm
;
254 /* Pointer pointing to next v4l2_buffer */
255 struct vpfe_cap_buffer
*next_frm
;
256 /* Used to store pixel format */
257 struct v4l2_format fmt
;
258 /* Used to store current bytes per pixel based on current format */
261 * used when IMP is chained to store the crop window which
262 * is different from the image window
264 struct v4l2_rect crop
;
265 /* Buffer queue used in video-buf */
266 struct vb2_queue buffer_queue
;
267 /* Queue of filled frames */
268 struct list_head dma_queue
;
269 /* IRQ lock for DMA queue */
270 spinlock_t dma_queue_lock
;
271 /* lock used to access this structure */
274 * offset where second field starts from the starting of the
275 * buffer for field separated YCbCr formats
278 struct vpfe_ccdc ccdc
;
281 #endif /* AM437X_VPFE_H */