1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
5 * Benoit Parrot <bparrot@ti.com>
6 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
12 #include <linux/am437x-vpfe.h>
13 #include <linux/clk.h>
14 #include <linux/completion.h>
15 #include <linux/device.h>
17 #include <linux/i2c.h>
18 #include <linux/videodev2.h>
20 #include <media/v4l2-dev.h>
21 #include <media/v4l2-device.h>
22 #include <media/v4l2-ioctl.h>
23 #include <media/videobuf2-v4l2.h>
24 #include <media/videobuf2-dma-contig.h>
26 #include "am437x-vpfe_regs.h"
29 VPFE_PINPOL_POSITIVE
= 0,
33 enum vpfe_hw_if_type
{
40 /* YCbCr - 8 bit with external sync */
42 /* YCbCr - 16 bit with external sync */
46 /* interface description */
47 struct vpfe_hw_if_param
{
48 enum vpfe_hw_if_type if_type
;
49 enum vpfe_pin_pol hdpol
;
50 enum vpfe_pin_pol vdpol
;
51 unsigned int bus_width
;
54 #define VPFE_MAX_SUBDEV 1
55 #define VPFE_MAX_INPUTS 1
57 struct vpfe_std_info
{
60 /* current frame format */
69 struct vpfe_subdev_info
{
70 /* Sub device group id */
72 /* inputs available at the sub device */
73 struct v4l2_input inputs
[VPFE_MAX_INPUTS
];
74 /* Sub dev routing information for each input */
75 struct vpfe_route
*routes
;
76 /* check if sub dev supports routing */
78 /* ccdc bus/interface configuration */
79 struct vpfe_hw_if_param vpfe_param
;
80 struct v4l2_subdev
*sd
;
84 /* information about each subdev */
85 struct vpfe_subdev_info sub_devs
[VPFE_MAX_SUBDEV
];
86 /* Flat array, arranged in groups */
87 struct v4l2_async_subdev
*asd
[VPFE_MAX_SUBDEV
];
90 struct vpfe_cap_buffer
{
91 struct vb2_v4l2_buffer vb
;
92 struct list_head list
;
97 CCDC_PIXFMT_YCBCR_16BIT
,
98 CCDC_PIXFMT_YCBCR_8BIT
,
102 CCDC_FRMFMT_PROGRESSIVE
= 0,
103 CCDC_FRMFMT_INTERLACED
,
106 /* PIXEL ORDER IN MEMORY from LSB to MSB */
107 /* only applicable for 8-bit input mode */
109 CCDC_PIXORDER_YCBYCR
,
110 CCDC_PIXORDER_CBYCRY
,
114 CCDC_BUFTYPE_FLD_INTERLEAVED
,
115 CCDC_BUFTYPE_FLD_SEPARATED
119 /* returns the highest bit used for the gamma */
120 static inline u8
ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width
)
125 /* returns the highest bit used for this data size */
126 static inline u8
ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz
)
128 return sz
== VPFE_CCDC_DATA_8BITS
? 7 : 15 - sz
;
131 /* Structure for CCDC configuration parameters for raw capture mode */
132 struct ccdc_params_raw
{
134 enum ccdc_pixfmt pix_fmt
;
135 /* progressive or interlaced frame */
136 enum ccdc_frmfmt frm_fmt
;
137 struct v4l2_rect win
;
138 /* Current Format Bytes Per Pixels */
139 unsigned int bytesperpixel
;
140 /* Current Format Bytes per Lines
141 * (Aligned to 32 bytes) used for HORZ_INFO
143 unsigned int bytesperline
;
144 /* field id polarity */
145 enum vpfe_pin_pol fid_pol
;
146 /* vertical sync polarity */
147 enum vpfe_pin_pol vd_pol
;
148 /* horizontal sync polarity */
149 enum vpfe_pin_pol hd_pol
;
150 /* interleaved or separated fields */
151 enum ccdc_buftype buf_type
;
153 * enable to store the image in inverse
154 * order in memory(bottom to top)
156 unsigned char image_invert_enable
;
157 /* configurable parameters */
158 struct vpfe_ccdc_config_params_raw config_params
;
161 struct ccdc_params_ycbcr
{
163 enum ccdc_pixfmt pix_fmt
;
164 /* progressive or interlaced frame */
165 enum ccdc_frmfmt frm_fmt
;
166 struct v4l2_rect win
;
167 /* Current Format Bytes Per Pixels */
168 unsigned int bytesperpixel
;
169 /* Current Format Bytes per Lines
170 * (Aligned to 32 bytes) used for HORZ_INFO
172 unsigned int bytesperline
;
173 /* field id polarity */
174 enum vpfe_pin_pol fid_pol
;
175 /* vertical sync polarity */
176 enum vpfe_pin_pol vd_pol
;
177 /* horizontal sync polarity */
178 enum vpfe_pin_pol hd_pol
;
179 /* enable BT.656 embedded sync mode */
181 /* cb:y:cr:y or y:cb:y:cr in memory */
182 enum ccdc_pixorder pix_order
;
183 /* interleaved or separated fields */
184 enum ccdc_buftype buf_type
;
188 * CCDC operational configuration
191 /* CCDC interface type */
192 enum vpfe_hw_if_type if_type
;
193 /* Raw Bayer configuration */
194 struct ccdc_params_raw bayer
;
195 /* YCbCr configuration */
196 struct ccdc_params_ycbcr ycbcr
;
197 /* ccdc base address */
198 void __iomem
*base_addr
;
202 struct ccdc_config ccdc_cfg
;
203 u32 ccdc_ctx
[VPFE_REG_END
/ sizeof(u32
)];
207 * struct vpfe_fmt - VPFE media bus format information
208 * fourcc: V4L2 pixel format code
209 * code: V4L2 media bus format code
210 * bitsperpixel: Bits per pixel over the bus
219 * When formats[] is modified make sure to adjust this value also.
220 * Expect compile time warnings if VPFE_NUM_FORMATS is smaller then
221 * the number of elements in formats[].
223 #define VPFE_NUM_FORMATS 10
226 /* V4l2 specific parameters */
227 /* Identifies video device for this channel */
228 struct video_device video_dev
;
230 struct v4l2_subdev
**sd
;
232 struct vpfe_config
*cfg
;
234 struct v4l2_device v4l2_dev
;
237 /* subdevice async Notifier */
238 struct v4l2_async_notifier notifier
;
239 /* Indicates id of the field which is being displayed */
242 /* current interface type */
243 struct vpfe_hw_if_param vpfe_if_params
;
244 /* ptr to currently selected sub device */
245 struct vpfe_subdev_info
*current_subdev
;
246 /* current input at the sub device */
248 /* Keeps track of the information about the standard */
249 struct vpfe_std_info std_info
;
250 /* std index into std table */
252 /* IRQs used when CCDC output to SDRAM */
254 /* Pointer pointing to current v4l2_buffer */
255 struct vpfe_cap_buffer
*cur_frm
;
256 /* Pointer pointing to next v4l2_buffer */
257 struct vpfe_cap_buffer
*next_frm
;
258 /* Used to store pixel format */
259 struct v4l2_format fmt
;
260 /* Used to keep a reference to the current vpfe_fmt */
261 struct vpfe_fmt
*current_vpfe_fmt
;
262 struct vpfe_fmt
*active_fmt
[VPFE_NUM_FORMATS
];
263 unsigned int num_active_fmt
;
266 * used when IMP is chained to store the crop window which
267 * is different from the image window
269 struct v4l2_rect crop
;
270 /* Buffer queue used in video-buf */
271 struct vb2_queue buffer_queue
;
272 /* Queue of filled frames */
273 struct list_head dma_queue
;
274 /* IRQ lock for DMA queue */
275 spinlock_t dma_queue_lock
;
276 /* lock used to access this structure */
279 * offset where second field starts from the starting of the
280 * buffer for field separated YCbCr formats
283 struct vpfe_ccdc ccdc
;
285 struct completion capture_stop
;
288 #endif /* AM437X_VPFE_H */