1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2008-2009 Texas Instruments Inc
4  */
5 
6 #ifndef _VPFE_CAPTURE_H
7 #define _VPFE_CAPTURE_H
8 
9 #ifdef __KERNEL__
10 
11 /* Header files */
12 #include <media/v4l2-dev.h>
13 #include <linux/videodev2.h>
14 #include <linux/clk.h>
15 #include <linux/i2c.h>
16 #include <media/v4l2-fh.h>
17 #include <media/v4l2-ioctl.h>
18 #include <media/v4l2-device.h>
19 #include <media/videobuf-dma-contig.h>
20 #include <media/davinci/vpfe_types.h>
21 
22 #define VPFE_CAPTURE_NUM_DECODERS        5
23 
24 /* Macros */
25 #define VPFE_MAJOR_RELEASE              0
26 #define VPFE_MINOR_RELEASE              0
27 #define VPFE_BUILD                      1
28 #define VPFE_CAPTURE_VERSION_CODE       ((VPFE_MAJOR_RELEASE << 16) | \
29 					(VPFE_MINOR_RELEASE << 8)  | \
30 					VPFE_BUILD)
31 
32 #define CAPTURE_DRV_NAME		"vpfe-capture"
33 
34 struct vpfe_pixel_format {
35 	u32 pixelformat;
36 	/* bytes per pixel */
37 	int bpp;
38 };
39 
40 struct vpfe_std_info {
41 	int active_pixels;
42 	int active_lines;
43 	/* current frame format */
44 	int frame_format;
45 };
46 
47 struct vpfe_route {
48 	u32 input;
49 	u32 output;
50 };
51 
52 struct vpfe_subdev_info {
53 	/* Sub device name */
54 	char name[32];
55 	/* Sub device group id */
56 	int grp_id;
57 	/* Number of inputs supported */
58 	int num_inputs;
59 	/* inputs available at the sub device */
60 	struct v4l2_input *inputs;
61 	/* Sub dev routing information for each input */
62 	struct vpfe_route *routes;
63 	/* check if sub dev supports routing */
64 	int can_route;
65 	/* ccdc bus/interface configuration */
66 	struct vpfe_hw_if_param ccdc_if_params;
67 	/* i2c subdevice board info */
68 	struct i2c_board_info board_info;
69 };
70 
71 struct vpfe_config {
72 	/* Number of sub devices connected to vpfe */
73 	int num_subdevs;
74 	/* i2c bus adapter no */
75 	int i2c_adapter_id;
76 	/* information about each subdev */
77 	struct vpfe_subdev_info *sub_devs;
78 	/* evm card info */
79 	char *card_name;
80 	/* ccdc name */
81 	char *ccdc;
82 	/* vpfe clock */
83 	struct clk *vpssclk;
84 	struct clk *slaveclk;
85 	/* Function for Clearing the interrupt */
86 	void (*clr_intr)(int vdint);
87 };
88 
89 struct vpfe_device {
90 	/* V4l2 specific parameters */
91 	/* Identifies video device for this channel */
92 	struct video_device video_dev;
93 	/* sub devices */
94 	struct v4l2_subdev **sd;
95 	/* vpfe cfg */
96 	struct vpfe_config *cfg;
97 	/* V4l2 device */
98 	struct v4l2_device v4l2_dev;
99 	/* parent device */
100 	struct device *pdev;
101 	/* number of open instances of the channel */
102 	u32 usrs;
103 	/* Indicates id of the field which is being displayed */
104 	u32 field_id;
105 	/* flag to indicate whether decoder is initialized */
106 	u8 initialized;
107 	/* current interface type */
108 	struct vpfe_hw_if_param vpfe_if_params;
109 	/* ptr to currently selected sub device */
110 	struct vpfe_subdev_info *current_subdev;
111 	/* current input at the sub device */
112 	int current_input;
113 	/* Keeps track of the information about the standard */
114 	struct vpfe_std_info std_info;
115 	/* std index into std table */
116 	int std_index;
117 	/* CCDC IRQs used when CCDC/ISIF output to SDRAM */
118 	unsigned int ccdc_irq0;
119 	unsigned int ccdc_irq1;
120 	/* number of buffers in fbuffers */
121 	u32 numbuffers;
122 	/* List of buffer pointers for storing frames */
123 	u8 *fbuffers[VIDEO_MAX_FRAME];
124 	/* Pointer pointing to current v4l2_buffer */
125 	struct videobuf_buffer *cur_frm;
126 	/* Pointer pointing to next v4l2_buffer */
127 	struct videobuf_buffer *next_frm;
128 	/*
129 	 * This field keeps track of type of buffer exchange mechanism
130 	 * user has selected
131 	 */
132 	enum v4l2_memory memory;
133 	/* Used to store pixel format */
134 	struct v4l2_format fmt;
135 	/*
136 	 * used when IMP is chained to store the crop window which
137 	 * is different from the image window
138 	 */
139 	struct v4l2_rect crop;
140 	/* Buffer queue used in video-buf */
141 	struct videobuf_queue buffer_queue;
142 	/* Queue of filled frames */
143 	struct list_head dma_queue;
144 	/* Used in video-buf */
145 	spinlock_t irqlock;
146 	/* IRQ lock for DMA queue */
147 	spinlock_t dma_queue_lock;
148 	/* lock used to access this structure */
149 	struct mutex lock;
150 	/* number of users performing IO */
151 	u32 io_usrs;
152 	/* Indicates whether streaming started */
153 	u8 started;
154 	/*
155 	 * offset where second field starts from the starting of the
156 	 * buffer for field separated YCbCr formats
157 	 */
158 	u32 field_off;
159 };
160 
161 /* File handle structure */
162 struct vpfe_fh {
163 	struct v4l2_fh fh;
164 	struct vpfe_device *vpfe_dev;
165 	/* Indicates whether this file handle is doing IO */
166 	u8 io_allowed;
167 };
168 
169 struct vpfe_config_params {
170 	u8 min_numbuffers;
171 	u8 numbuffers;
172 	u32 min_bufsize;
173 	u32 device_bufsize;
174 };
175 
176 #endif				/* End of __KERNEL__ */
177 #endif				/* _DAVINCI_VPFE_H */
178