cx88.h 22.6 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 22 23 24
/*
 *
 * v4l2 device driver for cx2388x based TV cards
 *
 * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
 *
 *  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.
 */

#include <linux/pci.h>
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>
25
#include <linux/videodev2.h>
L
Linus Torvalds 已提交
26 27
#include <linux/kdev_t.h>

28
#include <media/v4l2-device.h>
29
#include <media/v4l2-fh.h>
L
Linus Torvalds 已提交
30 31
#include <media/tuner.h>
#include <media/tveeprom.h>
H
Hans Verkuil 已提交
32
#include <media/videobuf2-dma-sg.h>
33
#include <media/cx2341x.h>
H
Hans Verkuil 已提交
34
#include <media/videobuf2-dvb.h>
35
#include <media/ir-kbd-i2c.h>
36
#include <media/wm8775.h>
L
Linus Torvalds 已提交
37 38

#include "cx88-reg.h"
39
#include "tuner-xc2028.h"
L
Linus Torvalds 已提交
40

41
#include <linux/mutex.h>
42

H
Hans Verkuil 已提交
43
#define CX88_VERSION "1.0.0"
L
Linus Torvalds 已提交
44 45 46 47 48

#define UNSET (-1U)

#define CX88_MAXBOARDS 8

49 50 51
/* Max number of inputs by card */
#define MAX_CX88_INPUT 8

L
Linus Torvalds 已提交
52 53 54
/* ----------------------------------------------------------- */
/* defines and enums                                           */

55 56 57 58 59
/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM/LC */
#define CX88_NORMS (V4L2_STD_ALL 		\
		    & ~V4L2_STD_PAL_H		\
		    & ~V4L2_STD_NTSC_M_KR	\
		    & ~V4L2_STD_SECAM_LC)
60

L
Linus Torvalds 已提交
61 62 63 64 65 66
#define FORMAT_FLAGS_PACKED       0x01
#define FORMAT_FLAGS_PLANAR       0x02

#define VBI_LINE_COUNT              17
#define VBI_LINE_LENGTH           2048

67 68
#define AUD_RDS_LINES		     4

L
Linus Torvalds 已提交
69 70 71
/* need "shadow" registers for some write-only ones ... */
#define SHADOW_AUD_VOL_CTL           1
#define SHADOW_AUD_BAL_CTL           2
72
#define SHADOW_MAX                   3
L
Linus Torvalds 已提交
73

74 75 76 77 78 79 80
/* FM Radio deemphasis type */
enum cx88_deemph_type {
	FM_NO_DEEMPH = 0,
	FM_DEEMPH_50,
	FM_DEEMPH_75
};

81 82
enum cx88_board_type {
	CX88_BOARD_NONE = 0,
83 84
	CX88_MPEG_DVB,
	CX88_MPEG_BLACKBIRD
85 86
};

87 88 89 90 91
enum cx8802_board_access {
	CX8802_DRVCTL_SHARED    = 1,
	CX8802_DRVCTL_EXCLUSIVE = 2,
};

L
Linus Torvalds 已提交
92 93 94
/* ----------------------------------------------------------- */
/* tv norms                                                    */

95
static inline unsigned int norm_maxw(v4l2_std_id norm)
L
Linus Torvalds 已提交
96
{
H
Hans Verkuil 已提交
97
	return 720;
L
Linus Torvalds 已提交
98 99
}

M
Mauro Carvalho Chehab 已提交
100

101
static inline unsigned int norm_maxh(v4l2_std_id norm)
L
Linus Torvalds 已提交
102
{
H
Hans Verkuil 已提交
103
	return (norm & V4L2_STD_525_60) ? 480 : 576;
L
Linus Torvalds 已提交
104 105 106 107 108 109
}

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

struct cx8800_fmt {
110
	const char  *name;
L
Linus Torvalds 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
	u32   fourcc;          /* v4l2 format id */
	int   depth;
	int   flags;
	u32   cxformat;
};

/* ----------------------------------------------------------- */
/* SRAM memory management data (see cx88-core.c)               */

#define SRAM_CH21 0   /* video */
#define SRAM_CH22 1
#define SRAM_CH23 2
#define SRAM_CH24 3   /* vbi   */
#define SRAM_CH25 4   /* audio */
#define SRAM_CH26 5
#define SRAM_CH28 6   /* mpeg */
127
#define SRAM_CH27 7   /* audio rds */
L
Linus Torvalds 已提交
128 129 130
/* more */

struct sram_channel {
131
	const char *name;
L
Linus Torvalds 已提交
132 133 134 135 136 137 138 139 140 141
	u32  cmds_start;
	u32  ctrl_start;
	u32  cdt;
	u32  fifo_start;
	u32  fifo_size;
	u32  ptr1_reg;
	u32  ptr2_reg;
	u32  cnt1_reg;
	u32  cnt2_reg;
};
142
extern const struct sram_channel cx88_sram_channels[];
L
Linus Torvalds 已提交
143 144 145 146 147 148 149 150 151 152 153

/* ----------------------------------------------------------- */
/* card configuration                                          */

#define CX88_BOARD_NOAUTO               UNSET
#define CX88_BOARD_UNKNOWN                  0
#define CX88_BOARD_HAUPPAUGE                1
#define CX88_BOARD_GDI                      2
#define CX88_BOARD_PIXELVIEW                3
#define CX88_BOARD_ATI_WONDER_PRO           4
#define CX88_BOARD_WINFAST2000XP_EXPERT     5
154
#define CX88_BOARD_AVERTV_STUDIO_303        6
L
Linus Torvalds 已提交
155 156 157 158 159 160 161 162 163 164
#define CX88_BOARD_MSI_TVANYWHERE_MASTER    7
#define CX88_BOARD_WINFAST_DV2000           8
#define CX88_BOARD_LEADTEK_PVR2000          9
#define CX88_BOARD_IODATA_GVVCP3PCI        10
#define CX88_BOARD_PROLINK_PLAYTVPVR       11
#define CX88_BOARD_ASUS_PVR_416            12
#define CX88_BOARD_MSI_TVANYWHERE          13
#define CX88_BOARD_KWORLD_DVB_T            14
#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1 15
#define CX88_BOARD_KWORLD_LTV883           16
M
Mauro Carvalho Chehab 已提交
165
#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q  17
L
Linus Torvalds 已提交
166 167 168 169 170 171 172
#define CX88_BOARD_HAUPPAUGE_DVB_T1        18
#define CX88_BOARD_CONEXANT_DVB_T1         19
#define CX88_BOARD_PROVIDEO_PV259          20
#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS 21
#define CX88_BOARD_PCHDTV_HD3000           22
#define CX88_BOARD_DNTV_LIVE_DVB_T         23
#define CX88_BOARD_HAUPPAUGE_ROSLYN        24
M
Mauro Carvalho Chehab 已提交
173
#define CX88_BOARD_DIGITALLOGIC_MEC        25
L
Linus Torvalds 已提交
174
#define CX88_BOARD_IODATA_GVBCTV7E         26
175
#define CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO 27
176
#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T  28
M
Mauro Carvalho Chehab 已提交
177
#define CX88_BOARD_ADSTECH_DVB_T_PCI          29
178
#define CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1  30
179
#define CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD 31
180
#define CX88_BOARD_AVERMEDIA_ULTRATV_MC_550 32
181
#define CX88_BOARD_KWORLD_VSTREAM_EXPERT_DVD 33
182
#define CX88_BOARD_ATI_HDTVWONDER          34
183
#define CX88_BOARD_WINFAST_DTV1000         35
184
#define CX88_BOARD_AVERTV_303              36
185 186
#define CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1  37
#define CX88_BOARD_HAUPPAUGE_NOVASE2_S1    38
187
#define CX88_BOARD_KWORLD_DVBS_100         39
188 189
#define CX88_BOARD_HAUPPAUGE_HVR1100       40
#define CX88_BOARD_HAUPPAUGE_HVR1100LP     41
190
#define CX88_BOARD_DNTV_LIVE_DVB_T_PRO     42
191
#define CX88_BOARD_KWORLD_DVB_T_CX22702    43
192
#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL 44
193
#define CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT 45
194
#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID 46
195
#define CX88_BOARD_PCHDTV_HD5500           47
196
#define CX88_BOARD_KWORLD_MCE200_DELUXE    48
197
#define CX88_BOARD_PIXELVIEW_PLAYTV_P7000  49
198
#define CX88_BOARD_NPGTECH_REALTV_TOP10FM  50
199
#define CX88_BOARD_WINFAST_DTV2000H        51
200
#define CX88_BOARD_GENIATECH_DVBS          52
201
#define CX88_BOARD_HAUPPAUGE_HVR3000       53
202
#define CX88_BOARD_NORWOOD_MICRO           54
203
#define CX88_BOARD_TE_DTV_250_OEM_SWANN    55
204
#define CX88_BOARD_HAUPPAUGE_HVR1300       56
205
#define CX88_BOARD_ADSTECH_PTV_390         57
206
#define CX88_BOARD_PINNACLE_PCTV_HD_800i   58
207
#define CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO 59
208 209 210 211
#define CX88_BOARD_PINNACLE_HYBRID_PCTV    60
#define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL 61
#define CX88_BOARD_POWERCOLOR_REAL_ANGEL   62
#define CX88_BOARD_GENIATECH_X8000_MT      63
212
#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO 64
213
#define CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD 65
214
#define CX88_BOARD_PROLINK_PV_8000GT       66
215
#define CX88_BOARD_KWORLD_ATSC_120         67
216 217
#define CX88_BOARD_HAUPPAUGE_HVR4000       68
#define CX88_BOARD_HAUPPAUGE_HVR4000LITE   69
218
#define CX88_BOARD_TEVII_S460              70
219
#define CX88_BOARD_OMICOM_SS4_PCI          71
220
#define CX88_BOARD_TBS_8920                72
221
#define CX88_BOARD_TEVII_S420              73
222
#define CX88_BOARD_PROLINK_PV_GLOBAL_XTREME 74
223
#define CX88_BOARD_PROF_7300               75
224 225
#define CX88_BOARD_SATTRADE_ST4200         76
#define CX88_BOARD_TBS_8910                77
226
#define CX88_BOARD_PROF_6200               78
227
#define CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII 79
228
#define CX88_BOARD_HAUPPAUGE_IRONLY        80
229
#define CX88_BOARD_WINFAST_DTV1800H        81
230
#define CX88_BOARD_WINFAST_DTV2000H_J      82
231
#define CX88_BOARD_PROF_7301               83
232
#define CX88_BOARD_SAMSUNG_SMT_7020        84
233
#define CX88_BOARD_TWINHAN_VP1027_DVBS     85
234
#define CX88_BOARD_TEVII_S464              86
235
#define CX88_BOARD_WINFAST_DTV2000H_PLUS   87
236
#define CX88_BOARD_WINFAST_DTV1800H_XC4000 88
237 238
#define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36 89
#define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43 90
L
Linus Torvalds 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

enum cx88_itype {
	CX88_VMUX_COMPOSITE1 = 1,
	CX88_VMUX_COMPOSITE2,
	CX88_VMUX_COMPOSITE3,
	CX88_VMUX_COMPOSITE4,
	CX88_VMUX_SVIDEO,
	CX88_VMUX_TELEVISION,
	CX88_VMUX_CABLE,
	CX88_VMUX_DVB,
	CX88_VMUX_DEBUG,
	CX88_RADIO,
};

struct cx88_input {
	enum cx88_itype type;
	u32             gpio0, gpio1, gpio2, gpio3;
256
	unsigned int    vmux:2;
257
	unsigned int    audioroute:4;
L
Linus Torvalds 已提交
258 259
};

H
Hans Verkuil 已提交
260
enum cx88_audio_chip {
261
	CX88_AUDIO_WM8775 = 1,
H
Hans Verkuil 已提交
262 263 264
	CX88_AUDIO_TVAUDIO,
};

L
Linus Torvalds 已提交
265
struct cx88_board {
266
	const char              *name;
L
Linus Torvalds 已提交
267
	unsigned int            tuner_type;
268 269 270
	unsigned int		radio_type;
	unsigned char		tuner_addr;
	unsigned char		radio_addr;
L
Linus Torvalds 已提交
271
	int                     tda9887_conf;
272
	struct cx88_input       input[MAX_CX88_INPUT];
L
Linus Torvalds 已提交
273
	struct cx88_input       radio;
274
	enum cx88_board_type    mpeg;
H
Hans Verkuil 已提交
275
	enum cx88_audio_chip	audio_chip;
276
	int			num_frontends;
277 278 279

	/* Used for I2S devices */
	int			i2sinputcntl;
L
Linus Torvalds 已提交
280 281 282 283 284 285 286 287
};

struct cx88_subid {
	u16     subvendor;
	u16     subdevice;
	u32     card;
};

288 289 290 291 292 293 294 295 296 297 298 299 300 301
enum cx88_tvaudio {
	WW_NONE = 1,
	WW_BTSC,
	WW_BG,
	WW_DK,
	WW_I,
	WW_L,
	WW_EIAJ,
	WW_I2SPT,
	WW_FM,
	WW_I2SADC,
	WW_M
};

302
#define INPUT(nr) (core->board.input[nr])
L
Linus Torvalds 已提交
303 304 305 306 307 308 309 310

/* ----------------------------------------------------------- */
/* device / file handle status                                 */

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

311
#define BUFFER_TIMEOUT     msecs_to_jiffies(2000)
L
Linus Torvalds 已提交
312

313 314 315 316 317 318 319
struct cx88_riscmem {
	unsigned int   size;
	__le32         *cpu;
	__le32         *jmp;
	dma_addr_t     dma;
};

L
Linus Torvalds 已提交
320 321 322
/* buffer for one video frame */
struct cx88_buffer {
	/* common v4l buffer stuff -- must be first */
H
Hans Verkuil 已提交
323 324
	struct vb2_buffer vb;
	struct list_head       list;
L
Linus Torvalds 已提交
325 326 327

	/* cx88 specific */
	unsigned int           bpl;
328
	struct cx88_riscmem    risc;
L
Linus Torvalds 已提交
329 330 331 332 333 334 335 336
	u32                    count;
};

struct cx88_dmaqueue {
	struct list_head       active;
	u32                    count;
};

337 338 339
struct cx8800_dev;
struct cx8802_dev;

L
Linus Torvalds 已提交
340 341 342 343 344 345 346
struct cx88_core {
	struct list_head           devlist;
	atomic_t                   refcount;

	/* board name */
	int                        nr;
	char                       name[32];
347
	u32			   model;
L
Linus Torvalds 已提交
348 349 350 351

	/* pci stuff */
	int                        pci_bus;
	int                        pci_slot;
352 353
	u32                        __iomem *lmmio;
	u8                         __iomem *bmmio;
L
Linus Torvalds 已提交
354 355 356 357 358 359 360 361 362 363
	u32                        shadow[SHADOW_MAX];
	int                        pci_irqmask;

	/* i2c i/o */
	struct i2c_adapter         i2c_adap;
	struct i2c_algo_bit_data   i2c_algo;
	struct i2c_client          i2c_client;
	u32                        i2c_state, i2c_rc;

	/* config info -- analog */
364
	struct v4l2_device 	   v4l2_dev;
365 366 367
	struct v4l2_ctrl_handler   video_hdl;
	struct v4l2_ctrl	   *chroma_agc;
	struct v4l2_ctrl_handler   audio_hdl;
368
	struct v4l2_subdev	   *sd_wm8775;
369
	struct i2c_client 	   *i2c_rtc;
370 371
	unsigned int               boardnr;
	struct cx88_board	   board;
L
Linus Torvalds 已提交
372

373 374 375
	/* Supported V4L _STD_ tuner formats */
	unsigned int               tuner_formats;

L
Linus Torvalds 已提交
376
	/* config info -- dvb */
377
#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
378
	int 			   (*prev_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
379
#endif
380
	void			   (*gate_ctrl)(struct cx88_core  *core, int open);
L
Linus Torvalds 已提交
381 382 383

	/* state info */
	struct task_struct         *kthread;
384
	v4l2_std_id                tvnorm;
385 386
	unsigned		   width, height;
	unsigned		   field;
387
	enum cx88_tvaudio          tvaudio;
L
Linus Torvalds 已提交
388 389 390
	u32                        audiomode_manual;
	u32                        audiomode_current;
	u32                        input;
391
	u32                        last_analog_input;
L
Linus Torvalds 已提交
392
	u32                        astat;
393
	u32			   use_nicam;
394
	unsigned long		   last_change;
L
Linus Torvalds 已提交
395 396 397

	/* IR remote control state */
	struct cx88_IR             *ir;
398

399 400
	/* I2C remote data */
	struct IR_i2c_init_data    init_data;
401
	struct wm8775_platform_data wm8775_data;
402

403
	struct mutex               lock;
404 405
	/* various v4l controls */
	u32                        freq;
406

407 408 409 410
	/*
	 * cx88-video needs to access cx8802 for hybrid tuner pll access and
	 * for vb2_is_busy() checks.
	 */
411
	struct cx8802_dev          *dvbdev;
412 413
	/* cx88-blackbird needs to access cx8800 for vb2_is_busy() checks */
	struct cx8800_dev          *v4ldev;
414
	enum cx88_board_type       active_type_id;
415
	int			   active_ref;
416
	int			   active_fe_id;
L
Linus Torvalds 已提交
417 418
};

419 420 421 422 423
static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
{
	return container_of(v4l2_dev, struct cx88_core, v4l2_dev);
}

424
#define call_hw(core, grpid, o, f, args...) \
425 426 427 428
	do {							\
		if (!core->i2c_rc) {				\
			if (core->gate_ctrl)			\
				core->gate_ctrl(core, 1);	\
429
			v4l2_device_call_all(&core->v4l2_dev, grpid, o, f, ##args); \
430 431 432 433 434
			if (core->gate_ctrl)			\
				core->gate_ctrl(core, 0);	\
		}						\
	} while (0)

435 436
#define call_all(core, o, f, args...) call_hw(core, 0, o, f, ##args)

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
#define WM8775_GID      (1 << 0)

#define wm8775_s_ctrl(core, id, val) \
	do {									\
		struct v4l2_ctrl *ctrl_ =					\
			v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id);	\
		if (ctrl_ && !core->i2c_rc) {					\
			if (core->gate_ctrl)					\
				core->gate_ctrl(core, 1);			\
			v4l2_ctrl_s_ctrl(ctrl_, val);				\
			if (core->gate_ctrl)					\
				core->gate_ctrl(core, 0);			\
		}								\
	} while (0)

#define wm8775_g_ctrl(core, id) \
	({									\
		struct v4l2_ctrl *ctrl_ =					\
			v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id);	\
		s32 val = 0;							\
		if (ctrl_ && !core->i2c_rc) {					\
			if (core->gate_ctrl)					\
				core->gate_ctrl(core, 1);			\
			val = v4l2_ctrl_g_ctrl(ctrl_);				\
			if (core->gate_ctrl)					\
				core->gate_ctrl(core, 0);			\
		}								\
		val;								\
	})

L
Linus Torvalds 已提交
467 468 469 470 471 472 473 474 475
/* ----------------------------------------------------------- */
/* function 0: video stuff                                     */

struct cx8800_suspend_state {
	int                        disabled;
};

struct cx8800_dev {
	struct cx88_core           *core;
476
	spinlock_t                 slock;
L
Linus Torvalds 已提交
477 478 479 480 481 482 483 484 485 486 487

	/* various device info */
	unsigned int               resources;
	struct video_device        *video_dev;
	struct video_device        *vbi_dev;
	struct video_device        *radio_dev;

	/* pci i/o */
	struct pci_dev             *pci;
	unsigned char              pci_rev,pci_lat;

488
	const struct cx8800_fmt    *fmt;
L
Linus Torvalds 已提交
489 490 491

	/* capture queues */
	struct cx88_dmaqueue       vidq;
H
Hans Verkuil 已提交
492
	struct vb2_queue           vb2_vidq;
L
Linus Torvalds 已提交
493
	struct cx88_dmaqueue       vbiq;
H
Hans Verkuil 已提交
494
	struct vb2_queue           vb2_vbiq;
L
Linus Torvalds 已提交
495 496 497 498 499 500 501 502 503

	/* various v4l controls */

	/* other global state info */
	struct cx8800_suspend_state state;
};

/* ----------------------------------------------------------- */
/* function 1: audio/alsa stuff                                */
504
/* =============> moved to cx88-alsa.c <====================== */
L
Linus Torvalds 已提交
505 506 507 508 509 510 511 512 513


/* ----------------------------------------------------------- */
/* function 2: mpeg stuff                                      */

struct cx8802_suspend_state {
	int                        disabled;
};

514 515
struct cx8802_driver {
	struct cx88_core *core;
516 517 518

	/* List of drivers attached to device */
	struct list_head drvlist;
519 520 521 522 523 524 525 526 527

	/* Type of driver and access required */
	enum cx88_board_type type_id;
	enum cx8802_board_access hw_access;

	/* MPEG 8802 internal only */
	int (*suspend)(struct pci_dev *pci_dev, pm_message_t state);
	int (*resume)(struct pci_dev *pci_dev);

528 529
	/* Callers to the following functions must hold core->lock */

530 531
	/* MPEG 8802 -> mini driver - Driver probe and configuration */
	int (*probe)(struct cx8802_driver *drv);
532 533 534 535 536 537 538 539 540 541 542
	int (*remove)(struct cx8802_driver *drv);

	/* MPEG 8802 -> mini driver - Access for hardware control */
	int (*advise_acquire)(struct cx8802_driver *drv);
	int (*advise_release)(struct cx8802_driver *drv);

	/* MPEG 8802 <- mini driver - Access for hardware control */
	int (*request_acquire)(struct cx8802_driver *drv);
	int (*request_release)(struct cx8802_driver *drv);
};

L
Linus Torvalds 已提交
543 544
struct cx8802_dev {
	struct cx88_core           *core;
545
	spinlock_t                 slock;
L
Linus Torvalds 已提交
546 547 548 549 550 551 552

	/* pci i/o */
	struct pci_dev             *pci;
	unsigned char              pci_rev,pci_lat;

	/* dma queues */
	struct cx88_dmaqueue       mpegq;
H
Hans Verkuil 已提交
553
	struct vb2_queue           vb2_mpegq;
L
Linus Torvalds 已提交
554 555 556 557 558 559 560 561
	u32                        ts_packet_size;
	u32                        ts_packet_count;

	/* other global state info */
	struct cx8802_suspend_state state;

	/* for blackbird only */
	struct list_head           devlist;
562
#if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD)
L
Linus Torvalds 已提交
563 564 565
	struct video_device        *mpeg_dev;
	u32                        mailbox;

566
	/* mpeg params */
567
	struct cx2341x_handler     cxhdl;
568 569
#endif

570
#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
L
Linus Torvalds 已提交
571
	/* for dvb only */
H
Hans Verkuil 已提交
572
	struct vb2_dvb_frontends frontends;
573
#endif
574

575
#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
576 577
	/* For VP3045 secondary I2C bus support */
	struct vp3054_i2c_state	   *vp3054;
578
#endif
L
Linus Torvalds 已提交
579 580
	/* for switching modulation types */
	unsigned char              ts_gen_cntrl;
581

582
	/* List of attached drivers; must hold core->lock to access */
583
	struct list_head	   drvlist;
584

585
	struct work_struct	   request_module_wk;
L
Linus Torvalds 已提交
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
};

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

#define cx_read(reg)             readl(core->lmmio + ((reg)>>2))
#define cx_write(reg,value)      writel((value), core->lmmio + ((reg)>>2))
#define cx_writeb(reg,value)     writeb((value), core->bmmio + (reg))

#define cx_andor(reg,mask,value) \
  writel((readl(core->lmmio+((reg)>>2)) & ~(mask)) |\
  ((value) & (mask)), core->lmmio+((reg)>>2))
#define cx_set(reg,bit)          cx_andor((reg),(bit),(bit))
#define cx_clear(reg,bit)        cx_andor((reg),(bit),0)

#define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }

/* shadow registers */
#define cx_sread(sreg)		    (core->shadow[sreg])
#define cx_swrite(sreg,reg,value) \
  (core->shadow[sreg] = value, \
   writel(core->shadow[sreg], core->lmmio + ((reg)>>2)))
#define cx_sandor(sreg,reg,mask,value) \
  (core->shadow[sreg] = (core->shadow[sreg] & ~(mask)) | ((value) & (mask)), \
   writel(core->shadow[sreg], core->lmmio + ((reg)>>2)))

/* ----------------------------------------------------------- */
/* cx88-core.c                                                 */

614 615
extern unsigned int cx88_core_debug;

616
extern void cx88_print_irqbits(const char *name, const char *tag, const char *strings[],
617
			       int len, u32 bits, u32 mask);
L
Linus Torvalds 已提交
618 619 620 621 622 623 624 625

extern int cx88_core_irq(struct cx88_core *core, u32 status);
extern void cx88_wakeup(struct cx88_core *core,
			struct cx88_dmaqueue *q, u32 count);
extern void cx88_shutdown(struct cx88_core *core);
extern int cx88_reset(struct cx88_core *core);

extern int
626
cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
L
Linus Torvalds 已提交
627 628 629 630
		 struct scatterlist *sglist,
		 unsigned int top_offset, unsigned int bottom_offset,
		 unsigned int bpl, unsigned int padding, unsigned int lines);
extern int
631
cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
L
Linus Torvalds 已提交
632
		     struct scatterlist *sglist, unsigned int bpl,
633
		     unsigned int lines, unsigned int lpi);
L
Linus Torvalds 已提交
634 635

extern void cx88_risc_disasm(struct cx88_core *core,
636
			     struct cx88_riscmem *risc);
L
Linus Torvalds 已提交
637
extern int cx88_sram_channel_setup(struct cx88_core *core,
638
				   const struct sram_channel *ch,
L
Linus Torvalds 已提交
639 640
				   unsigned int bpl, u32 risc);
extern void cx88_sram_channel_dump(struct cx88_core *core,
641
				   const struct sram_channel *ch);
L
Linus Torvalds 已提交
642 643 644

extern int cx88_set_scale(struct cx88_core *core, unsigned int width,
			  unsigned int height, enum v4l2_field field);
645
extern int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm);
L
Linus Torvalds 已提交
646 647 648

extern struct video_device *cx88_vdev_init(struct cx88_core *core,
					   struct pci_dev *pci,
649 650
					   const struct video_device *template_,
					   const char *type);
H
Hans Verkuil 已提交
651
extern struct cx88_core *cx88_core_get(struct pci_dev *pci);
L
Linus Torvalds 已提交
652 653 654
extern void cx88_core_put(struct cx88_core *core,
			  struct pci_dev *pci);

655 656 657 658
extern int cx88_start_audio_dma(struct cx88_core *core);
extern int cx88_stop_audio_dma(struct cx88_core *core);


L
Linus Torvalds 已提交
659 660 661
/* ----------------------------------------------------------- */
/* cx88-vbi.c                                                  */

662 663 664 665
/* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */
int cx8800_vbi_fmt (struct file *file, void *priv,
					struct v4l2_format *f);

666 667 668 669 670
/*
int cx8800_start_vbi_dma(struct cx8800_dev    *dev,
			 struct cx88_dmaqueue *q,
			 struct cx88_buffer   *buf);
*/
H
Hans Verkuil 已提交
671 672
void cx8800_stop_vbi_dma(struct cx8800_dev *dev);
int cx8800_restart_vbi_queue(struct cx8800_dev *dev, struct cx88_dmaqueue *q);
L
Linus Torvalds 已提交
673

H
Hans Verkuil 已提交
674
extern const struct vb2_ops cx8800_vbi_qops;
L
Linus Torvalds 已提交
675 676 677 678 679 680 681 682 683 684

/* ----------------------------------------------------------- */
/* cx88-i2c.c                                                  */

extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);


/* ----------------------------------------------------------- */
/* cx88-cards.c                                                */

685
extern int cx88_tuner_callback(void *dev, int component, int command, int arg);
686 687 688
extern int cx88_get_resources(const struct cx88_core *core,
			      struct pci_dev *pci);
extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
689
extern void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl);
L
Linus Torvalds 已提交
690 691 692 693 694 695 696 697 698 699

/* ----------------------------------------------------------- */
/* cx88-tvaudio.c                                              */

void cx88_set_tvaudio(struct cx88_core *core);
void cx88_newstation(struct cx88_core *core);
void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t);
void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual);
int cx88_audio_thread(void *data);

700 701
int cx8802_register_driver(struct cx8802_driver *drv);
int cx8802_unregister_driver(struct cx8802_driver *drv);
702 703

/* Caller must hold core->lock */
704 705
struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_type btype);

706 707 708 709 710
/* ----------------------------------------------------------- */
/* cx88-dsp.c                                                  */

s32 cx88_dsp_detect_stereo_sap(struct cx88_core *core);

L
Linus Torvalds 已提交
711 712 713 714 715 716
/* ----------------------------------------------------------- */
/* cx88-input.c                                                */

int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci);
int cx88_ir_fini(struct cx88_core *core);
void cx88_ir_irq(struct cx88_core *core);
717 718
int cx88_ir_start(struct cx88_core *core);
void cx88_ir_stop(struct cx88_core *core);
719
extern void cx88_i2c_init_ir(struct cx88_core *core);
L
Linus Torvalds 已提交
720 721 722 723

/* ----------------------------------------------------------- */
/* cx88-mpeg.c                                                 */

H
Hans Verkuil 已提交
724
int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
725
			struct cx88_buffer *buf);
L
Linus Torvalds 已提交
726 727
void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
void cx8802_cancel_buffers(struct cx8802_dev *dev);
H
Hans Verkuil 已提交
728 729 730
int cx8802_start_dma(struct cx8802_dev    *dev,
			    struct cx88_dmaqueue *q,
			    struct cx88_buffer   *buf);
L
Linus Torvalds 已提交
731

732
/* ----------------------------------------------------------- */
733
/* cx88-video.c*/
H
Hans Verkuil 已提交
734
int cx88_enum_input(struct cx88_core *core, struct v4l2_input *i);
735
int cx88_set_freq(struct cx88_core  *core, const struct v4l2_frequency *f);
736
int cx88_video_mux(struct cx88_core *core, unsigned int input);
H
Hans Verkuil 已提交
737 738
void cx88_querycap(struct file *file, struct cx88_core *core,
		struct v4l2_capability *cap);