aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/am437x/am437x-vpfe.h
diff options
context:
space:
mode:
authorBenoit Parrot <bparrot@ti.com>2014-12-09 14:43:44 -0500
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2014-12-23 09:09:58 -0500
commit417d2e507edcb5cf15eb344f86bd3dd28737f24e (patch)
treec4f5d7079f63144c28aa5ceb6d7a94d7c62ae8cc /drivers/media/platform/am437x/am437x-vpfe.h
parent3b1635e02e524e2cc7bded4b998d35074b68065e (diff)
[media] media: platform: add VPFE capture driver support for AM437X
This patch adds Video Processing Front End (VPFE) driver for AM437X family of devices Driver supports the following: - V4L2 API using MMAP buffer access based on videobuf2 api - Asynchronous sensor/decoder sub device registration - DT support Signed-off-by: Benoit Parrot <bparrot@ti.com> Signed-off-by: Darren Etheridge <detheridge@ti.com> Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> [hans.verkuil@cisco.com: swapped two lines to fix vpfe_release() & add pinctrl include] Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/platform/am437x/am437x-vpfe.h')
-rw-r--r--drivers/media/platform/am437x/am437x-vpfe.h283
1 files changed, 283 insertions, 0 deletions
diff --git a/drivers/media/platform/am437x/am437x-vpfe.h b/drivers/media/platform/am437x/am437x-vpfe.h
new file mode 100644
index 000000000000..0f557352313d
--- /dev/null
+++ b/drivers/media/platform/am437x/am437x-vpfe.h
@@ -0,0 +1,283 @@
1/*
2 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
3 *
4 * Benoit Parrot <bparrot@ti.com>
5 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
6 *
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.
10 *
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
18 * SOFTWARE.
19 */
20
21#ifndef AM437X_VPFE_H
22#define AM437X_VPFE_H
23
24#include <linux/am437x-vpfe.h>
25#include <linux/clk.h>
26#include <linux/device.h>
27#include <linux/io.h>
28#include <linux/i2c.h>
29#include <linux/videodev2.h>
30
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>
35
36#include "am437x-vpfe_regs.h"
37
38enum vpfe_pin_pol {
39 VPFE_PINPOL_POSITIVE = 0,
40 VPFE_PINPOL_NEGATIVE,
41};
42
43enum vpfe_hw_if_type {
44 /* Raw Bayer */
45 VPFE_RAW_BAYER = 0,
46 /* BT656 - 8 bit */
47 VPFE_BT656,
48 /* BT656 - 10 bit */
49 VPFE_BT656_10BIT,
50 /* YCbCr - 8 bit with external sync */
51 VPFE_YCBCR_SYNC_8,
52 /* YCbCr - 16 bit with external sync */
53 VPFE_YCBCR_SYNC_16,
54};
55
56/* interface description */
57struct 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;
62};
63
64#define VPFE_MAX_SUBDEV 1
65#define VPFE_MAX_INPUTS 1
66
67struct vpfe_pixel_format {
68 struct v4l2_fmtdesc fmtdesc;
69 /* bytes per pixel */
70 int bpp;
71};
72
73struct vpfe_std_info {
74 int active_pixels;
75 int active_lines;
76 /* current frame format */
77 int frame_format;
78};
79
80struct vpfe_route {
81 u32 input;
82 u32 output;
83};
84
85struct vpfe_subdev_info {
86 char name[32];
87 /* Sub device group id */
88 int grp_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 */
94 int can_route;
95 /* ccdc bus/interface configuration */
96 struct vpfe_hw_if_param vpfe_param;
97 struct v4l2_subdev *sd;
98};
99
100struct vpfe_config {
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];
105};
106
107struct vpfe_cap_buffer {
108 struct vb2_buffer vb;
109 struct list_head list;
110};
111
112enum ccdc_pixfmt {
113 CCDC_PIXFMT_RAW = 0,
114 CCDC_PIXFMT_YCBCR_16BIT,
115 CCDC_PIXFMT_YCBCR_8BIT,
116};
117
118enum ccdc_frmfmt {
119 CCDC_FRMFMT_PROGRESSIVE = 0,
120 CCDC_FRMFMT_INTERLACED,
121};
122
123/* PIXEL ORDER IN MEMORY from LSB to MSB */
124/* only applicable for 8-bit input mode */
125enum ccdc_pixorder {
126 CCDC_PIXORDER_YCBYCR,
127 CCDC_PIXORDER_CBYCRY,
128};
129
130enum ccdc_buftype {
131 CCDC_BUFTYPE_FLD_INTERLEAVED,
132 CCDC_BUFTYPE_FLD_SEPARATED
133};
134
135
136/* returns the highest bit used for the gamma */
137static inline u8 ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width)
138{
139 return 15 - width;
140}
141
142/* returns the highest bit used for this data size */
143static inline u8 ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz)
144{
145 return sz == VPFE_CCDC_DATA_8BITS ? 7 : 15 - sz;
146}
147
148/* Structure for CCDC configuration parameters for raw capture mode */
149struct ccdc_params_raw {
150 /* pixel format */
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
159 */
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;
169 /*
170 * enable to store the image in inverse
171 * order in memory(bottom to top)
172 */
173 unsigned char image_invert_enable;
174 /* configurable parameters */
175 struct vpfe_ccdc_config_params_raw config_params;
176};
177
178struct ccdc_params_ycbcr {
179 /* pixel format */
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
188 */
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 */
197 int bt656_enable;
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;
202};
203
204/*
205 * CCDC operational configuration
206 */
207struct ccdc_config {
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;
216};
217
218struct vpfe_ccdc {
219 struct ccdc_config ccdc_cfg;
220 u32 ccdc_ctx[VPFE_REG_END / sizeof(u32)];
221};
222
223struct vpfe_device {
224 /* V4l2 specific parameters */
225 /* Identifies video device for this channel */
226 struct video_device *video_dev;
227 /* sub devices */
228 struct v4l2_subdev **sd;
229 /* vpfe cfg */
230 struct vpfe_config *cfg;
231 /* V4l2 device */
232 struct v4l2_device v4l2_dev;
233 /* parent device */
234 struct device *pdev;
235 /* subdevice async Notifier */
236 struct v4l2_async_notifier notifier;
237 /* Indicates id of the field which is being displayed */
238 unsigned field;
239 unsigned sequence;
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 */
245 int current_input;
246 /* Keeps track of the information about the standard */
247 struct vpfe_std_info std_info;
248 /* std index into std table */
249 int std_index;
250 /* IRQs used when CCDC output to SDRAM */
251 unsigned int irq;
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 */
259 unsigned int bpp;
260 /*
261 * used when IMP is chained to store the crop window which
262 * is different from the image window
263 */
264 struct v4l2_rect crop;
265 /* Buffer queue used in video-buf */
266 struct vb2_queue buffer_queue;
267 /* Allocator-specific contexts for each plane */
268 struct vb2_alloc_ctx *alloc_ctx;
269 /* Queue of filled frames */
270 struct list_head dma_queue;
271 /* IRQ lock for DMA queue */
272 spinlock_t dma_queue_lock;
273 /* lock used to access this structure */
274 struct mutex lock;
275 /*
276 * offset where second field starts from the starting of the
277 * buffer for field separated YCbCr formats
278 */
279 u32 field_off;
280 struct vpfe_ccdc ccdc;
281};
282
283#endif /* AM437X_VPFE_H */