1 /*
2  * Copyright (C) 2008-2009 Texas Instruments Inc
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 #ifndef _VPFE_CAPTURE_H
20 #define _VPFE_CAPTURE_H
21 
22 #ifdef __KERNEL__
23 
24 /* Header files */
25 #include <media/v4l2-dev.h>
26 #include <linux/videodev2.h>
27 #include <linux/clk.h>
28 #include <linux/i2c.h>
29 #include <media/v4l2-fh.h>
30 #include <media/v4l2-ioctl.h>
31 #include <media/v4l2-device.h>
32 #include <media/videobuf-dma-contig.h>
33 #include <media/davinci/vpfe_types.h>
34 
35 #define VPFE_CAPTURE_NUM_DECODERS        5
36 
37 /* Macros */
38 #define VPFE_MAJOR_RELEASE              0
39 #define VPFE_MINOR_RELEASE              0
40 #define VPFE_BUILD                      1
41 #define VPFE_CAPTURE_VERSION_CODE       ((VPFE_MAJOR_RELEASE << 16) | \
42 					(VPFE_MINOR_RELEASE << 8)  | \
43 					VPFE_BUILD)
44 
45 #define CAPTURE_DRV_NAME		"vpfe-capture"
46 
47 struct vpfe_pixel_format {
48 	struct v4l2_fmtdesc fmtdesc;
49 	/* bytes per pixel */
50 	int bpp;
51 };
52 
53 struct vpfe_std_info {
54 	int active_pixels;
55 	int active_lines;
56 	/* current frame format */
57 	int frame_format;
58 };
59 
60 struct vpfe_route {
61 	u32 input;
62 	u32 output;
63 };
64 
65 struct vpfe_subdev_info {
66 	/* Sub device name */
67 	char name[32];
68 	/* Sub device group id */
69 	int grp_id;
70 	/* Number of inputs supported */
71 	int num_inputs;
72 	/* inputs available at the sub device */
73 	struct v4l2_input *inputs;
74 	/* Sub dev routing information for each input */
75 	struct vpfe_route *routes;
76 	/* check if sub dev supports routing */
77 	int can_route;
78 	/* ccdc bus/interface configuration */
79 	struct vpfe_hw_if_param ccdc_if_params;
80 	/* i2c subdevice board info */
81 	struct i2c_board_info board_info;
82 };
83 
84 struct vpfe_config {
85 	/* Number of sub devices connected to vpfe */
86 	int num_subdevs;
87 	/* i2c bus adapter no */
88 	int i2c_adapter_id;
89 	/* information about each subdev */
90 	struct vpfe_subdev_info *sub_devs;
91 	/* evm card info */
92 	char *card_name;
93 	/* ccdc name */
94 	char *ccdc;
95 	/* vpfe clock */
96 	struct clk *vpssclk;
97 	struct clk *slaveclk;
98 	/* Function for Clearing the interrupt */
99 	void (*clr_intr)(int vdint);
100 };
101 
102 struct vpfe_device {
103 	/* V4l2 specific parameters */
104 	/* Identifies video device for this channel */
105 	struct video_device video_dev;
106 	/* sub devices */
107 	struct v4l2_subdev **sd;
108 	/* vpfe cfg */
109 	struct vpfe_config *cfg;
110 	/* V4l2 device */
111 	struct v4l2_device v4l2_dev;
112 	/* parent device */
113 	struct device *pdev;
114 	/* number of open instances of the channel */
115 	u32 usrs;
116 	/* Indicates id of the field which is being displayed */
117 	u32 field_id;
118 	/* flag to indicate whether decoder is initialized */
119 	u8 initialized;
120 	/* current interface type */
121 	struct vpfe_hw_if_param vpfe_if_params;
122 	/* ptr to currently selected sub device */
123 	struct vpfe_subdev_info *current_subdev;
124 	/* current input at the sub device */
125 	int current_input;
126 	/* Keeps track of the information about the standard */
127 	struct vpfe_std_info std_info;
128 	/* std index into std table */
129 	int std_index;
130 	/* CCDC IRQs used when CCDC/ISIF output to SDRAM */
131 	unsigned int ccdc_irq0;
132 	unsigned int ccdc_irq1;
133 	/* number of buffers in fbuffers */
134 	u32 numbuffers;
135 	/* List of buffer pointers for storing frames */
136 	u8 *fbuffers[VIDEO_MAX_FRAME];
137 	/* Pointer pointing to current v4l2_buffer */
138 	struct videobuf_buffer *cur_frm;
139 	/* Pointer pointing to next v4l2_buffer */
140 	struct videobuf_buffer *next_frm;
141 	/*
142 	 * This field keeps track of type of buffer exchange mechanism
143 	 * user has selected
144 	 */
145 	enum v4l2_memory memory;
146 	/* Used to store pixel format */
147 	struct v4l2_format fmt;
148 	/*
149 	 * used when IMP is chained to store the crop window which
150 	 * is different from the image window
151 	 */
152 	struct v4l2_rect crop;
153 	/* Buffer queue used in video-buf */
154 	struct videobuf_queue buffer_queue;
155 	/* Queue of filled frames */
156 	struct list_head dma_queue;
157 	/* Used in video-buf */
158 	spinlock_t irqlock;
159 	/* IRQ lock for DMA queue */
160 	spinlock_t dma_queue_lock;
161 	/* lock used to access this structure */
162 	struct mutex lock;
163 	/* number of users performing IO */
164 	u32 io_usrs;
165 	/* Indicates whether streaming started */
166 	u8 started;
167 	/*
168 	 * offset where second field starts from the starting of the
169 	 * buffer for field separated YCbCr formats
170 	 */
171 	u32 field_off;
172 };
173 
174 /* File handle structure */
175 struct vpfe_fh {
176 	struct v4l2_fh fh;
177 	struct vpfe_device *vpfe_dev;
178 	/* Indicates whether this file handle is doing IO */
179 	u8 io_allowed;
180 };
181 
182 struct vpfe_config_params {
183 	u8 min_numbuffers;
184 	u8 numbuffers;
185 	u32 min_bufsize;
186 	u32 device_bufsize;
187 };
188 
189 #endif				/* End of __KERNEL__ */
190 /**
191  * VPFE_CMD_S_CCDC_RAW_PARAMS - EXPERIMENTAL IOCTL to set raw capture params
192  * This can be used to configure modules such as defect pixel correction,
193  * color space conversion, culling etc. This is an experimental ioctl that
194  * will change in future kernels. So use this ioctl with care !
195  * TODO: This is to be split into multiple ioctls and also explore the
196  * possibility of extending the v4l2 api to include this
197  **/
198 #define VPFE_CMD_S_CCDC_RAW_PARAMS _IOW('V', BASE_VIDIOC_PRIVATE + 1, \
199 					void *)
200 #endif				/* _DAVINCI_VPFE_H */
201