2 * cx18 driver internal defines and structures
4 * Derived from ivtv-driver.h
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA
27 #include <linux/version.h>
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
30 #include <linux/init.h>
31 #include <linux/delay.h>
32 #include <linux/sched.h>
34 #include <linux/pci.h>
35 #include <linux/interrupt.h>
36 #include <linux/spinlock.h>
37 #include <linux/i2c.h>
38 #include <linux/i2c-algo-bit.h>
39 #include <linux/list.h>
40 #include <linux/unistd.h>
41 #include <linux/pagemap.h>
42 #include <linux/workqueue.h>
43 #include <linux/mutex.h>
45 #include <linux/dvb/video.h>
46 #include <linux/dvb/audio.h>
47 #include <media/v4l2-common.h>
48 #include <media/v4l2-ioctl.h>
49 #include <media/tuner.h>
50 #include "cx18-mailbox.h"
51 #include "cx18-av-core.h"
57 #include "dvb_demux.h"
58 #include "dvb_frontend.h"
63 # error "This driver requires kernel PCI support."
66 /* Default delay to throttle mmio access to the CX23418 */
67 #define CX18_DEFAULT_MMIO_NDELAY 0 /* 0 ns = 0 PCI clock(s) / 33 MHz */
69 #define CX18_MEM_OFFSET 0x00000000
70 #define CX18_MEM_SIZE 0x04000000
71 #define CX18_REG_OFFSET 0x02000000
73 /* Maximum cx18 driver instances. */
74 #define CX18_MAX_CARDS 32
77 #define CX18_CARD_HVR_1600_ESMT 0 /* Hauppauge HVR 1600 (ESMT memory) */
78 #define CX18_CARD_HVR_1600_SAMSUNG 1 /* Hauppauge HVR 1600 (Samsung memory) */
79 #define CX18_CARD_COMPRO_H900 2 /* Compro VideoMate H900 */
80 #define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */
81 #define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */
82 #define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/
83 #define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */
84 #define CX18_CARD_LAST 6
86 #define CX18_ENC_STREAM_TYPE_MPG 0
87 #define CX18_ENC_STREAM_TYPE_TS 1
88 #define CX18_ENC_STREAM_TYPE_YUV 2
89 #define CX18_ENC_STREAM_TYPE_VBI 3
90 #define CX18_ENC_STREAM_TYPE_PCM 4
91 #define CX18_ENC_STREAM_TYPE_IDX 5
92 #define CX18_ENC_STREAM_TYPE_RAD 6
93 #define CX18_MAX_STREAMS 7
95 /* system vendor and device IDs */
96 #define PCI_VENDOR_ID_CX 0x14f1
97 #define PCI_DEVICE_ID_CX23418 0x5b7a
99 /* subsystem vendor ID */
100 #define CX18_PCI_ID_HAUPPAUGE 0x0070
101 #define CX18_PCI_ID_COMPRO 0x185b
102 #define CX18_PCI_ID_YUAN 0x12ab
103 #define CX18_PCI_ID_CONEXANT 0x14f1
104 #define CX18_PCI_ID_TOSHIBA 0x1179
105 #define CX18_PCI_ID_LEADTEK 0x107D
107 /* ======================================================================== */
108 /* ========================== START USER SETTABLE DMA VARIABLES =========== */
109 /* ======================================================================== */
111 /* DMA Buffers, Default size in MB allocated */
112 #define CX18_DEFAULT_ENC_TS_BUFFERS 1
113 #define CX18_DEFAULT_ENC_MPG_BUFFERS 2
114 #define CX18_DEFAULT_ENC_IDX_BUFFERS 1
115 #define CX18_DEFAULT_ENC_YUV_BUFFERS 2
116 #define CX18_DEFAULT_ENC_VBI_BUFFERS 1
117 #define CX18_DEFAULT_ENC_PCM_BUFFERS 1
120 #define I2C_CLIENTS_MAX 16
124 /* Flag to turn on high volume debugging */
125 #define CX18_DBGFLG_WARN (1 << 0)
126 #define CX18_DBGFLG_INFO (1 << 1)
127 #define CX18_DBGFLG_API (1 << 2)
128 #define CX18_DBGFLG_DMA (1 << 3)
129 #define CX18_DBGFLG_IOCTL (1 << 4)
130 #define CX18_DBGFLG_FILE (1 << 5)
131 #define CX18_DBGFLG_I2C (1 << 6)
132 #define CX18_DBGFLG_IRQ (1 << 7)
133 /* Flag to turn on high volume debugging */
134 #define CX18_DBGFLG_HIGHVOL (1 << 8)
136 /* NOTE: extra space before comma in 'cx->num , ## args' is required for
137 gcc-2.95, otherwise it won't compile. */
138 #define CX18_DEBUG(x, type, fmt, args...) \
140 if ((x) & cx18_debug) \
141 printk(KERN_INFO "cx18-%d " type ": " fmt, cx->num , ## args); \
143 #define CX18_DEBUG_WARN(fmt, args...) CX18_DEBUG(CX18_DBGFLG_WARN, "warning", fmt , ## args)
144 #define CX18_DEBUG_INFO(fmt, args...) CX18_DEBUG(CX18_DBGFLG_INFO, "info", fmt , ## args)
145 #define CX18_DEBUG_API(fmt, args...) CX18_DEBUG(CX18_DBGFLG_API, "api", fmt , ## args)
146 #define CX18_DEBUG_DMA(fmt, args...) CX18_DEBUG(CX18_DBGFLG_DMA, "dma", fmt , ## args)
147 #define CX18_DEBUG_IOCTL(fmt, args...) CX18_DEBUG(CX18_DBGFLG_IOCTL, "ioctl", fmt , ## args)
148 #define CX18_DEBUG_FILE(fmt, args...) CX18_DEBUG(CX18_DBGFLG_FILE, "file", fmt , ## args)
149 #define CX18_DEBUG_I2C(fmt, args...) CX18_DEBUG(CX18_DBGFLG_I2C, "i2c", fmt , ## args)
150 #define CX18_DEBUG_IRQ(fmt, args...) CX18_DEBUG(CX18_DBGFLG_IRQ, "irq", fmt , ## args)
152 #define CX18_DEBUG_HIGH_VOL(x, type, fmt, args...) \
154 if (((x) & cx18_debug) && (cx18_debug & CX18_DBGFLG_HIGHVOL)) \
155 printk(KERN_INFO "cx18%d " type ": " fmt, cx->num , ## args); \
157 #define CX18_DEBUG_HI_WARN(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_WARN, "warning", fmt , ## args)
158 #define CX18_DEBUG_HI_INFO(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_INFO, "info", fmt , ## args)
159 #define CX18_DEBUG_HI_API(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_API, "api", fmt , ## args)
160 #define CX18_DEBUG_HI_DMA(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_DMA, "dma", fmt , ## args)
161 #define CX18_DEBUG_HI_IOCTL(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IOCTL, "ioctl", fmt , ## args)
162 #define CX18_DEBUG_HI_FILE(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_FILE, "file", fmt , ## args)
163 #define CX18_DEBUG_HI_I2C(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_I2C, "i2c", fmt , ## args)
164 #define CX18_DEBUG_HI_IRQ(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IRQ, "irq", fmt , ## args)
166 /* Standard kernel messages */
167 #define CX18_ERR(fmt, args...) printk(KERN_ERR "cx18-%d: " fmt, cx->num , ## args)
168 #define CX18_WARN(fmt, args...) printk(KERN_WARNING "cx18-%d: " fmt, cx->num , ## args)
169 #define CX18_INFO(fmt, args...) printk(KERN_INFO "cx18-%d: " fmt, cx->num , ## args)
171 /* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
172 #define MPEG_FRAME_TYPE_IFRAME 1
173 #define MPEG_FRAME_TYPE_IFRAME_PFRAME 3
174 #define MPEG_FRAME_TYPE_ALL 7
176 #define CX18_MAX_PGM_INDEX (400)
178 extern int cx18_retry_mmio; /* enable check & retry of mmio accesses */
179 extern int cx18_debug;
182 struct cx18_options {
183 int megabytes[CX18_MAX_STREAMS]; /* Size in megabytes of each stream */
184 int cardtype; /* force card type on load */
185 int tuner; /* set tuner on load */
186 int radio; /* enable/disable radio */
187 unsigned long mmio_ndelay; /* delay in ns after every PCI mmio access */
190 /* per-buffer bit flags */
191 #define CX18_F_B_NEED_BUF_SWAP 0 /* this buffer should be byte swapped */
193 /* per-stream, s_flags */
194 #define CX18_F_S_CLAIMED 3 /* this stream is claimed */
195 #define CX18_F_S_STREAMING 4 /* the fw is decoding/encoding this stream */
196 #define CX18_F_S_INTERNAL_USE 5 /* this stream is used internally (sliced VBI processing) */
197 #define CX18_F_S_STREAMOFF 7 /* signal end of stream EOS */
198 #define CX18_F_S_APPL_IO 8 /* this stream is used read/written by an application */
200 /* per-cx18, i_flags */
201 #define CX18_F_I_LOADED_FW 0 /* Loaded the firmware the first time */
202 #define CX18_F_I_EOS 4 /* End of encoder stream reached */
203 #define CX18_F_I_RADIO_USER 5 /* The radio tuner is selected */
204 #define CX18_F_I_ENC_PAUSED 13 /* the encoder is paused */
205 #define CX18_F_I_INITED 21 /* set after first open */
206 #define CX18_F_I_FAILED 22 /* set if first open failed */
208 /* These are the VBI types as they appear in the embedded VBI private packets. */
209 #define CX18_SLICED_TYPE_TELETEXT_B (1)
210 #define CX18_SLICED_TYPE_CAPTION_525 (4)
211 #define CX18_SLICED_TYPE_WSS_625 (5)
212 #define CX18_SLICED_TYPE_VPS (7)
215 struct list_head list;
216 dma_addr_t dma_handle;
218 unsigned long b_flags;
226 struct list_head list;
232 struct dmx_frontend hw_frontend;
233 struct dmx_frontend mem_frontend;
234 struct dmxdev dmxdev;
235 struct dvb_adapter dvb_adapter;
236 struct dvb_demux demux;
237 struct dvb_frontend *fe;
238 struct dvb_net dvbnet;
241 struct mutex feedlock;
244 struct cx18; /* forward reference */
245 struct cx18_scb; /* forward reference */
247 #define CX18_INVALID_TASK_HANDLE 0xffffffff
250 /* These first four fields are always set, even if the stream
251 is not actually created. */
252 struct video_device *v4l2dev; /* NULL when stream not created */
253 struct cx18 *cx; /* for ease of use */
254 const char *name; /* name of the stream */
255 int type; /* stream type */
256 u32 handle; /* task handle */
260 spinlock_t qlock; /* locks access to the queues */
261 unsigned long s_flags; /* status flags, see above */
262 int dma; /* can be PCI_DMA_TODEVICE,
263 PCI_DMA_FROMDEVICE or
266 wait_queue_head_t waitq;
273 struct cx18_queue q_free; /* free buffers */
274 struct cx18_queue q_full; /* full buffers */
275 struct cx18_queue q_io; /* waiting for I/O */
277 /* DVB / Digital Transport */
281 struct cx18_open_id {
284 enum v4l2_priority prio;
288 /* forward declaration of struct defined in cx18-cards.h */
292 #define CX18_VBI_FRAMES 32
299 u8 cc_data_even[256];
307 u32 raw_decoder_line_size;
308 u8 raw_decoder_sav_odd_field;
309 u8 raw_decoder_sav_even_field;
310 u32 sliced_decoder_line_size;
311 u8 sliced_decoder_sav_odd_field;
312 u8 sliced_decoder_sav_even_field;
313 struct v4l2_format in;
314 /* convenience pointer to sliced struct in vbi_in union */
315 struct v4l2_sliced_vbi_format *sliced_in;
319 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines.
320 One for /dev/vbi0 and one for /dev/vbi8 */
321 struct v4l2_sliced_vbi_data sliced_data[36];
323 /* Buffer for VBI data inserted into MPEG stream.
324 The first byte is a dummy byte that's never used.
325 The next 16 bytes contain the MPEG header for the VBI data,
326 the remainder is the actual VBI data.
327 The max size accepted by the MPEG VBI reinsertion turns out
328 to be 1552 bytes, which happens to be 4 + (1 + 42) * (2 * 18) bytes,
329 where 4 is a four byte header, 42 is the max sliced VBI payload, 1 is
330 a single line header byte and 2 * 18 is the number of VBI lines per frame.
332 However, it seems that the data must be 1K aligned, so we have to
333 pad the data until the 1 or 2 K boundary.
335 This pointer array will allocate 2049 bytes to store each VBI frame. */
336 u8 *sliced_mpeg_data[CX18_VBI_FRAMES];
337 u32 sliced_mpeg_size[CX18_VBI_FRAMES];
338 struct cx18_buffer sliced_mpeg_buf;
346 /* Per cx23418, per I2C bus private algo callback data */
347 struct cx18_i2c_algo_callback_data {
349 int bus_index; /* 0 or 1 for the cx23418's 1st or 2nd I2C bus */
352 #define CX18_MAX_MMIO_RETRIES 10
354 struct cx18_mmio_stats {
355 atomic_t retried_write[CX18_MAX_MMIO_RETRIES+1];
356 atomic_t retried_read[CX18_MAX_MMIO_RETRIES+1];
359 /* Struct to hold info about cx18 cards */
361 int num; /* board number, -1 during init! */
362 char name[8]; /* board name for printk and interrupts (e.g. 'cx180') */
363 struct pci_dev *dev; /* PCI device */
364 const struct cx18_card *card; /* card information */
365 const char *card_name; /* full name of the card */
366 const struct cx18_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */
371 u8 nof_inputs; /* number of video inputs */
372 u8 nof_audio_inputs; /* number of audio inputs */
373 u16 buffer_id; /* buffer ID counter */
374 u32 v4l2_cap; /* V4L2 capabilities of card */
375 u32 hw_flags; /* Hardware description of the board */
377 struct cx18_scb __iomem *scb; /* pointer to SCB */
379 struct cx18_av_state av_state;
382 struct cx2341x_mpeg_params params;
384 u32 temporal_strength;
385 u32 spatial_strength;
388 unsigned long dualwatch_jiffies;
389 u16 dualwatch_stereo_mode;
392 int digitizer; /* 0x00EF = saa7114 0x00FO = saa7115 0x0106 = mic */
394 struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */
395 struct cx18_options options; /* User options */
396 int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */
397 struct cx18_stream streams[CX18_MAX_STREAMS]; /* Stream data */
398 unsigned long i_flags; /* global cx18 flags */
399 atomic_t ana_capturing; /* count number of active analog capture streams */
400 atomic_t tot_capturing; /* total count number of active capture streams */
401 spinlock_t lock; /* lock access to this struct */
402 int search_pack_header;
404 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */
406 int open_id; /* incremented each time an open occurs, used as
407 unique ID. Starts at 1, so 0 can be used as
408 uninitialized value in the stream->id. */
411 struct v4l2_prio_state prio;
414 void __iomem *enc_mem, *reg_mem;
420 u32 pgm_info_write_idx;
421 u32 pgm_info_read_idx;
422 struct v4l2_enc_idx_entry pgm_info[CX18_MAX_PGM_INDEX];
424 u64 mpg_data_received;
425 u64 vbi_data_inserted;
427 wait_queue_head_t mb_apu_waitq;
428 wait_queue_head_t mb_cpu_waitq;
429 wait_queue_head_t mb_epu_waitq;
430 wait_queue_head_t mb_hpu_waitq;
431 wait_queue_head_t cap_w;
432 /* when the current DMA is finished this queue is woken up */
433 wait_queue_head_t dma_waitq;
436 struct i2c_adapter i2c_adap[2];
437 struct i2c_algo_bit_data i2c_algo[2];
438 struct cx18_i2c_algo_callback_data i2c_algo_cb_data[2];
439 struct i2c_client i2c_client[2];
440 struct mutex i2c_bus_lock[2];
441 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];
446 struct mutex gpio_lock;
449 struct cx18_mmio_stats mmio_stats;
451 /* v4l2 and User settings */
458 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */
462 extern struct cx18 *cx18_cards[];
463 extern int cx18_cards_active;
464 extern int cx18_first_minor;
465 extern spinlock_t cx18_cards_lock;
467 /*==============Prototypes==================*/
469 /* Return non-zero if a signal is pending */
470 int cx18_msleep_timeout(unsigned int msecs, int intr);
472 /* Read Hauppauge eeprom */
473 struct tveeprom; /* forward reference */
474 void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv);
476 /* First-open initialization: load firmware, etc. */
477 int cx18_init_on_first_open(struct cx18 *cx);
479 #endif /* CX18_DRIVER_H */