aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/em28xx/em28xx.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/em28xx/em28xx.h')
-rw-r--r--drivers/media/video/em28xx/em28xx.h479
1 files changed, 479 insertions, 0 deletions
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
new file mode 100644
index 000000000000..7779121a3dea
--- /dev/null
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -0,0 +1,479 @@
1/*
2 em2820-cards.c - driver for Empia EM2820/2840 USB video capture devices
3
4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
5 Ludovico Cavedon <cavedon@sssup.it>
6 Mauro Carvalho Chehab <mchehab@brturbo.com.br>
7
8 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#ifndef _EM2820_H
26#define _EM2820_H
27
28#include <linux/videodev.h>
29#include <linux/i2c.h>
30
31/* maximum number of frames that can be queued */
32#define EM2820_NUM_FRAMES 5
33/* number of frames that get used for v4l2_read() */
34#define EM2820_NUM_READ_FRAMES 2
35
36/* number of buffers for isoc transfers */
37#define EM2820_NUM_BUFS 5
38
39/* number of packets for each buffer */
40// windows requests only 40 packets .. so we better do the same
41// this is what I found out for all alternate numbers there!
42
43#define EM2820_NUM_PACKETS 40
44
45/* packet size for each packet */
46/* no longer needed: read from endpoint descriptor */
47//#define EM2820_MAX_PACKET_SIZE 3072 //7
48//#define EM2820_MAX_PACKET_SIZE 2892 //6
49//#define EM2820_MAX_PACKET_SIZE 2580 //5
50//#define EM2820_MAX_PACKET_SIZE 1448 //2
51
52/* default alternate; 0 means choose the best */
53#define EM2820_PINOUT 0
54#define EM2820_MAX_ALT 7
55
56#define EM2820_INTERLACED_DEFAULT 1
57
58/*
59#define (use usbview if you want to get the other alternate number infos)
60#define
61#define alternate number 2
62#define Endpoint Address: 82
63 Direction: in
64 Attribute: 1
65 Type: Isoc
66 Max Packet Size: 1448
67 Interval: 125us
68
69 alternate number 7
70
71 Endpoint Address: 82
72 Direction: in
73 Attribute: 1
74 Type: Isoc
75 Max Packet Size: 3072
76 Interval: 125us
77*/
78
79/* time to wait when stopping the isoc transfer */
80#define EM2820_URB_TIMEOUT msecs_to_jiffies(EM2820_NUM_BUFS * EM2820_NUM_PACKETS)
81
82/* the various frame states */
83enum em2820_frame_state {
84 F_UNUSED = 0,
85 F_QUEUED,
86 F_GRABBING,
87 F_DONE,
88 F_ERROR,
89};
90
91/* stream states */
92enum em2820_stream_state {
93 STREAM_OFF,
94 STREAM_INTERRUPT,
95 STREAM_ON,
96};
97
98/* frames */
99struct em2820_frame_t {
100 void *bufmem;
101 struct v4l2_buffer buf;
102 enum em2820_frame_state state;
103 struct list_head frame;
104 unsigned long vma_use_count;
105 int top_field;
106 int fieldbytesused;
107};
108
109/* io methods */
110enum em2820_io_method {
111 IO_NONE,
112 IO_READ,
113 IO_MMAP,
114};
115
116/* inputs */
117
118#define MAX_EM2820_INPUT 4
119enum enum2820_itype {
120 EM2820_VMUX_COMPOSITE1 = 1,
121 EM2820_VMUX_COMPOSITE2,
122 EM2820_VMUX_COMPOSITE3,
123 EM2820_VMUX_COMPOSITE4,
124 EM2820_VMUX_SVIDEO,
125 EM2820_VMUX_TELEVISION,
126 EM2820_VMUX_CABLE,
127 EM2820_VMUX_DVB,
128 EM2820_VMUX_DEBUG,
129 EM2820_RADIO,
130};
131
132struct em2820_input {
133 enum enum2820_itype type;
134 unsigned int vmux;
135 unsigned int amux;
136};
137
138#define INPUT(nr) (&em2820_boards[dev->model].input[nr])
139
140enum em2820_decoder {
141 EM2820_TVP5150,
142 EM2820_SAA7113,
143 EM2820_SAA7114
144};
145
146struct em2820_board {
147 char *name;
148
149 int vchannels;
150 int norm;
151 int tuner_type;
152
153 /* i2c flags */
154 unsigned int tda9887_conf;
155
156 unsigned int has_tuner:1;
157 unsigned int has_msp34xx:1;
158
159 enum em2820_decoder decoder;
160
161 struct em2820_input input[MAX_EM2820_INPUT];
162};
163
164struct em2820_eeprom {
165 u32 id; /* 0x9567eb1a */
166 u16 vendor_ID;
167 u16 product_ID;
168
169 u16 chip_conf;
170
171 u16 board_conf;
172
173 u16 string1, string2, string3;
174
175 u8 string_idx_table;
176};
177
178/* device states */
179enum em2820_dev_state {
180 DEV_INITIALIZED = 0x01,
181 DEV_DISCONNECTED = 0x02,
182 DEV_MISCONFIGURED = 0x04,
183};
184
185/* tvnorms */
186struct em2820_tvnorm {
187 char *name;
188 v4l2_std_id id;
189 /* mode for saa7113h */
190 int mode;
191};
192
193/* main device struct */
194struct em2820 {
195 /* generic device properties */
196 char name[30]; /* name (including minor) of the device */
197 int model; /* index in the device_data struct */
198 int video_inputs; /* number of video inputs */
199 unsigned int has_tuner:1;
200 unsigned int has_msp34xx:1;
201 unsigned int has_tda9887:1;
202
203 enum em2820_decoder decoder;
204
205 int tuner_type; /* type of the tuner */
206 int tuner_addr; /* tuner address */
207 int tda9887_conf;
208 /* i2c i/o */
209 struct i2c_adapter i2c_adap;
210 struct i2c_client i2c_client;
211 /* video for linux */
212 int users; /* user count for exclusive use */
213 struct video_device *vdev; /* video for linux device struct */
214 struct video_picture vpic; /* picture settings only used to init saa7113h */
215 struct em2820_tvnorm *tvnorm; /* selected tv norm */
216 int ctl_freq; /* selected frequency */
217 unsigned int ctl_input; /* selected input */
218 unsigned int ctl_ainput; /* slected audio input */
219 int mute;
220 int volume;
221 /* frame properties */
222 struct em2820_frame_t frame[EM2820_NUM_FRAMES]; /* list of frames */
223 int num_frames; /* number of frames currently in use */
224 unsigned int frame_count; /* total number of transfered frames */
225 struct em2820_frame_t *frame_current; /* the frame that is being filled */
226 int width; /* current frame width */
227 int height; /* current frame height */
228 int frame_size; /* current frame size */
229 int field_size; /* current field size */
230 int bytesperline;
231 int hscale; /* horizontal scale factor (see datasheet) */
232 int vscale; /* vertical scale factor (see datasheet) */
233 int interlaced; /* 1=interlace fileds, 0=just top fileds */
234 int type;
235
236 /* states */
237 enum em2820_dev_state state;
238 enum em2820_stream_state stream;
239 enum em2820_io_method io;
240 /* locks */
241 struct semaphore lock, fileop_lock;
242 spinlock_t queue_lock;
243 struct list_head inqueue, outqueue;
244 wait_queue_head_t open, wait_frame, wait_stream;
245 struct video_device *vbi_dev;
246
247 unsigned char eedata[256];
248
249 /* usb transfer */
250 struct usb_device *udev; /* the usb device */
251 int alt; /* alternate */
252 int max_pkt_size; /* max packet size of isoc transaction */
253 unsigned int alt_max_pkt_size[EM2820_MAX_ALT + 1]; /* array of wMaxPacketSize */
254 struct urb *urb[EM2820_NUM_BUFS]; /* urb for isoc transfers */
255 char *transfer_buffer[EM2820_NUM_BUFS]; /* transfer buffers for isoc transfer */
256 /* helper funcs that call usb_control_msg */
257 int (*em2820_write_regs) (struct em2820 * dev, u16 reg, char *buf,
258 int len);
259 int (*em2820_read_reg) (struct em2820 * dev, u16 reg);
260 int (*em2820_read_reg_req_len) (struct em2820 * dev, u8 req, u16 reg,
261 char *buf, int len);
262 int (*em2820_write_regs_req) (struct em2820 * dev, u8 req, u16 reg,
263 char *buf, int len);
264 int (*em2820_read_reg_req) (struct em2820 * dev, u8 req, u16 reg);
265};
266
267/* Provided by em2820-i2c.c */
268
269void em2820_i2c_call_clients(struct em2820 *dev, unsigned int cmd, void *arg);
270int em2820_i2c_register(struct em2820 *dev);
271int em2820_i2c_unregister(struct em2820 *dev);
272
273/* Provided by em2820-core.c */
274
275void em2820_print_ioctl(char *name, unsigned int cmd);
276
277u32 em2820_request_buffers(struct em2820 *dev, u32 count);
278void em2820_queue_unusedframes(struct em2820 *dev);
279void em2820_release_buffers(struct em2820 *dev);
280
281int em2820_read_reg_req_len(struct em2820 *dev, u8 req, u16 reg,
282 char *buf, int len);
283int em2820_read_reg_req(struct em2820 *dev, u8 req, u16 reg);
284int em2820_read_reg(struct em2820 *dev, u16 reg);
285int em2820_write_regs_req(struct em2820 *dev, u8 req, u16 reg, char *buf,
286 int len);
287int em2820_write_regs(struct em2820 *dev, u16 reg, char *buf, int len);
288int em2820_write_reg_bits(struct em2820 *dev, u16 reg, u8 val,
289 u8 bitmask);
290int em2820_write_ac97(struct em2820 *dev, u8 reg, u8 * val);
291int em2820_audio_analog_set(struct em2820 *dev);
292int em2820_colorlevels_set_default(struct em2820 *dev);
293int em2820_capture_start(struct em2820 *dev, int start);
294int em2820_outfmt_set_yuv422(struct em2820 *dev);
295int em2820_accumulator_set(struct em2820 *dev, u8 xmin, u8 xmax, u8 ymin,
296 u8 ymax);
297int em2820_capture_area_set(struct em2820 *dev, u8 hstart, u8 vstart,
298 u16 width, u16 height);
299int em2820_scaler_set(struct em2820 *dev, u16 h, u16 v);
300int em2820_resolution_set(struct em2820 *dev);
301void em2820_isocIrq(struct urb *urb, struct pt_regs *regs);
302int em2820_init_isoc(struct em2820 *dev);
303void em2820_uninit_isoc(struct em2820 *dev);
304int em2820_set_alternate(struct em2820 *dev);
305
306/* Provided by em2820-cards.c */
307extern void em2820_card_setup(struct em2820 *dev);
308extern struct em2820_board em2820_boards[];
309extern struct usb_device_id em2820_id_table[];
310
311/* em2820 registers */
312#define USBSUSP_REG 0x0c /* */
313
314#define AUDIOSRC_REG 0x0e
315#define XCLK_REG 0x0f
316
317#define VINMODE_REG 0x10
318#define VINCTRL_REG 0x11
319#define VINENABLE_REG 0x12 /* */
320
321#define GAMMA_REG 0x14
322#define RGAIN_REG 0x15
323#define GGAIN_REG 0x16
324#define BGAIN_REG 0x17
325#define ROFFSET_REG 0x18
326#define GOFFSET_REG 0x19
327#define BOFFSET_REG 0x1a
328
329#define OFLOW_REG 0x1b
330#define HSTART_REG 0x1c
331#define VSTART_REG 0x1d
332#define CWIDTH_REG 0x1e
333#define CHEIGHT_REG 0x1f
334
335#define YGAIN_REG 0x20
336#define YOFFSET_REG 0x21
337#define UVGAIN_REG 0x22
338#define UOFFSET_REG 0x23
339#define VOFFSET_REG 0x24
340#define SHARPNESS_REG 0x25
341
342#define COMPR_REG 0x26
343#define OUTFMT_REG 0x27
344
345#define XMIN_REG 0x28
346#define XMAX_REG 0x29
347#define YMIN_REG 0x2a
348#define YMAX_REG 0x2b
349
350#define HSCALELOW_REG 0x30
351#define HSCALEHIGH_REG 0x31
352#define VSCALELOW_REG 0x32
353#define VSCALEHIGH_REG 0x33
354
355#define AC97LSB_REG 0x40
356#define AC97MSB_REG 0x41
357#define AC97ADDR_REG 0x42
358#define AC97BUSY_REG 0x43
359
360/* em202 registers */
361#define MASTER_AC97 0x02
362#define VIDEO_AC97 0x14
363
364/* register settings */
365#define EM2820_AUDIO_SRC_TUNER 0xc0
366#define EM2820_AUDIO_SRC_LINE 0x80
367
368/* printk macros */
369
370#define em2820_err(fmt, arg...) do {\
371 printk(KERN_ERR fmt , ##arg); } while (0)
372
373#define em2820_errdev(fmt, arg...) do {\
374 printk(KERN_ERR "%s: "fmt,\
375 dev->name , ##arg); } while (0)
376
377#define em2820_info(fmt, arg...) do {\
378 printk(KERN_INFO "%s: "fmt,\
379 dev->name , ##arg); } while (0)
380#define em2820_warn(fmt, arg...) do {\
381 printk(KERN_WARNING "%s: "fmt,\
382 dev->name , ##arg); } while (0)
383
384inline static int em2820_audio_source(struct em2820 *dev, int input)
385{
386 return em2820_write_reg_bits(dev, AUDIOSRC_REG, input, 0xc0);
387}
388
389inline static int em2820_audio_usb_mute(struct em2820 *dev, int mute)
390{
391 return em2820_write_reg_bits(dev, XCLK_REG, mute ? 0x00 : 0x80, 0x80);
392}
393
394inline static int em2820_audio_analog_setup(struct em2820 *dev)
395{
396 /* unmute video mixer with default volume level */
397 return em2820_write_ac97(dev, VIDEO_AC97, "\x08\x08");
398}
399
400inline static int em2820_compression_disable(struct em2820 *dev)
401{
402 /* side effect of disabling scaler and mixer */
403 return em2820_write_regs(dev, COMPR_REG, "\x00", 1);
404}
405
406inline static int em2820_contrast_get(struct em2820 *dev)
407{
408 return em2820_read_reg(dev, YGAIN_REG) & 0x1f;
409}
410
411inline static int em2820_brightness_get(struct em2820 *dev)
412{
413 return em2820_read_reg(dev, YOFFSET_REG);
414}
415
416inline static int em2820_saturation_get(struct em2820 *dev)
417{
418 return em2820_read_reg(dev, UVGAIN_REG) & 0x1f;
419}
420
421inline static int em2820_u_balance_get(struct em2820 *dev)
422{
423 return em2820_read_reg(dev, UOFFSET_REG);
424}
425
426inline static int em2820_v_balance_get(struct em2820 *dev)
427{
428 return em2820_read_reg(dev, VOFFSET_REG);
429}
430
431inline static int em2820_gamma_get(struct em2820 *dev)
432{
433 return em2820_read_reg(dev, GAMMA_REG) & 0x3f;
434}
435
436inline static int em2820_contrast_set(struct em2820 *dev, s32 val)
437{
438 u8 tmp = (u8) val;
439 return em2820_write_regs(dev, YGAIN_REG, &tmp, 1);
440}
441
442inline static int em2820_brightness_set(struct em2820 *dev, s32 val)
443{
444 u8 tmp = (u8) val;
445 return em2820_write_regs(dev, YOFFSET_REG, &tmp, 1);
446}
447
448inline static int em2820_saturation_set(struct em2820 *dev, s32 val)
449{
450 u8 tmp = (u8) val;
451 return em2820_write_regs(dev, UVGAIN_REG, &tmp, 1);
452}
453
454inline static int em2820_u_balance_set(struct em2820 *dev, s32 val)
455{
456 u8 tmp = (u8) val;
457 return em2820_write_regs(dev, UOFFSET_REG, &tmp, 1);
458}
459
460inline static int em2820_v_balance_set(struct em2820 *dev, s32 val)
461{
462 u8 tmp = (u8) val;
463 return em2820_write_regs(dev, VOFFSET_REG, &tmp, 1);
464}
465
466inline static int em2820_gamma_set(struct em2820 *dev, s32 val)
467{
468 u8 tmp = (u8) val;
469 return em2820_write_regs(dev, GAMMA_REG, &tmp, 1);
470}
471
472/*FIXME: maxw should be dependent of alt mode */
473#define norm_maxw(dev) 720
474inline static unsigned int norm_maxh(struct em2820 *dev)
475{
476 return (dev->tvnorm->id & V4L2_STD_625_50) ? 576 : 480;
477}
478
479#endif