2 * cx18 driver internal defines and structures
4 * Derived from ivtv-driver.h
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
7 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 #include <linux/version.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/sched.h>
35 #include <linux/pci.h>
36 #include <linux/interrupt.h>
37 #include <linux/spinlock.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-algo-bit.h>
40 #include <linux/list.h>
41 #include <linux/unistd.h>
42 #include <linux/pagemap.h>
43 #include <linux/workqueue.h>
44 #include <linux/mutex.h>
45 #include <asm/byteorder.h>
47 #include <linux/dvb/video.h>
48 #include <linux/dvb/audio.h>
49 #include <media/v4l2-common.h>
50 #include <media/v4l2-ioctl.h>
51 #include <media/tuner.h>
52 #include "cx18-mailbox.h"
53 #include "cx18-av-core.h"
59 #include "dvb_demux.h"
60 #include "dvb_frontend.h"
65 # error "This driver requires kernel PCI support."
68 #define CX18_MEM_OFFSET 0x00000000
69 #define CX18_MEM_SIZE 0x04000000
70 #define CX18_REG_OFFSET 0x02000000
72 /* Maximum cx18 driver instances. */
73 #define CX18_MAX_CARDS 32
76 #define CX18_CARD_HVR_1600_ESMT 0 /* Hauppauge HVR 1600 (ESMT memory) */
77 #define CX18_CARD_HVR_1600_SAMSUNG 1 /* Hauppauge HVR 1600 (Samsung memory) */
78 #define CX18_CARD_COMPRO_H900 2 /* Compro VideoMate H900 */
79 #define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */
80 #define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */
81 #define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/
82 #define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */
83 #define CX18_CARD_LAST 6
85 #define CX18_ENC_STREAM_TYPE_MPG 0
86 #define CX18_ENC_STREAM_TYPE_TS 1
87 #define CX18_ENC_STREAM_TYPE_YUV 2
88 #define CX18_ENC_STREAM_TYPE_VBI 3
89 #define CX18_ENC_STREAM_TYPE_PCM 4
90 #define CX18_ENC_STREAM_TYPE_IDX 5
91 #define CX18_ENC_STREAM_TYPE_RAD 6
92 #define CX18_MAX_STREAMS 7
94 /* system vendor and device IDs */
95 #define PCI_VENDOR_ID_CX 0x14f1
96 #define PCI_DEVICE_ID_CX23418 0x5b7a
98 /* subsystem vendor ID */
99 #define CX18_PCI_ID_HAUPPAUGE 0x0070
100 #define CX18_PCI_ID_COMPRO 0x185b
101 #define CX18_PCI_ID_YUAN 0x12ab
102 #define CX18_PCI_ID_CONEXANT 0x14f1
103 #define CX18_PCI_ID_TOSHIBA 0x1179
104 #define CX18_PCI_ID_LEADTEK 0x107D
106 /* ======================================================================== */
107 /* ========================== START USER SETTABLE DMA VARIABLES =========== */
108 /* ======================================================================== */
110 /* DMA Buffers, Default size in MB allocated */
111 #define CX18_DEFAULT_ENC_TS_BUFFERS 1
112 #define CX18_DEFAULT_ENC_MPG_BUFFERS 2
113 #define CX18_DEFAULT_ENC_IDX_BUFFERS 1
114 #define CX18_DEFAULT_ENC_YUV_BUFFERS 2
115 #define CX18_DEFAULT_ENC_VBI_BUFFERS 1
116 #define CX18_DEFAULT_ENC_PCM_BUFFERS 1
119 #define I2C_CLIENTS_MAX 16
123 /* Flag to turn on high volume debugging */
124 #define CX18_DBGFLG_WARN (1 << 0)
125 #define CX18_DBGFLG_INFO (1 << 1)
126 #define CX18_DBGFLG_API (1 << 2)
127 #define CX18_DBGFLG_DMA (1 << 3)
128 #define CX18_DBGFLG_IOCTL (1 << 4)
129 #define CX18_DBGFLG_FILE (1 << 5)
130 #define CX18_DBGFLG_I2C (1 << 6)
131 #define CX18_DBGFLG_IRQ (1 << 7)
132 /* Flag to turn on high volume debugging */
133 #define CX18_DBGFLG_HIGHVOL (1 << 8)
135 /* NOTE: extra space before comma in 'cx->num , ## args' is required for
136 gcc-2.95, otherwise it won't compile. */
137 #define CX18_DEBUG(x, type, fmt, args...) \
139 if ((x) & cx18_debug) \
140 printk(KERN_INFO "cx18-%d " type ": " fmt, cx->num , ## args); \
142 #define CX18_DEBUG_WARN(fmt, args...) CX18_DEBUG(CX18_DBGFLG_WARN, "warning", fmt , ## args)
143 #define CX18_DEBUG_INFO(fmt, args...) CX18_DEBUG(CX18_DBGFLG_INFO, "info", fmt , ## args)
144 #define CX18_DEBUG_API(fmt, args...) CX18_DEBUG(CX18_DBGFLG_API, "api", fmt , ## args)
145 #define CX18_DEBUG_DMA(fmt, args...) CX18_DEBUG(CX18_DBGFLG_DMA, "dma", fmt , ## args)
146 #define CX18_DEBUG_IOCTL(fmt, args...) CX18_DEBUG(CX18_DBGFLG_IOCTL, "ioctl", fmt , ## args)
147 #define CX18_DEBUG_FILE(fmt, args...) CX18_DEBUG(CX18_DBGFLG_FILE, "file", fmt , ## args)
148 #define CX18_DEBUG_I2C(fmt, args...) CX18_DEBUG(CX18_DBGFLG_I2C, "i2c", fmt , ## args)
149 #define CX18_DEBUG_IRQ(fmt, args...) CX18_DEBUG(CX18_DBGFLG_IRQ, "irq", fmt , ## args)
151 #define CX18_DEBUG_HIGH_VOL(x, type, fmt, args...) \
153 if (((x) & cx18_debug) && (cx18_debug & CX18_DBGFLG_HIGHVOL)) \
154 printk(KERN_INFO "cx18%d " type ": " fmt, cx->num , ## args); \
156 #define CX18_DEBUG_HI_WARN(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_WARN, "warning", fmt , ## args)
157 #define CX18_DEBUG_HI_INFO(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_INFO, "info", fmt , ## args)
158 #define CX18_DEBUG_HI_API(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_API, "api", fmt , ## args)
159 #define CX18_DEBUG_HI_DMA(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_DMA, "dma", fmt , ## args)
160 #define CX18_DEBUG_HI_IOCTL(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IOCTL, "ioctl", fmt , ## args)
161 #define CX18_DEBUG_HI_FILE(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_FILE, "file", fmt , ## args)
162 #define CX18_DEBUG_HI_I2C(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_I2C, "i2c", fmt , ## args)
163 #define CX18_DEBUG_HI_IRQ(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IRQ, "irq", fmt , ## args)
165 /* Standard kernel messages */
166 #define CX18_ERR(fmt, args...) printk(KERN_ERR "cx18-%d: " fmt, cx->num , ## args)
167 #define CX18_WARN(fmt, args...) printk(KERN_WARNING "cx18-%d: " fmt, cx->num , ## args)
168 #define CX18_INFO(fmt, args...) printk(KERN_INFO "cx18-%d: " fmt, cx->num , ## args)
170 /* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
171 #define MPEG_FRAME_TYPE_IFRAME 1
172 #define MPEG_FRAME_TYPE_IFRAME_PFRAME 3
173 #define MPEG_FRAME_TYPE_ALL 7
175 #define CX18_MAX_PGM_INDEX (400)
177 extern int cx18_debug;
180 struct cx18_options {
181 int megabytes[CX18_MAX_STREAMS]; /* Size in megabytes of each stream */
182 int cardtype; /* force card type on load */
183 int tuner; /* set tuner on load */
184 int radio; /* enable/disable radio */
187 /* per-buffer bit flags */
188 #define CX18_F_B_NEED_BUF_SWAP 0 /* this buffer should be byte swapped */
190 /* per-stream, s_flags */
191 #define CX18_F_S_CLAIMED 3 /* this stream is claimed */
192 #define CX18_F_S_STREAMING 4 /* the fw is decoding/encoding this stream */
193 #define CX18_F_S_INTERNAL_USE 5 /* this stream is used internally (sliced VBI processing) */
194 #define CX18_F_S_STREAMOFF 7 /* signal end of stream EOS */
195 #define CX18_F_S_APPL_IO 8 /* this stream is used read/written by an application */
197 /* per-cx18, i_flags */
198 #define CX18_F_I_LOADED_FW 0 /* Loaded firmware 1st time */
199 #define CX18_F_I_EOS 4 /* End of encoder stream */
200 #define CX18_F_I_RADIO_USER 5 /* radio tuner is selected */
201 #define CX18_F_I_ENC_PAUSED 13 /* the encoder is paused */
202 #define CX18_F_I_INITED 21 /* set after first open */
203 #define CX18_F_I_FAILED 22 /* set if first open failed */
205 /* These are the VBI types as they appear in the embedded VBI private packets. */
206 #define CX18_SLICED_TYPE_TELETEXT_B (1)
207 #define CX18_SLICED_TYPE_CAPTION_525 (4)
208 #define CX18_SLICED_TYPE_WSS_625 (5)
209 #define CX18_SLICED_TYPE_VPS (7)
212 struct list_head list;
213 dma_addr_t dma_handle;
215 unsigned long b_flags;
224 struct list_head list;
230 struct dmx_frontend hw_frontend;
231 struct dmx_frontend mem_frontend;
232 struct dmxdev dmxdev;
233 struct dvb_adapter dvb_adapter;
234 struct dvb_demux demux;
235 struct dvb_frontend *fe;
236 struct dvb_net dvbnet;
239 struct mutex feedlock;
242 struct cx18; /* forward reference */
243 struct cx18_scb; /* forward reference */
246 #define CX18_MAX_MDL_ACKS 2
247 #define CX18_MAX_EPU_WORK_ORDERS 70 /* CPU_DE_RELEASE_MDL bursts 63 commands */
249 #define CX18_F_EWO_MB_STALE_UPON_RECEIPT 0x1
250 #define CX18_F_EWO_MB_STALE_WHILE_PROC 0x2
251 #define CX18_F_EWO_MB_STALE \
252 (CX18_F_EWO_MB_STALE_UPON_RECEIPT | CX18_F_EWO_MB_STALE_WHILE_PROC)
254 struct cx18_epu_work_order {
255 struct work_struct work;
260 struct cx18_mailbox mb;
261 struct cx18_mdl_ack mdl_ack[CX18_MAX_MDL_ACKS];
265 #define CX18_INVALID_TASK_HANDLE 0xffffffff
268 /* These first four fields are always set, even if the stream
269 is not actually created. */
270 struct video_device *v4l2dev; /* NULL when stream not created */
271 struct cx18 *cx; /* for ease of use */
272 const char *name; /* name of the stream */
273 int type; /* stream type */
274 u32 handle; /* task handle */
278 struct mutex qlock; /* locks access to the queues */
279 unsigned long s_flags; /* status flags, see above */
280 int dma; /* can be PCI_DMA_TODEVICE,
281 PCI_DMA_FROMDEVICE or
284 wait_queue_head_t waitq;
291 struct cx18_queue q_free; /* free buffers */
292 struct cx18_queue q_full; /* full buffers */
293 struct cx18_queue q_io; /* waiting for I/O */
295 /* DVB / Digital Transport */
299 struct cx18_open_id {
302 enum v4l2_priority prio;
306 /* forward declaration of struct defined in cx18-cards.h */
310 #define CX18_VBI_FRAMES 32
317 u8 cc_data_even[256];
325 u32 raw_decoder_line_size;
326 u8 raw_decoder_sav_odd_field;
327 u8 raw_decoder_sav_even_field;
328 u32 sliced_decoder_line_size;
329 u8 sliced_decoder_sav_odd_field;
330 u8 sliced_decoder_sav_even_field;
331 struct v4l2_format in;
332 /* convenience pointer to sliced struct in vbi_in union */
333 struct v4l2_sliced_vbi_format *sliced_in;
337 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines.
338 One for /dev/vbi0 and one for /dev/vbi8 */
339 struct v4l2_sliced_vbi_data sliced_data[36];
341 /* Buffer for VBI data inserted into MPEG stream.
342 The first byte is a dummy byte that's never used.
343 The next 16 bytes contain the MPEG header for the VBI data,
344 the remainder is the actual VBI data.
345 The max size accepted by the MPEG VBI reinsertion turns out
346 to be 1552 bytes, which happens to be 4 + (1 + 42) * (2 * 18) bytes,
347 where 4 is a four byte header, 42 is the max sliced VBI payload, 1 is
348 a single line header byte and 2 * 18 is the number of VBI lines per frame.
350 However, it seems that the data must be 1K aligned, so we have to
351 pad the data until the 1 or 2 K boundary.
353 This pointer array will allocate 2049 bytes to store each VBI frame. */
354 u8 *sliced_mpeg_data[CX18_VBI_FRAMES];
355 u32 sliced_mpeg_size[CX18_VBI_FRAMES];
356 struct cx18_buffer sliced_mpeg_buf;
364 /* Per cx23418, per I2C bus private algo callback data */
365 struct cx18_i2c_algo_callback_data {
367 int bus_index; /* 0 or 1 for the cx23418's 1st or 2nd I2C bus */
370 #define CX18_MAX_MMIO_WR_RETRIES 10
372 /* Struct to hold info about cx18 cards */
374 int num; /* board number, -1 during init! */
375 char name[8]; /* board name for printk and interrupts (e.g. 'cx180') */
376 struct pci_dev *dev; /* PCI device */
377 const struct cx18_card *card; /* card information */
378 const char *card_name; /* full name of the card */
379 const struct cx18_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */
384 u8 nof_inputs; /* number of video inputs */
385 u8 nof_audio_inputs; /* number of audio inputs */
386 u16 buffer_id; /* buffer ID counter */
387 u32 v4l2_cap; /* V4L2 capabilities of card */
388 u32 hw_flags; /* Hardware description of the board */
390 struct cx18_scb __iomem *scb; /* pointer to SCB */
391 struct mutex epu2apu_mb_lock; /* protect driver to chip mailbox in SCB*/
392 struct mutex epu2cpu_mb_lock; /* protect driver to chip mailbox in SCB*/
394 struct cx18_av_state av_state;
397 struct cx2341x_mpeg_params params;
399 u32 temporal_strength;
400 u32 spatial_strength;
403 unsigned long dualwatch_jiffies;
404 u16 dualwatch_stereo_mode;
407 int digitizer; /* 0x00EF = saa7114 0x00FO = saa7115 0x0106 = mic */
409 struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */
410 struct cx18_options options; /* User options */
411 int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */
412 struct cx18_stream streams[CX18_MAX_STREAMS]; /* Stream data */
413 unsigned long i_flags; /* global cx18 flags */
414 atomic_t ana_capturing; /* count number of active analog capture streams */
415 atomic_t tot_capturing; /* total count number of active capture streams */
416 spinlock_t lock; /* lock access to this struct */
417 int search_pack_header;
419 int open_id; /* incremented each time an open occurs, used as
420 unique ID. Starts at 1, so 0 can be used as
421 uninitialized value in the stream->id. */
424 struct v4l2_prio_state prio;
427 void __iomem *enc_mem, *reg_mem;
433 u32 pgm_info_write_idx;
434 u32 pgm_info_read_idx;
435 struct v4l2_enc_idx_entry pgm_info[CX18_MAX_PGM_INDEX];
437 u64 mpg_data_received;
438 u64 vbi_data_inserted;
440 wait_queue_head_t mb_apu_waitq;
441 wait_queue_head_t mb_cpu_waitq;
442 wait_queue_head_t cap_w;
443 /* when the current DMA is finished this queue is woken up */
444 wait_queue_head_t dma_waitq;
450 struct cx18_epu_work_order epu_work_order[CX18_MAX_EPU_WORK_ORDERS];
451 char epu_debug_str[256]; /* CX18_EPU_DEBUG is rare: use shared space */
454 struct i2c_adapter i2c_adap[2];
455 struct i2c_algo_bit_data i2c_algo[2];
456 struct cx18_i2c_algo_callback_data i2c_algo_cb_data[2];
457 struct i2c_client i2c_client[2];
458 struct mutex i2c_bus_lock[2];
459 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];
464 struct mutex gpio_lock;
466 /* v4l2 and User settings */
473 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */
477 extern struct cx18 *cx18_cards[];
478 extern int cx18_cards_active;
479 extern int cx18_first_minor;
480 extern spinlock_t cx18_cards_lock;
481 extern struct workqueue_struct *cx18_work_queue;
483 /*==============Prototypes==================*/
485 /* Return non-zero if a signal is pending */
486 int cx18_msleep_timeout(unsigned int msecs, int intr);
488 /* Read Hauppauge eeprom */
489 struct tveeprom; /* forward reference */
490 void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv);
492 /* First-open initialization: load firmware, etc. */
493 int cx18_init_on_first_open(struct cx18 *cx);
495 #endif /* CX18_DRIVER_H */