1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef _BUZ_H_
19#define _BUZ_H_
20
21#include <media/v4l2-device.h>
22#include <media/v4l2-ctrls.h>
23#include <media/videobuf2-core.h>
24#include <media/videobuf2-v4l2.h>
25#include <media/videobuf2-dma-contig.h>
26
27#define ZR_NORM_PAL 0
28#define ZR_NORM_NTSC 1
29#define ZR_NORM_SECAM 2
30
31struct zr_buffer {
32
33 struct vb2_v4l2_buffer vbuf;
34 struct list_head queue;
35};
36
37static inline struct zr_buffer *vb2_to_zr_buffer(struct vb2_buffer *vb)
38{
39 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
40
41 return container_of(vbuf, struct zr_buffer, vbuf);
42}
43
44#define ZORAN_NAME "ZORAN"
45
46#define ZR_DEVNAME(zr) ((zr)->name)
47
48#define BUZ_MAX_WIDTH (zr->timing->wa)
49#define BUZ_MAX_HEIGHT (zr->timing->ha)
50#define BUZ_MIN_WIDTH 32
51#define BUZ_MIN_HEIGHT 24
52
53#define BUZ_NUM_STAT_COM 4
54#define BUZ_MASK_STAT_COM 3
55
56#define BUZ_MAX_FRAME 256
57#define BUZ_MASK_FRAME 255
58
59#define BUZ_MAX_INPUT 16
60
61#if VIDEO_MAX_FRAME <= 32
62# define V4L_MAX_FRAME 32
63#elif VIDEO_MAX_FRAME <= 64
64# define V4L_MAX_FRAME 64
65#else
66# error "Too many video frame buffers to handle"
67#endif
68#define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
69
70#define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
71
72#include "zr36057.h"
73
74enum card_type {
75 UNKNOWN = -1,
76
77
78 DC10_OLD,
79 DC10_NEW,
80 DC10_PLUS,
81 DC30,
82 DC30_PLUS,
83
84
85 LML33,
86 LML33R10,
87
88
89 BUZ,
90
91
92 AVS6EYES,
93
94
95 NUM_CARDS
96};
97
98enum zoran_codec_mode {
99 BUZ_MODE_IDLE,
100 BUZ_MODE_MOTION_COMPRESS,
101 BUZ_MODE_MOTION_DECOMPRESS,
102 BUZ_MODE_STILL_COMPRESS,
103 BUZ_MODE_STILL_DECOMPRESS
104};
105
106enum zoran_map_mode {
107 ZORAN_MAP_MODE_NONE,
108 ZORAN_MAP_MODE_RAW,
109 ZORAN_MAP_MODE_JPG_REC,
110 ZORAN_MAP_MODE_JPG_PLAY,
111};
112
113enum gpio_type {
114 ZR_GPIO_JPEG_SLEEP = 0,
115 ZR_GPIO_JPEG_RESET,
116 ZR_GPIO_JPEG_FRAME,
117 ZR_GPIO_VID_DIR,
118 ZR_GPIO_VID_EN,
119 ZR_GPIO_VID_RESET,
120 ZR_GPIO_CLK_SEL1,
121 ZR_GPIO_CLK_SEL2,
122 ZR_GPIO_MAX,
123};
124
125enum gpcs_type {
126 GPCS_JPEG_RESET = 0,
127 GPCS_JPEG_START,
128 GPCS_MAX,
129};
130
131struct zoran_format {
132 char *name;
133 __u32 fourcc;
134 int colorspace;
135 int depth;
136 __u32 flags;
137 __u32 vfespfr;
138};
139
140
141#define ZORAN_FORMAT_COMPRESSED BIT(0)
142#define ZORAN_FORMAT_OVERLAY BIT(1)
143#define ZORAN_FORMAT_CAPTURE BIT(2)
144#define ZORAN_FORMAT_PLAYBACK BIT(3)
145
146
147struct zoran_v4l_settings {
148 int width, height, bytesperline;
149 const struct zoran_format *format;
150};
151
152
153struct zoran_jpg_settings {
154 int decimation;
155 int hor_dcm, ver_dcm, tmp_dcm;
156 int field_per_buff, odd_even;
157 int img_x, img_y, img_width, img_height;
158 struct v4l2_jpegcompression jpg_comp;
159};
160
161struct zoran;
162
163
164struct zoran_fh {
165 struct v4l2_fh fh;
166 struct zoran *zr;
167};
168
169struct card_info {
170 enum card_type type;
171 char name[32];
172 const char *i2c_decoder;
173 const unsigned short *addrs_decoder;
174 const char *i2c_encoder;
175 const unsigned short *addrs_encoder;
176 u16 video_vfe, video_codec;
177 u16 audio_chip;
178
179 int inputs;
180 struct input {
181 int muxsel;
182 char name[32];
183 } input[BUZ_MAX_INPUT];
184
185 v4l2_std_id norms;
186 const struct tvnorm *tvn[3];
187
188 u32 jpeg_int;
189 u32 vsync_int;
190 s8 gpio[ZR_GPIO_MAX];
191 u8 gpcs[GPCS_MAX];
192
193 struct vfe_polarity vfe_pol;
194 u8 gpio_pol[ZR_GPIO_MAX];
195
196
197 u8 gws_not_connected;
198
199
200 u8 input_mux;
201
202 void (*init)(struct zoran *zr);
203};
204
205struct zoran {
206 struct v4l2_device v4l2_dev;
207 struct v4l2_ctrl_handler hdl;
208 struct video_device *video_dev;
209 struct vb2_queue vq;
210
211 struct i2c_adapter i2c_adapter;
212 struct i2c_algo_bit_data i2c_algo;
213 u32 i2cbr;
214
215 struct v4l2_subdev *decoder;
216 struct v4l2_subdev *encoder;
217
218 struct videocodec *codec;
219 struct videocodec *vfe;
220
221 struct mutex lock;
222
223 u8 initialized;
224 struct card_info card;
225 const struct tvnorm *timing;
226
227 unsigned short id;
228 char name[32];
229 struct pci_dev *pci_dev;
230 unsigned char revision;
231 unsigned char __iomem *zr36057_mem;
232
233 spinlock_t spinlock;
234
235
236 int input;
237 v4l2_std_id norm;
238
239
240 unsigned int buffer_size;
241
242 struct zoran_v4l_settings v4l_settings;
243
244
245 enum zoran_codec_mode codec_mode;
246 struct zoran_jpg_settings jpg_settings;
247
248
249
250
251 unsigned long jpg_que_head;
252 unsigned long jpg_dma_head;
253 unsigned long jpg_dma_tail;
254 unsigned long jpg_que_tail;
255 unsigned long jpg_seq_num;
256 unsigned long jpg_err_seq;
257 unsigned long jpg_err_shift;
258 unsigned long jpg_queued_num;
259 unsigned long vbseq;
260
261
262 __le32 *stat_com;
263
264
265 unsigned int ghost_int;
266 int intr_counter_GIRQ1;
267 int intr_counter_GIRQ0;
268 int intr_counter_cod_rep_irq;
269 int intr_counter_jpeg_rep_irq;
270 int field_counter;
271 int irq1_in;
272 int irq1_out;
273 int jpeg_in;
274 int jpeg_out;
275 int JPEG_0;
276 int JPEG_1;
277 int end_event_missed;
278 int jpeg_missed;
279 int jpeg_error;
280 int num_errors;
281 int jpeg_max_missed;
282 int jpeg_min_missed;
283 unsigned int prepared;
284 unsigned int queued;
285
286 u32 last_isr;
287 unsigned long frame_num;
288 int running;
289 int buf_in_reserve;
290
291 dma_addr_t p_sc;
292 __le32 *stat_comb;
293 dma_addr_t p_scb;
294 enum zoran_map_mode map_mode;
295 struct list_head queued_bufs;
296 spinlock_t queued_bufs_lock;
297 struct zr_buffer *inuse[BUZ_NUM_STAT_COM * 2];
298};
299
300static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
301{
302 return container_of(v4l2_dev, struct zoran, v4l2_dev);
303}
304
305
306
307#define btwrite(dat, adr) writel((dat), zr->zr36057_mem + (adr))
308#define btread(adr) readl(zr->zr36057_mem + (adr))
309
310#define btand(dat, adr) btwrite((dat) & btread(adr), adr)
311#define btor(dat, adr) btwrite((dat) | btread(adr), adr)
312#define btaor(dat, mask, adr) btwrite((dat) | ((mask) & btread(adr)), adr)
313
314#endif
315
316int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq);
317void zoran_queue_exit(struct zoran *zr);
318int zr_set_buf(struct zoran *zr);
319