2 * $Id: saa7134.h,v 1.49 2005/07/13 17:25:25 mchehab Exp $
4 * v4l2 device driver for philips saa7134 based TV cards
6 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/version.h>
24 #define SAA7134_VERSION_CODE KERNEL_VERSION(0,2,14)
26 #include <linux/pci.h>
27 #include <linux/i2c.h>
28 #include <linux/videodev.h>
29 #include <linux/kdev_t.h>
30 #include <linux/input.h>
34 #include <media/tuner.h>
35 #include <media/audiochip.h>
37 #include <media/ir-common.h>
38 #include <media/video-buf.h>
39 #include <media/video-buf-dvb.h>
49 /* ----------------------------------------------------------- */
52 enum saa7134_tvaudio_mode
{
54 TVAUDIO_FM_BG_STEREO
= 2,
55 TVAUDIO_FM_SAT_STEREO
= 3,
56 TVAUDIO_FM_K_STEREO
= 4,
61 enum saa7134_audio_in
{
68 enum saa7134_video_out
{
72 /* ----------------------------------------------------------- */
75 struct saa7134_tvnorm
{
80 unsigned int sync_control
;
81 unsigned int luma_control
;
82 unsigned int chroma_ctrl1
;
83 unsigned int chroma_gain
;
84 unsigned int chroma_ctrl2
;
85 unsigned int vgate_misc
;
90 unsigned int video_v_start
;
91 unsigned int video_v_stop
;
92 unsigned int vbi_v_start_0
;
93 unsigned int vbi_v_stop_0
;
94 unsigned int src_timing
;
95 unsigned int vbi_v_start_1
;
98 struct saa7134_tvaudio
{
101 enum saa7134_tvaudio_mode mode
;
106 struct saa7134_format
{
111 unsigned int vshift
; /* vertical downsampling (for planar yuv) */
112 unsigned int hshift
; /* horizontal downsampling (for planar yuv) */
113 unsigned int bswap
:1;
114 unsigned int wswap
:1;
116 unsigned int planar
:1;
117 unsigned int uvswap
:1;
120 /* ----------------------------------------------------------- */
121 /* card configuration */
123 #define SAA7134_BOARD_NOAUTO UNSET
124 #define SAA7134_BOARD_UNKNOWN 0
125 #define SAA7134_BOARD_PROTEUS_PRO 1
126 #define SAA7134_BOARD_FLYVIDEO3000 2
127 #define SAA7134_BOARD_FLYVIDEO2000 3
128 #define SAA7134_BOARD_EMPRESS 4
129 #define SAA7134_BOARD_MONSTERTV 5
130 #define SAA7134_BOARD_MD9717 6
131 #define SAA7134_BOARD_TVSTATION_RDS 7
132 #define SAA7134_BOARD_CINERGY400 8
133 #define SAA7134_BOARD_MD5044 9
134 #define SAA7134_BOARD_KWORLD 10
135 #define SAA7134_BOARD_CINERGY600 11
136 #define SAA7134_BOARD_MD7134 12
137 #define SAA7134_BOARD_TYPHOON_90031 13
138 #define SAA7134_BOARD_ELSA 14
139 #define SAA7134_BOARD_ELSA_500TV 15
140 #define SAA7134_BOARD_ASUSTeK_TVFM7134 16
141 #define SAA7134_BOARD_VA1000POWER 17
142 #define SAA7134_BOARD_BMK_MPEX_NOTUNER 18
143 #define SAA7134_BOARD_VIDEOMATE_TV 19
144 #define SAA7134_BOARD_CRONOS_PLUS 20
145 #define SAA7134_BOARD_10MOONSTVMASTER 21
146 #define SAA7134_BOARD_MD2819 22
147 #define SAA7134_BOARD_BMK_MPEX_TUNER 23
148 #define SAA7134_BOARD_TVSTATION_DVR 24
149 #define SAA7134_BOARD_ASUSTEK_TVFM7133 25
150 #define SAA7134_BOARD_PINNACLE_PCTV_STEREO 26
151 #define SAA7134_BOARD_MANLI_MTV002 27
152 #define SAA7134_BOARD_MANLI_MTV001 28
153 #define SAA7134_BOARD_TG3000TV 29
154 #define SAA7134_BOARD_ECS_TVP3XP 30
155 #define SAA7134_BOARD_ECS_TVP3XP_4CB5 31
156 #define SAA7134_BOARD_AVACSSMARTTV 32
157 #define SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER 33
158 #define SAA7134_BOARD_NOVAC_PRIMETV7133 34
159 #define SAA7134_BOARD_AVERMEDIA_STUDIO_305 35
160 #define SAA7134_BOARD_UPMOST_PURPLE_TV 36
161 #define SAA7134_BOARD_ITEMS_MTV005 37
162 #define SAA7134_BOARD_CINERGY200 38
163 #define SAA7134_BOARD_FLYTVPLATINUM_MINI 39
164 #define SAA7134_BOARD_VIDEOMATE_TV_PVR 40
165 #define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS 41
166 #define SAA7134_BOARD_SABRENT_SBTTVFM 42
167 #define SAA7134_BOARD_ZOLID_XPERT_TV7134 43
168 #define SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE 44
169 #define SAA7134_BOARD_AVERMEDIA_STUDIO_307 45
170 #define SAA7134_BOARD_AVERMEDIA_CARDBUS 46
171 #define SAA7134_BOARD_CINERGY400_CARDBUS 47
172 #define SAA7134_BOARD_CINERGY600_MK3 48
173 #define SAA7134_BOARD_VIDEOMATE_GOLD_PLUS 49
174 #define SAA7134_BOARD_PINNACLE_300I_DVBT_PAL 50
175 #define SAA7134_BOARD_PROVIDEO_PV952 51
176 #define SAA7134_BOARD_AVERMEDIA_305 52
177 #define SAA7134_BOARD_ASUSTeK_TVFM7135 53
178 #define SAA7134_BOARD_FLYTVPLATINUM_FM 54
179 #define SAA7134_BOARD_FLYDVBTDUO 55
180 #define SAA7134_BOARD_AVERMEDIA_307 56
181 #define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57
182 #define SAA7134_BOARD_ADS_INSTANT_TV 58
183 #define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59
184 #define SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS 60
185 #define SAA7134_BOARD_PHILIPS_TOUGH 61
186 #define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII 62
187 #define SAA7134_BOARD_KWORLD_XPERT 63
189 #define SAA7134_MAXBOARDS 8
190 #define SAA7134_INPUT_MAX 8
192 struct saa7134_input
{
195 enum saa7134_audio_in amux
;
200 enum saa7134_mpeg_type
{
202 SAA7134_MPEG_EMPRESS
,
206 struct saa7134_board
{
208 unsigned int audio_clock
;
210 /* input switching */
211 unsigned int gpiomask
;
212 struct saa7134_input inputs
[SAA7134_INPUT_MAX
];
213 struct saa7134_input radio
;
214 struct saa7134_input mute
;
217 unsigned int tuner_type
;
218 unsigned int radio_type
;
219 unsigned char tuner_addr
;
220 unsigned char radio_addr
;
222 unsigned int tda9887_conf
;
225 enum saa7134_video_out video_out
;
226 enum saa7134_mpeg_type mpeg
;
229 #define card_has_radio(dev) (NULL != saa7134_boards[dev->board].radio.name)
230 #define card_is_empress(dev) (SAA7134_MPEG_EMPRESS == saa7134_boards[dev->board].mpeg)
231 #define card_is_dvb(dev) (SAA7134_MPEG_DVB == saa7134_boards[dev->board].mpeg)
232 #define card_has_mpeg(dev) (SAA7134_MPEG_UNUSED != saa7134_boards[dev->board].mpeg)
233 #define card(dev) (saa7134_boards[dev->board])
234 #define card_in(dev,n) (saa7134_boards[dev->board].inputs[n])
236 /* ----------------------------------------------------------- */
237 /* device / file handle status */
239 #define RESOURCE_OVERLAY 1
240 #define RESOURCE_VIDEO 2
241 #define RESOURCE_VBI 4
243 #define INTERLACE_AUTO 0
244 #define INTERLACE_ON 1
245 #define INTERLACE_OFF 2
247 #define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
252 /* saa7134 page table */
253 struct saa7134_pgtable
{
259 /* tvaudio thread status */
260 struct saa7134_thread
{
262 struct completion exit
;
263 wait_queue_head_t wq
;
264 unsigned int shutdown
;
270 /* buffer for one video/vbi/ts frame */
272 /* common v4l buffer stuff -- must be first */
273 struct videobuf_buffer vb
;
275 /* saa7134 specific */
276 struct saa7134_format
*fmt
;
277 unsigned int top_seen
;
278 int (*activate
)(struct saa7134_dev
*dev
,
279 struct saa7134_buf
*buf
,
280 struct saa7134_buf
*next
);
283 struct saa7134_pgtable
*pt
;
286 struct saa7134_dmaqueue
{
287 struct saa7134_dev
*dev
;
288 struct saa7134_buf
*curr
;
289 struct list_head queue
;
290 struct timer_list timeout
;
291 unsigned int need_two
;
294 /* video filehandle status */
296 struct saa7134_dev
*dev
;
298 enum v4l2_buf_type type
;
299 unsigned int resources
;
300 #ifdef VIDIOC_G_PRIORITY
301 enum v4l2_priority prio
;
305 struct v4l2_window win
;
306 struct v4l2_clip clips
[8];
310 struct saa7134_format
*fmt
;
311 unsigned int width
,height
;
312 struct videobuf_queue cap
;
313 struct saa7134_pgtable pt_cap
;
316 struct videobuf_queue vbi
;
317 struct saa7134_pgtable pt_vbi
;
322 struct semaphore lock
;
325 unsigned int users_dsp
;
328 enum saa7134_audio_in input
;
336 unsigned int channels
;
337 unsigned int recording_on
;
338 unsigned int dma_running
;
340 unsigned int blksize
;
341 unsigned int bufsize
;
342 struct saa7134_pgtable pt
;
343 struct videobuf_dmabuf dma
;
344 wait_queue_head_t wq
;
345 unsigned int dma_blk
;
346 unsigned int read_offset
;
347 unsigned int read_count
;
352 struct input_dev dev
;
353 struct ir_input_state ir
;
361 struct timer_list timer
;
367 struct saa7134_pgtable pt_ts
;
373 struct saa7134_mpeg_ops
{
374 enum saa7134_mpeg_type type
;
375 struct list_head next
;
376 int (*init
)(struct saa7134_dev
*dev
);
377 int (*fini
)(struct saa7134_dev
*dev
);
378 void (*signal_change
)(struct saa7134_dev
*dev
);
381 /* global device status */
383 struct list_head devlist
;
384 struct semaphore lock
;
386 #ifdef VIDIOC_G_PRIORITY
387 struct v4l2_prio_state prio
;
390 /* various device info */
391 unsigned int resources
;
392 struct video_device
*video_dev
;
393 struct video_device
*radio_dev
;
394 struct video_device
*vbi_dev
;
395 struct saa7134_oss oss
;
397 /* infrared remote */
399 struct saa7134_ir
*remote
;
405 unsigned char pci_rev
,pci_lat
;
406 __u32 __iomem
*lmmio
;
411 unsigned int tuner_type
;
412 unsigned int radio_type
;
413 unsigned char tuner_addr
;
414 unsigned char radio_addr
;
416 unsigned int tda9887_conf
;
417 unsigned int gpio_value
;
420 struct i2c_adapter i2c_adap
;
421 struct i2c_client i2c_client
;
422 unsigned char eedata
[64];
425 struct v4l2_framebuffer ovbuf
;
426 struct saa7134_format
*ovfmt
;
427 unsigned int ovenable
;
428 enum v4l2_field ovfield
;
430 /* video+ts+vbi capture */
431 struct saa7134_dmaqueue video_q
;
432 struct saa7134_dmaqueue vbi_q
;
433 unsigned int video_fieldcount
;
434 unsigned int vbi_fieldcount
;
436 /* various v4l controls */
437 struct saa7134_tvnorm
*tvnorm
; /* video */
438 struct saa7134_tvaudio
*tvaudio
;
439 unsigned int ctl_input
;
445 int ctl_mute
; /* audio */
447 int ctl_invert
; /* private */
454 struct v4l2_rect crop_bounds
;
455 struct v4l2_rect crop_defrect
;
456 struct v4l2_rect crop_current
;
458 /* other global state info */
459 unsigned int automute
;
460 struct saa7134_thread thread
;
461 struct saa7134_input
*input
;
462 struct saa7134_input
*hw_input
;
463 unsigned int hw_mute
;
468 struct saa7134_ts ts
;
469 struct saa7134_dmaqueue ts_q
;
470 struct saa7134_mpeg_ops
*mops
;
472 /* SAA7134_MPEG_EMPRESS only */
473 struct video_device
*empress_dev
;
474 struct videobuf_queue empress_tsq
;
475 unsigned int empress_users
;
476 struct work_struct empress_workqueue
;
479 /* SAA7134_MPEG_DVB only */
480 struct videobuf_dvb dvb
;
483 /* ----------------------------------------------------------- */
485 #define saa_readl(reg) readl(dev->lmmio + (reg))
486 #define saa_writel(reg,value) writel((value), dev->lmmio + (reg));
487 #define saa_andorl(reg,mask,value) \
488 writel((readl(dev->lmmio+(reg)) & ~(mask)) |\
489 ((value) & (mask)), dev->lmmio+(reg))
490 #define saa_setl(reg,bit) saa_andorl((reg),(bit),(bit))
491 #define saa_clearl(reg,bit) saa_andorl((reg),(bit),0)
493 #define saa_readb(reg) readb(dev->bmmio + (reg))
494 #define saa_writeb(reg,value) writeb((value), dev->bmmio + (reg));
495 #define saa_andorb(reg,mask,value) \
496 writeb((readb(dev->bmmio+(reg)) & ~(mask)) |\
497 ((value) & (mask)), dev->bmmio+(reg))
498 #define saa_setb(reg,bit) saa_andorb((reg),(bit),(bit))
499 #define saa_clearb(reg,bit) saa_andorb((reg),(bit),0)
501 #define saa_wait(us) { udelay(us); }
503 /* ----------------------------------------------------------- */
506 extern struct list_head saa7134_devlist
;
508 void saa7134_print_ioctl(char *name
, unsigned int cmd
);
509 void saa7134_track_gpio(struct saa7134_dev
*dev
, char *msg
);
511 #define SAA7134_PGTABLE_SIZE 4096
513 int saa7134_pgtable_alloc(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
);
514 int saa7134_pgtable_build(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
,
515 struct scatterlist
*list
, unsigned int length
,
516 unsigned int startpage
);
517 void saa7134_pgtable_free(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
);
519 int saa7134_buffer_count(unsigned int size
, unsigned int count
);
520 int saa7134_buffer_startpage(struct saa7134_buf
*buf
);
521 unsigned long saa7134_buffer_base(struct saa7134_buf
*buf
);
523 int saa7134_buffer_queue(struct saa7134_dev
*dev
, struct saa7134_dmaqueue
*q
,
524 struct saa7134_buf
*buf
);
525 void saa7134_buffer_finish(struct saa7134_dev
*dev
, struct saa7134_dmaqueue
*q
,
527 void saa7134_buffer_next(struct saa7134_dev
*dev
, struct saa7134_dmaqueue
*q
);
528 void saa7134_buffer_timeout(unsigned long data
);
529 void saa7134_dma_free(struct saa7134_dev
*dev
,struct saa7134_buf
*buf
);
531 int saa7134_set_dmabits(struct saa7134_dev
*dev
);
533 /* ----------------------------------------------------------- */
534 /* saa7134-cards.c */
536 extern struct saa7134_board saa7134_boards
[];
537 extern const unsigned int saa7134_bcount
;
538 extern struct pci_device_id __devinitdata saa7134_pci_tbl
[];
540 extern int saa7134_board_init1(struct saa7134_dev
*dev
);
541 extern int saa7134_board_init2(struct saa7134_dev
*dev
);
544 /* ----------------------------------------------------------- */
547 int saa7134_i2c_register(struct saa7134_dev
*dev
);
548 int saa7134_i2c_unregister(struct saa7134_dev
*dev
);
549 void saa7134_i2c_call_clients(struct saa7134_dev
*dev
,
550 unsigned int cmd
, void *arg
);
553 /* ----------------------------------------------------------- */
554 /* saa7134-video.c */
556 extern struct video_device saa7134_video_template
;
557 extern struct video_device saa7134_radio_template
;
559 int saa7134_common_ioctl(struct saa7134_dev
*dev
,
560 unsigned int cmd
, void *arg
);
562 int saa7134_video_init1(struct saa7134_dev
*dev
);
563 int saa7134_video_init2(struct saa7134_dev
*dev
);
564 int saa7134_video_fini(struct saa7134_dev
*dev
);
565 void saa7134_irq_video_intl(struct saa7134_dev
*dev
);
566 void saa7134_irq_video_done(struct saa7134_dev
*dev
, unsigned long status
);
569 /* ----------------------------------------------------------- */
572 #define TS_PACKET_SIZE 188 /* TS packets 188 bytes */
574 extern struct videobuf_queue_ops saa7134_ts_qops
;
576 int saa7134_ts_init1(struct saa7134_dev
*dev
);
577 int saa7134_ts_fini(struct saa7134_dev
*dev
);
578 void saa7134_irq_ts_done(struct saa7134_dev
*dev
, unsigned long status
);
580 int saa7134_ts_register(struct saa7134_mpeg_ops
*ops
);
581 void saa7134_ts_unregister(struct saa7134_mpeg_ops
*ops
);
583 /* ----------------------------------------------------------- */
586 extern struct videobuf_queue_ops saa7134_vbi_qops
;
587 extern struct video_device saa7134_vbi_template
;
589 int saa7134_vbi_init1(struct saa7134_dev
*dev
);
590 int saa7134_vbi_fini(struct saa7134_dev
*dev
);
591 void saa7134_irq_vbi_done(struct saa7134_dev
*dev
, unsigned long status
);
594 /* ----------------------------------------------------------- */
595 /* saa7134-tvaudio.c */
597 int saa7134_tvaudio_rx2mode(u32 rx
);
599 void saa7134_tvaudio_setmute(struct saa7134_dev
*dev
);
600 void saa7134_tvaudio_setinput(struct saa7134_dev
*dev
,
601 struct saa7134_input
*in
);
602 void saa7134_tvaudio_setvolume(struct saa7134_dev
*dev
, int level
);
603 int saa7134_tvaudio_getstereo(struct saa7134_dev
*dev
);
605 int saa7134_tvaudio_init2(struct saa7134_dev
*dev
);
606 int saa7134_tvaudio_fini(struct saa7134_dev
*dev
);
607 int saa7134_tvaudio_do_scan(struct saa7134_dev
*dev
);
609 int saa_dsp_writel(struct saa7134_dev
*dev
, int reg
, u32 value
);
611 /* ----------------------------------------------------------- */
614 extern struct file_operations saa7134_dsp_fops
;
615 extern struct file_operations saa7134_mixer_fops
;
617 int saa7134_oss_init1(struct saa7134_dev
*dev
);
618 int saa7134_oss_fini(struct saa7134_dev
*dev
);
619 void saa7134_irq_oss_done(struct saa7134_dev
*dev
, unsigned long status
);
621 /* ----------------------------------------------------------- */
622 /* saa7134-input.c */
624 int saa7134_input_init1(struct saa7134_dev
*dev
);
625 void saa7134_input_fini(struct saa7134_dev
*dev
);
626 void saa7134_input_irq(struct saa7134_dev
*dev
);