saa7134.h 29.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *
 * v4l2 device driver for philips saa7134 based TV cards
 *
 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

22
#define SAA7134_VERSION "0, 2, 17"
L
Linus Torvalds 已提交
23 24 25

#include <linux/pci.h>
#include <linux/i2c.h>
26
#include <linux/videodev2.h>
L
Linus Torvalds 已提交
27 28
#include <linux/kdev_t.h>
#include <linux/input.h>
29 30
#include <linux/notifier.h>
#include <linux/delay.h>
31
#include <linux/mutex.h>
32
#include <linux/pm_qos.h>
L
Linus Torvalds 已提交
33 34 35

#include <asm/io.h>

36
#include <media/v4l2-common.h>
37
#include <media/v4l2-ioctl.h>
38
#include <media/v4l2-device.h>
39
#include <media/v4l2-fh.h>
40
#include <media/v4l2-ctrls.h>
L
Linus Torvalds 已提交
41
#include <media/tuner.h>
42
#include <media/rc-core.h>
43
#include <media/ir-kbd-i2c.h>
44
#include <media/videobuf-dma-sg.h>
45 46
#include <sound/core.h>
#include <sound/pcm.h>
47
#if IS_ENABLED(CONFIG_VIDEO_SAA7134_DVB)
48
#include <media/videobuf-dvb.h>
49
#endif
50
#include "tda8290.h"
L
Linus Torvalds 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

#define UNSET (-1U)

/* ----------------------------------------------------------- */
/* enums                                                       */

enum saa7134_tvaudio_mode {
	TVAUDIO_FM_MONO       = 1,
	TVAUDIO_FM_BG_STEREO  = 2,
	TVAUDIO_FM_SAT_STEREO = 3,
	TVAUDIO_FM_K_STEREO   = 4,
	TVAUDIO_NICAM_AM      = 5,
	TVAUDIO_NICAM_FM      = 6,
};

enum saa7134_audio_in {
	TV    = 1,
	LINE1 = 2,
	LINE2 = 3,
	LINE2_LEFT,
};

enum saa7134_video_out {
	CCIR656 = 1,
};

/* ----------------------------------------------------------- */
/* static data                                                 */

struct saa7134_tvnorm {
	char          *name;
	v4l2_std_id   id;

	/* video decoder */
	unsigned int  sync_control;
	unsigned int  luma_control;
	unsigned int  chroma_ctrl1;
	unsigned int  chroma_gain;
	unsigned int  chroma_ctrl2;
	unsigned int  vgate_misc;

	/* video scaler */
	unsigned int  h_start;
	unsigned int  h_stop;
	unsigned int  video_v_start;
	unsigned int  video_v_stop;
97 98
	unsigned int  vbi_v_start_0;
	unsigned int  vbi_v_stop_0;
L
Linus Torvalds 已提交
99
	unsigned int  src_timing;
100
	unsigned int  vbi_v_start_1;
L
Linus Torvalds 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
};

struct saa7134_tvaudio {
	char         *name;
	v4l2_std_id  std;
	enum         saa7134_tvaudio_mode mode;
	int          carr1;
	int          carr2;
};

struct saa7134_format {
	char           *name;
	unsigned int   fourcc;
	unsigned int   depth;
	unsigned int   pm;
	unsigned int   vshift;   /* vertical downsampling (for planar yuv) */
	unsigned int   hshift;   /* horizontal downsampling (for planar yuv) */
	unsigned int   bswap:1;
	unsigned int   wswap:1;
	unsigned int   yuv:1;
	unsigned int   planar:1;
	unsigned int   uvswap:1;
};

125 126 127 128 129
struct saa7134_card_ir {
	struct rc_dev		*dev;

	char                    name[32];
	char                    phys[32];
130
	unsigned                users;
131 132

	u32			polling;
133 134
	u32			last_gpio;
	u32			mask_keycode, mask_keydown, mask_keyup;
135 136 137 138 139 140 141 142 143

	bool                    running;

	struct timer_list       timer;

	/* IR core raw decoding */
	u32                     raw_decode;
};

L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
/* ----------------------------------------------------------- */
/* card configuration                                          */

#define SAA7134_BOARD_NOAUTO        UNSET
#define SAA7134_BOARD_UNKNOWN           0
#define SAA7134_BOARD_PROTEUS_PRO       1
#define SAA7134_BOARD_FLYVIDEO3000      2
#define SAA7134_BOARD_FLYVIDEO2000      3
#define SAA7134_BOARD_EMPRESS           4
#define SAA7134_BOARD_MONSTERTV         5
#define SAA7134_BOARD_MD9717            6
#define SAA7134_BOARD_TVSTATION_RDS     7
#define SAA7134_BOARD_CINERGY400	8
#define SAA7134_BOARD_MD5044		9
#define SAA7134_BOARD_KWORLD           10
#define SAA7134_BOARD_CINERGY600       11
#define SAA7134_BOARD_MD7134           12
#define SAA7134_BOARD_TYPHOON_90031    13
#define SAA7134_BOARD_ELSA             14
#define SAA7134_BOARD_ELSA_500TV       15
#define SAA7134_BOARD_ASUSTeK_TVFM7134 16
#define SAA7134_BOARD_VA1000POWER      17
#define SAA7134_BOARD_BMK_MPEX_NOTUNER 18
#define SAA7134_BOARD_VIDEOMATE_TV     19
#define SAA7134_BOARD_CRONOS_PLUS      20
#define SAA7134_BOARD_10MOONSTVMASTER  21
#define SAA7134_BOARD_MD2819           22
#define SAA7134_BOARD_BMK_MPEX_TUNER   23
#define SAA7134_BOARD_TVSTATION_DVR    24
#define SAA7134_BOARD_ASUSTEK_TVFM7133	25
#define SAA7134_BOARD_PINNACLE_PCTV_STEREO 26
#define SAA7134_BOARD_MANLI_MTV002     27
#define SAA7134_BOARD_MANLI_MTV001     28
#define SAA7134_BOARD_TG3000TV         29
#define SAA7134_BOARD_ECS_TVP3XP       30
#define SAA7134_BOARD_ECS_TVP3XP_4CB5  31
#define SAA7134_BOARD_AVACSSMARTTV     32
#define SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER 33
#define SAA7134_BOARD_NOVAC_PRIMETV7133 34
#define SAA7134_BOARD_AVERMEDIA_STUDIO_305 35
184
#define SAA7134_BOARD_UPMOST_PURPLE_TV 36
L
Linus Torvalds 已提交
185 186 187 188 189 190 191 192
#define SAA7134_BOARD_ITEMS_MTV005     37
#define SAA7134_BOARD_CINERGY200       38
#define SAA7134_BOARD_FLYTVPLATINUM_MINI 39
#define SAA7134_BOARD_VIDEOMATE_TV_PVR 40
#define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS 41
#define SAA7134_BOARD_SABRENT_SBTTVFM  42
#define SAA7134_BOARD_ZOLID_XPERT_TV7134 43
#define SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE 44
193
#define SAA7134_BOARD_AVERMEDIA_STUDIO_307    45
L
Linus Torvalds 已提交
194 195 196 197 198 199 200
#define SAA7134_BOARD_AVERMEDIA_CARDBUS 46
#define SAA7134_BOARD_CINERGY400_CARDBUS 47
#define SAA7134_BOARD_CINERGY600_MK3   48
#define SAA7134_BOARD_VIDEOMATE_GOLD_PLUS 49
#define SAA7134_BOARD_PINNACLE_300I_DVBT_PAL 50
#define SAA7134_BOARD_PROVIDEO_PV952   51
#define SAA7134_BOARD_AVERMEDIA_305    52
201
#define SAA7134_BOARD_ASUSTeK_TVFM7135 53
L
Linus Torvalds 已提交
202 203
#define SAA7134_BOARD_FLYTVPLATINUM_FM 54
#define SAA7134_BOARD_FLYDVBTDUO 55
204 205 206 207
#define SAA7134_BOARD_AVERMEDIA_307    56
#define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57
#define SAA7134_BOARD_ADS_INSTANT_TV 58
#define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59
208
#define SAA7134_BOARD_FLYDVBT_DUO_CARDBUS 60
209 210 211
#define SAA7134_BOARD_PHILIPS_TOUGH 61
#define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII 62
#define SAA7134_BOARD_KWORLD_XPERT 63
212
#define SAA7134_BOARD_FLYTV_DIGIMATRIX 64
213
#define SAA7134_BOARD_KWORLD_TERMINATOR 65
214
#define SAA7134_BOARD_YUAN_TUN900 66
215
#define SAA7134_BOARD_BEHOLD_409FM 67
216
#define SAA7134_BOARD_GOTVIEW_7135 68
217 218 219
#define SAA7134_BOARD_PHILIPS_EUROPA  69
#define SAA7134_BOARD_VIDEOMATE_DVBT_300 70
#define SAA7134_BOARD_VIDEOMATE_DVBT_200 71
220 221
#define SAA7134_BOARD_RTD_VFG7350 72
#define SAA7134_BOARD_RTD_VFG7330 73
222
#define SAA7134_BOARD_FLYTVPLATINUM_MINI2 74
223
#define SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180 75
224
#define SAA7134_BOARD_MONSTERTV_MOBILE 76
225
#define SAA7134_BOARD_PINNACLE_PCTV_110i 77
226
#define SAA7134_BOARD_ASUSTeK_P7131_DUAL 78
227
#define SAA7134_BOARD_SEDNA_PC_TV_CARDBUS     79
228
#define SAA7134_BOARD_ASUSTEK_DIGIMATRIX_TV 80
229
#define SAA7134_BOARD_PHILIPS_TIGER  81
230
#define SAA7134_BOARD_MSI_TVATANYWHERE_PLUS  82
231
#define SAA7134_BOARD_CINERGY250PCI 83
232
#define SAA7134_BOARD_FLYDVB_TRIO 84
233
#define SAA7134_BOARD_AVERMEDIA_777 85
234
#define SAA7134_BOARD_FLYDVBT_LR301 86
235
#define SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331 87
236
#define SAA7134_BOARD_TEVION_DVBT_220RF 88
237
#define SAA7134_BOARD_ELSA_700TV       89
238
#define SAA7134_BOARD_KWORLD_ATSC110   90
239 240
#define SAA7134_BOARD_AVERMEDIA_A169_B 91
#define SAA7134_BOARD_AVERMEDIA_A169_B1 92
241
#define SAA7134_BOARD_MD7134_BRIDGE_2     93
242
#define SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS 94
243
#define SAA7134_BOARD_FLYVIDEO3000_NTSC 95
244
#define SAA7134_BOARD_MEDION_MD8800_QUADRO 96
245
#define SAA7134_BOARD_FLYDVBS_LR300 97
246
#define SAA7134_BOARD_PROTEUS_2309 98
247
#define SAA7134_BOARD_AVERMEDIA_A16AR   99
248
#define SAA7134_BOARD_ASUS_EUROPA2_HYBRID 100
249
#define SAA7134_BOARD_PINNACLE_PCTV_310i  101
250
#define SAA7134_BOARD_AVERMEDIA_STUDIO_507 102
251
#define SAA7134_BOARD_VIDEOMATE_DVBT_200A  103
252 253
#define SAA7134_BOARD_HAUPPAUGE_HVR1110    104
#define SAA7134_BOARD_CINERGY_HT_PCMCIA    105
254
#define SAA7134_BOARD_ENCORE_ENLTV         106
255
#define SAA7134_BOARD_ENCORE_ENLTV_FM      107
256
#define SAA7134_BOARD_CINERGY_HT_PCI       108
257
#define SAA7134_BOARD_PHILIPS_TIGER_S      109
258
#define SAA7134_BOARD_AVERMEDIA_M102	   110
259
#define SAA7134_BOARD_ASUS_P7131_4871	   111
260
#define SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA 112
261 262
#define SAA7134_BOARD_ECS_TVP3XP_4CB6  113
#define SAA7134_BOARD_KWORLD_DVBT_210 114
263
#define SAA7134_BOARD_SABRENT_TV_PCB05     115
264
#define SAA7134_BOARD_10MOONSTVMASTER3     116
265
#define SAA7134_BOARD_AVERMEDIA_SUPER_007  117
266 267 268 269 270 271 272 273 274 275 276
#define SAA7134_BOARD_BEHOLD_401  	118
#define SAA7134_BOARD_BEHOLD_403  	119
#define SAA7134_BOARD_BEHOLD_403FM	120
#define SAA7134_BOARD_BEHOLD_405	121
#define SAA7134_BOARD_BEHOLD_405FM	122
#define SAA7134_BOARD_BEHOLD_407	123
#define SAA7134_BOARD_BEHOLD_407FM	124
#define SAA7134_BOARD_BEHOLD_409	125
#define SAA7134_BOARD_BEHOLD_505FM	126
#define SAA7134_BOARD_BEHOLD_507_9FM	127
#define SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM 128
277
#define SAA7134_BOARD_BEHOLD_607FM_MK3	129
278
#define SAA7134_BOARD_BEHOLD_M6		130
279
#define SAA7134_BOARD_TWINHAN_DTV_DVB_3056 131
280 281
#define SAA7134_BOARD_GENIUS_TVGO_A11MCE   132
#define SAA7134_BOARD_PHILIPS_SNAKE        133
282
#define SAA7134_BOARD_CREATIX_CTX953       134
283
#define SAA7134_BOARD_MSI_TVANYWHERE_AD11  135
284 285 286 287
#define SAA7134_BOARD_AVERMEDIA_CARDBUS_506 136
#define SAA7134_BOARD_AVERMEDIA_A16D       137
#define SAA7134_BOARD_AVERMEDIA_M115       138
#define SAA7134_BOARD_VIDEOMATE_T750       139
288 289
#define SAA7134_BOARD_AVERMEDIA_A700_PRO    140
#define SAA7134_BOARD_AVERMEDIA_A700_HYBRID 141
290
#define SAA7134_BOARD_BEHOLD_H6      142
291 292
#define SAA7134_BOARD_BEHOLD_M63      143
#define SAA7134_BOARD_BEHOLD_M6_EXTRA    144
293
#define SAA7134_BOARD_AVERMEDIA_M103    145
294
#define SAA7134_BOARD_ASUSTeK_P7131_ANALOG 146
295
#define SAA7134_BOARD_ASUSTeK_TIGER_3IN1   147
296
#define SAA7134_BOARD_ENCORE_ENLTV_FM53 148
297
#define SAA7134_BOARD_AVERMEDIA_M135A    149
298 299
#define SAA7134_BOARD_REAL_ANGEL_220     150
#define SAA7134_BOARD_ADS_INSTANT_HDTV_PCI  151
300
#define SAA7134_BOARD_ASUSTeK_TIGER         152
301
#define SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG 153
302
#define SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS 154
303
#define SAA7134_BOARD_HAUPPAUGE_HVR1150     155
304
#define SAA7134_BOARD_HAUPPAUGE_HVR1120   156
305
#define SAA7134_BOARD_AVERMEDIA_STUDIO_507UA 157
306
#define SAA7134_BOARD_AVERMEDIA_CARDBUS_501 158
307
#define SAA7134_BOARD_BEHOLD_505RDS_MK5     159
308 309 310 311 312 313 314 315 316
#define SAA7134_BOARD_BEHOLD_507RDS_MK3     160
#define SAA7134_BOARD_BEHOLD_507RDS_MK5     161
#define SAA7134_BOARD_BEHOLD_607FM_MK5      162
#define SAA7134_BOARD_BEHOLD_609FM_MK3      163
#define SAA7134_BOARD_BEHOLD_609FM_MK5      164
#define SAA7134_BOARD_BEHOLD_607RDS_MK3     165
#define SAA7134_BOARD_BEHOLD_607RDS_MK5     166
#define SAA7134_BOARD_BEHOLD_609RDS_MK3     167
#define SAA7134_BOARD_BEHOLD_609RDS_MK5     168
317
#define SAA7134_BOARD_VIDEOMATE_S350        169
318
#define SAA7134_BOARD_AVERMEDIA_STUDIO_505  170
319
#define SAA7134_BOARD_BEHOLD_X7             171
320
#define SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM 172
321
#define SAA7134_BOARD_ZOLID_HYBRID_PCI		173
322
#define SAA7134_BOARD_ASUS_EUROPA_HYBRID	174
323
#define SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S 175
324
#define SAA7134_BOARD_BEHOLD_505RDS_MK3     176
325
#define SAA7134_BOARD_HAWELL_HW_404M7		177
326 327
#define SAA7134_BOARD_BEHOLD_H7             178
#define SAA7134_BOARD_BEHOLD_A7             179
328
#define SAA7134_BOARD_AVERMEDIA_M733A       180
329
#define SAA7134_BOARD_TECHNOTREND_BUDGET_T3000 181
330
#define SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG 182
331
#define SAA7134_BOARD_VIDEOMATE_M1F         183
332
#define SAA7134_BOARD_ENCORE_ENLTV_FM3      184
333
#define SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2 185
334 335
#define SAA7134_BOARD_BEHOLD_501            186
#define SAA7134_BOARD_BEHOLD_503FM          187
336
#define SAA7134_BOARD_SENSORAY811_911       188
337
#define SAA7134_BOARD_KWORLD_PC150U         189
338
#define SAA7134_BOARD_ASUSTeK_PS3_100      190
339
#define SAA7134_BOARD_HAWELL_HW_9004V1      191
340
#define SAA7134_BOARD_AVERMEDIA_A706		192
L
Linus Torvalds 已提交
341

342
#define SAA7134_MAXBOARDS 32
L
Linus Torvalds 已提交
343 344
#define SAA7134_INPUT_MAX 8

345 346 347 348 349 350
/* ----------------------------------------------------------- */
/* Since we support 2 remote types, lets tell them apart       */

#define SAA7134_REMOTE_GPIO  1
#define SAA7134_REMOTE_I2C   2

351 352 353 354 355 356 357 358
/* ----------------------------------------------------------- */
/* Video Output Port Register Initialization Options           */

#define SET_T_CODE_POLARITY_NON_INVERTED	(1 << 0)
#define SET_CLOCK_NOT_DELAYED			(1 << 1)
#define SET_CLOCK_INVERTED			(1 << 2)
#define SET_VSYNC_OFF				(1 << 3)

L
Linus Torvalds 已提交
359 360 361 362 363 364 365 366 367 368 369 370 371 372
struct saa7134_input {
	char                    *name;
	unsigned int            vmux;
	enum saa7134_audio_in   amux;
	unsigned int            gpio;
	unsigned int            tv:1;
};

enum saa7134_mpeg_type {
	SAA7134_MPEG_UNUSED,
	SAA7134_MPEG_EMPRESS,
	SAA7134_MPEG_DVB,
};

373 374 375 376 377
enum saa7134_mpeg_ts_type {
	SAA7134_MPEG_TS_PARALLEL = 0,
	SAA7134_MPEG_TS_SERIAL,
};

L
Linus Torvalds 已提交
378 379 380 381 382 383 384 385 386 387 388 389
struct saa7134_board {
	char                    *name;
	unsigned int            audio_clock;

	/* input switching */
	unsigned int            gpiomask;
	struct saa7134_input    inputs[SAA7134_INPUT_MAX];
	struct saa7134_input    radio;
	struct saa7134_input    mute;

	/* i2c chip info */
	unsigned int            tuner_type;
390 391 392
	unsigned int		radio_type;
	unsigned char		tuner_addr;
	unsigned char		radio_addr;
393
	unsigned char		empress_addr;
394
	unsigned char		rds_addr;
395

L
Linus Torvalds 已提交
396
	unsigned int            tda9887_conf;
397
	struct tda829x_config   tda829x_conf;
L
Linus Torvalds 已提交
398 399 400 401

	/* peripheral I/O */
	enum saa7134_video_out  video_out;
	enum saa7134_mpeg_type  mpeg;
402
	enum saa7134_mpeg_ts_type ts_type;
403
	unsigned int            vid_port_opts;
404
	unsigned int            ts_force_val:1;
L
Linus Torvalds 已提交
405 406 407 408 409 410 411 412 413
};

#define card_has_radio(dev)   (NULL != saa7134_boards[dev->board].radio.name)
#define card_is_empress(dev)  (SAA7134_MPEG_EMPRESS == saa7134_boards[dev->board].mpeg)
#define card_is_dvb(dev)      (SAA7134_MPEG_DVB     == saa7134_boards[dev->board].mpeg)
#define card_has_mpeg(dev)    (SAA7134_MPEG_UNUSED  != saa7134_boards[dev->board].mpeg)
#define card(dev)             (saa7134_boards[dev->board])
#define card_in(dev,n)        (saa7134_boards[dev->board].inputs[n])

414 415 416 417 418
#define V4L2_CID_PRIVATE_INVERT      (V4L2_CID_USER_SAA7134_BASE + 0)
#define V4L2_CID_PRIVATE_Y_ODD       (V4L2_CID_USER_SAA7134_BASE + 1)
#define V4L2_CID_PRIVATE_Y_EVEN      (V4L2_CID_USER_SAA7134_BASE + 2)
#define V4L2_CID_PRIVATE_AUTOMUTE    (V4L2_CID_USER_SAA7134_BASE + 3)

L
Linus Torvalds 已提交
419 420 421 422 423 424 425 426 427 428 429
/* ----------------------------------------------------------- */
/* device / file handle status                                 */

#define RESOURCE_OVERLAY       1
#define RESOURCE_VIDEO         2
#define RESOURCE_VBI           4

#define INTERLACE_AUTO         0
#define INTERLACE_ON           1
#define INTERLACE_OFF          2

430
#define BUFFER_TIMEOUT     msecs_to_jiffies(500)  /* 0.5 seconds */
431
#define TS_BUFFER_TIMEOUT  msecs_to_jiffies(1000)  /* 1 second */
L
Linus Torvalds 已提交
432 433 434 435 436 437 438

struct saa7134_dev;
struct saa7134_dma;

/* saa7134 page table */
struct saa7134_pgtable {
	unsigned int               size;
439
	__le32                     *cpu;
L
Linus Torvalds 已提交
440 441 442 443 444
	dma_addr_t                 dma;
};

/* tvaudio thread status */
struct saa7134_thread {
445
	struct task_struct         *thread;
L
Linus Torvalds 已提交
446 447 448
	unsigned int               scan1;
	unsigned int               scan2;
	unsigned int               mode;
449
	unsigned int		   stopped;
L
Linus Torvalds 已提交
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
};

/* buffer for one video/vbi/ts frame */
struct saa7134_buf {
	/* common v4l buffer stuff -- must be first */
	struct videobuf_buffer vb;

	/* saa7134 specific */
	struct saa7134_format   *fmt;
	unsigned int            top_seen;
	int (*activate)(struct saa7134_dev *dev,
			struct saa7134_buf *buf,
			struct saa7134_buf *next);

	/* page tables */
	struct saa7134_pgtable  *pt;
};

struct saa7134_dmaqueue {
	struct saa7134_dev         *dev;
	struct saa7134_buf         *curr;
	struct list_head           queue;
	struct timer_list          timeout;
	unsigned int               need_two;
};

/* video filehandle status */
struct saa7134_fh {
478
	struct v4l2_fh             fh;
L
Linus Torvalds 已提交
479 480 481 482
	struct saa7134_dev         *dev;
	unsigned int               resources;
};

483 484
/* dmasound dsp status */
struct saa7134_dmasound {
485
	struct mutex               lock;
L
Linus Torvalds 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
	int                        minor_mixer;
	int                        minor_dsp;
	unsigned int               users_dsp;

	/* mixer */
	enum saa7134_audio_in      input;
	unsigned int               count;
	unsigned int               line1;
	unsigned int               line2;

	/* dsp */
	unsigned int               afmt;
	unsigned int               rate;
	unsigned int               channels;
	unsigned int               recording_on;
	unsigned int               dma_running;
	unsigned int               blocks;
	unsigned int               blksize;
	unsigned int               bufsize;
	struct saa7134_pgtable     pt;
	struct videobuf_dmabuf     dma;
	unsigned int               dma_blk;
	unsigned int               read_offset;
	unsigned int               read_count;
510
	void *			   priv_data;
T
Takashi Iwai 已提交
511
	struct snd_pcm_substream   *substream;
L
Linus Torvalds 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
};

/* ts/mpeg status */
struct saa7134_ts {
	/* TS capture */
	struct saa7134_pgtable     pt_ts;
	int                        nr_packets;
	int                        nr_bufs;
};

/* ts/mpeg ops */
struct saa7134_mpeg_ops {
	enum saa7134_mpeg_type     type;
	struct list_head           next;
	int                        (*init)(struct saa7134_dev *dev);
	int                        (*fini)(struct saa7134_dev *dev);
	void                       (*signal_change)(struct saa7134_dev *dev);
};

/* global device status */
struct saa7134_dev {
	struct list_head           devlist;
534
	struct mutex               lock;
535
	spinlock_t                 slock;
536
	struct v4l2_device         v4l2_dev;
537 538
	/* workstruct for loading modules */
	struct work_struct request_module_wk;
L
Linus Torvalds 已提交
539

540 541 542
	/* insmod option/autodetected */
	int                        autodetected;

L
Linus Torvalds 已提交
543 544 545 546 547
	/* various device info */
	unsigned int               resources;
	struct video_device        *video_dev;
	struct video_device        *radio_dev;
	struct video_device        *vbi_dev;
548
	struct saa7134_dmasound    dmasound;
L
Linus Torvalds 已提交
549 550 551

	/* infrared remote */
	int                        has_remote;
552
	struct saa7134_card_ir     *remote;
L
Linus Torvalds 已提交
553 554 555 556 557 558 559 560 561 562 563 564

	/* pci i/o */
	char                       name[32];
	int                        nr;
	struct pci_dev             *pci;
	unsigned char              pci_rev,pci_lat;
	__u32                      __iomem *lmmio;
	__u8                       __iomem *bmmio;

	/* config info */
	unsigned int               board;
	unsigned int               tuner_type;
565 566 567 568
	unsigned int 		   radio_type;
	unsigned char		   tuner_addr;
	unsigned char		   radio_addr;

L
Linus Torvalds 已提交
569 570 571 572 573 574
	unsigned int               tda9887_conf;
	unsigned int               gpio_value;

	/* i2c i/o */
	struct i2c_adapter         i2c_adap;
	struct i2c_client          i2c_client;
575
	unsigned char              eedata[256];
576
	int 			   has_rds;
L
Linus Torvalds 已提交
577 578 579 580 581 582

	/* video overlay */
	struct v4l2_framebuffer    ovbuf;
	struct saa7134_format      *ovfmt;
	unsigned int               ovenable;
	enum v4l2_field            ovfield;
583 584 585 586
	struct v4l2_window         win;
	struct v4l2_clip           clips[8];
	unsigned int               nclips;

L
Linus Torvalds 已提交
587 588 589

	/* video+ts+vbi capture */
	struct saa7134_dmaqueue    video_q;
590 591
	struct videobuf_queue      cap;
	struct saa7134_pgtable     pt_cap;
L
Linus Torvalds 已提交
592
	struct saa7134_dmaqueue    vbi_q;
593 594
	struct videobuf_queue      vbi;
	struct saa7134_pgtable     pt_vbi;
L
Linus Torvalds 已提交
595 596
	unsigned int               video_fieldcount;
	unsigned int               vbi_fieldcount;
597 598
	struct saa7134_format      *fmt;
	unsigned int               width, height;
599
	struct pm_qos_request	   qos_request;
L
Linus Torvalds 已提交
600 601 602 603

	/* various v4l controls */
	struct saa7134_tvnorm      *tvnorm;              /* video */
	struct saa7134_tvaudio     *tvaudio;
604
	struct v4l2_ctrl_handler   ctrl_handler;
L
Linus Torvalds 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
	unsigned int               ctl_input;
	int                        ctl_bright;
	int                        ctl_contrast;
	int                        ctl_hue;
	int                        ctl_saturation;
	int                        ctl_mute;             /* audio */
	int                        ctl_volume;
	int                        ctl_invert;           /* private */
	int                        ctl_mirror;
	int                        ctl_y_odd;
	int                        ctl_y_even;
	int                        ctl_automute;

	/* crop */
	struct v4l2_rect           crop_bounds;
	struct v4l2_rect           crop_defrect;
	struct v4l2_rect           crop_current;

	/* other global state info */
	unsigned int               automute;
	struct saa7134_thread      thread;
	struct saa7134_input       *input;
	struct saa7134_input       *hw_input;
	unsigned int               hw_mute;
	int                        last_carrier;
	int                        nosignal;
631
	unsigned int               insuspend;
632
	struct v4l2_ctrl_handler   radio_ctrl_handler;
L
Linus Torvalds 已提交
633

634 635 636
	/* I2C keyboard data */
	struct IR_i2c_init_data    init_data;

L
Linus Torvalds 已提交
637 638 639
	/* SAA7134_MPEG_* */
	struct saa7134_ts          ts;
	struct saa7134_dmaqueue    ts_q;
640
	int                        ts_started;
L
Linus Torvalds 已提交
641 642 643 644
	struct saa7134_mpeg_ops    *mops;

	/* SAA7134_MPEG_EMPRESS only */
	struct video_device        *empress_dev;
645
	struct v4l2_subdev	   *empress_sd;
L
Linus Torvalds 已提交
646
	struct videobuf_queue      empress_tsq;
647
	atomic_t 		   empress_users;
L
Linus Torvalds 已提交
648 649
	struct work_struct         empress_workqueue;
	int                        empress_started;
650
	struct v4l2_ctrl_handler   empress_ctrl_handler;
L
Linus Torvalds 已提交
651

652
#if IS_ENABLED(CONFIG_VIDEO_SAA7134_DVB)
L
Linus Torvalds 已提交
653
	/* SAA7134_MPEG_DVB only */
654
	struct videobuf_dvb_frontends frontends;
655 656 657
	int (*original_demod_sleep)(struct dvb_frontend *fe);
	int (*original_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
	int (*original_set_high_voltage)(struct dvb_frontend *fe, long arg);
658
#endif
659
	void (*gate_ctrl)(struct saa7134_dev *dev, int open);
L
Linus Torvalds 已提交
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
};

/* ----------------------------------------------------------- */

#define saa_readl(reg)             readl(dev->lmmio + (reg))
#define saa_writel(reg,value)      writel((value), dev->lmmio + (reg));
#define saa_andorl(reg,mask,value) \
  writel((readl(dev->lmmio+(reg)) & ~(mask)) |\
  ((value) & (mask)), dev->lmmio+(reg))
#define saa_setl(reg,bit)          saa_andorl((reg),(bit),(bit))
#define saa_clearl(reg,bit)        saa_andorl((reg),(bit),0)

#define saa_readb(reg)             readb(dev->bmmio + (reg))
#define saa_writeb(reg,value)      writeb((value), dev->bmmio + (reg));
#define saa_andorb(reg,mask,value) \
  writeb((readb(dev->bmmio+(reg)) & ~(mask)) |\
  ((value) & (mask)), dev->bmmio+(reg))
#define saa_setb(reg,bit)          saa_andorb((reg),(bit),(bit))
#define saa_clearb(reg,bit)        saa_andorb((reg),(bit),0)

#define saa_wait(us) { udelay(us); }

682 683 684 685 686 687
#define SAA7134_NORMS	(\
		V4L2_STD_PAL    | V4L2_STD_PAL_N | \
		V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
		V4L2_STD_NTSC   | V4L2_STD_PAL_M | \
		V4L2_STD_PAL_60)

688
#define GRP_EMPRESS (1)
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
#define saa_call_all(dev, o, f, args...) do {				\
	if (dev->gate_ctrl)						\
		dev->gate_ctrl(dev, 1);					\
	v4l2_device_call_all(&(dev)->v4l2_dev, 0, o, f , ##args);	\
	if (dev->gate_ctrl)						\
		dev->gate_ctrl(dev, 0);					\
} while (0)

#define saa_call_empress(dev, o, f, args...) ({				\
	long _rc;							\
	if (dev->gate_ctrl)						\
		dev->gate_ctrl(dev, 1);					\
	_rc = v4l2_device_call_until_err(&(dev)->v4l2_dev,		\
					 GRP_EMPRESS, o, f , ##args);	\
	if (dev->gate_ctrl)						\
		dev->gate_ctrl(dev, 0);					\
	_rc;								\
})
707

L
Linus Torvalds 已提交
708 709 710 711
/* ----------------------------------------------------------- */
/* saa7134-core.c                                              */

extern struct list_head  saa7134_devlist;
712
extern struct mutex saa7134_devlist_lock;
713
extern int saa7134_no_overlay;
L
Linus Torvalds 已提交
714 715

void saa7134_track_gpio(struct saa7134_dev *dev, char *msg);
716
void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value);
L
Linus Torvalds 已提交
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735

#define SAA7134_PGTABLE_SIZE 4096

int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt);
int  saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt,
			   struct scatterlist *list, unsigned int length,
			   unsigned int startpage);
void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt);

int saa7134_buffer_count(unsigned int size, unsigned int count);
int saa7134_buffer_startpage(struct saa7134_buf *buf);
unsigned long saa7134_buffer_base(struct saa7134_buf *buf);

int saa7134_buffer_queue(struct saa7134_dev *dev, struct saa7134_dmaqueue *q,
			 struct saa7134_buf *buf);
void saa7134_buffer_finish(struct saa7134_dev *dev, struct saa7134_dmaqueue *q,
			   unsigned int state);
void saa7134_buffer_next(struct saa7134_dev *dev, struct saa7134_dmaqueue *q);
void saa7134_buffer_timeout(unsigned long data);
736
void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf);
L
Linus Torvalds 已提交
737 738 739

int saa7134_set_dmabits(struct saa7134_dev *dev);

740 741
extern int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
extern int (*saa7134_dmasound_exit)(struct saa7134_dev *dev);
742 743


L
Linus Torvalds 已提交
744 745 746 747 748
/* ----------------------------------------------------------- */
/* saa7134-cards.c                                             */

extern struct saa7134_board saa7134_boards[];
extern const unsigned int saa7134_bcount;
749
extern struct pci_device_id saa7134_pci_tbl[];
L
Linus Torvalds 已提交
750 751 752

extern int saa7134_board_init1(struct saa7134_dev *dev);
extern int saa7134_board_init2(struct saa7134_dev *dev);
753
int saa7134_tuner_callback(void *priv, int component, int command, int arg);
L
Linus Torvalds 已提交
754 755 756 757 758 759 760 761 762 763 764 765


/* ----------------------------------------------------------- */
/* saa7134-i2c.c                                               */

int saa7134_i2c_register(struct saa7134_dev *dev);
int saa7134_i2c_unregister(struct saa7134_dev *dev);


/* ----------------------------------------------------------- */
/* saa7134-video.c                                             */

766
extern unsigned int video_debug;
L
Linus Torvalds 已提交
767 768 769
extern struct video_device saa7134_video_template;
extern struct video_device saa7134_radio_template;

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
int saa7134_s_std(struct file *file, void *priv, v4l2_std_id id);
int saa7134_g_std(struct file *file, void *priv, v4l2_std_id *id);
int saa7134_enum_input(struct file *file, void *priv, struct v4l2_input *i);
int saa7134_g_input(struct file *file, void *priv, unsigned int *i);
int saa7134_s_input(struct file *file, void *priv, unsigned int i);
int saa7134_querycap(struct file *file, void  *priv,
					struct v4l2_capability *cap);
int saa7134_g_tuner(struct file *file, void *priv,
					struct v4l2_tuner *t);
int saa7134_s_tuner(struct file *file, void *priv,
					const struct v4l2_tuner *t);
int saa7134_g_frequency(struct file *file, void *priv,
					struct v4l2_frequency *f);
int saa7134_s_frequency(struct file *file, void *priv,
					const struct v4l2_frequency *f);
785

786
int saa7134_videoport_init(struct saa7134_dev *dev);
787
void saa7134_set_tvnorm_hw(struct saa7134_dev *dev);
788

L
Linus Torvalds 已提交
789 790
int saa7134_video_init1(struct saa7134_dev *dev);
int saa7134_video_init2(struct saa7134_dev *dev);
791
void saa7134_irq_video_signalchange(struct saa7134_dev *dev);
L
Linus Torvalds 已提交
792
void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status);
793
void saa7134_video_fini(struct saa7134_dev *dev);
L
Linus Torvalds 已提交
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809


/* ----------------------------------------------------------- */
/* saa7134-ts.c                                                */

#define TS_PACKET_SIZE 188 /* TS packets 188 bytes */

extern struct videobuf_queue_ops saa7134_ts_qops;

int saa7134_ts_init1(struct saa7134_dev *dev);
int saa7134_ts_fini(struct saa7134_dev *dev);
void saa7134_irq_ts_done(struct saa7134_dev *dev, unsigned long status);

int saa7134_ts_register(struct saa7134_mpeg_ops *ops);
void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops);

810 811
int saa7134_ts_init_hw(struct saa7134_dev *dev);

812 813 814
int saa7134_ts_start(struct saa7134_dev *dev);
int saa7134_ts_stop(struct saa7134_dev *dev);

L
Linus Torvalds 已提交
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
/* ----------------------------------------------------------- */
/* saa7134-vbi.c                                               */

extern struct videobuf_queue_ops saa7134_vbi_qops;
extern struct video_device saa7134_vbi_template;

int saa7134_vbi_init1(struct saa7134_dev *dev);
int saa7134_vbi_fini(struct saa7134_dev *dev);
void saa7134_irq_vbi_done(struct saa7134_dev *dev, unsigned long status);


/* ----------------------------------------------------------- */
/* saa7134-tvaudio.c                                           */

int saa7134_tvaudio_rx2mode(u32 rx);

void saa7134_tvaudio_setmute(struct saa7134_dev *dev);
void saa7134_tvaudio_setinput(struct saa7134_dev *dev,
			      struct saa7134_input *in);
void saa7134_tvaudio_setvolume(struct saa7134_dev *dev, int level);
int saa7134_tvaudio_getstereo(struct saa7134_dev *dev);

837
void saa7134_tvaudio_init(struct saa7134_dev *dev);
L
Linus Torvalds 已提交
838 839 840
int saa7134_tvaudio_init2(struct saa7134_dev *dev);
int saa7134_tvaudio_fini(struct saa7134_dev *dev);
int saa7134_tvaudio_do_scan(struct saa7134_dev *dev);
841
int saa7134_tvaudio_close(struct saa7134_dev *dev);
L
Linus Torvalds 已提交
842 843 844

int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value);

845 846
void saa7134_enable_i2s(struct saa7134_dev *dev);

L
Linus Torvalds 已提交
847 848 849
/* ----------------------------------------------------------- */
/* saa7134-oss.c                                               */

850 851
extern const struct file_operations saa7134_dsp_fops;
extern const struct file_operations saa7134_mixer_fops;
L
Linus Torvalds 已提交
852 853 854 855 856 857 858 859

int saa7134_oss_init1(struct saa7134_dev *dev);
int saa7134_oss_fini(struct saa7134_dev *dev);
void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status);

/* ----------------------------------------------------------- */
/* saa7134-input.c                                             */

860
#if defined(CONFIG_VIDEO_SAA7134_RC)
L
Linus Torvalds 已提交
861 862 863
int  saa7134_input_init1(struct saa7134_dev *dev);
void saa7134_input_fini(struct saa7134_dev *dev);
void saa7134_input_irq(struct saa7134_dev *dev);
864
void saa7134_probe_i2c_ir(struct saa7134_dev *dev);
865
int saa7134_ir_start(struct saa7134_dev *dev);
866
void saa7134_ir_stop(struct saa7134_dev *dev);
867
#else
868 869 870 871 872 873
#define saa7134_input_init1(dev)	((void)0)
#define saa7134_input_fini(dev)		((void)0)
#define saa7134_input_irq(dev)		((void)0)
#define saa7134_probe_i2c_ir(dev)	((void)0)
#define saa7134_ir_start(dev)		((void)0)
#define saa7134_ir_stop(dev)		((void)0)
874
#endif