3 * Support for a cx23416 mpeg encoder via cx2388x host port.
4 * "blackbird" reference design.
6 * (c) 2004 Jelle Foks <jelle@foks.8m.com>
7 * (c) 2004 Gerd Knorr <kraxel@bytesex.org>
9 * Includes parts from the ivtv driver( http://ivtv.sourceforge.net/),
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/device.h>
32 #include <linux/firmware.h>
33 #include <media/v4l2-common.h>
34 #include <media/cx2341x.h>
38 MODULE_DESCRIPTION("driver for cx2388x/cx23416 based mpeg encoder cards");
39 MODULE_AUTHOR("Jelle Foks <jelle@foks.8m.com>, Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
40 MODULE_LICENSE("GPL");
42 static unsigned int mpegbufs = 32;
43 module_param(mpegbufs,int,0644);
44 MODULE_PARM_DESC(mpegbufs,"number of mpeg buffers, range 2-32");
46 static unsigned int debug = 0;
47 module_param(debug,int,0644);
48 MODULE_PARM_DESC(debug,"enable debug messages [blackbird]");
50 #define dprintk(level,fmt, arg...) if (debug >= level) \
51 printk(KERN_DEBUG "%s/2-bb: " fmt, dev->core->name , ## arg)
53 static LIST_HEAD(cx8802_devlist);
55 /* ------------------------------------------------------------------ */
57 #define BLACKBIRD_FIRM_IMAGE_SIZE 256*1024
59 /* defines below are from ivtv-driver.h */
61 #define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF
63 /* Firmware API commands */
64 #define IVTV_API_STD_TIMEOUT 500
66 enum blackbird_capture_type {
67 BLACKBIRD_MPEG_CAPTURE,
68 BLACKBIRD_RAW_CAPTURE,
69 BLACKBIRD_RAW_PASSTHRU_CAPTURE
71 enum blackbird_capture_bits {
72 BLACKBIRD_RAW_BITS_NONE = 0x00,
73 BLACKBIRD_RAW_BITS_YUV_CAPTURE = 0x01,
74 BLACKBIRD_RAW_BITS_PCM_CAPTURE = 0x02,
75 BLACKBIRD_RAW_BITS_VBI_CAPTURE = 0x04,
76 BLACKBIRD_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
77 BLACKBIRD_RAW_BITS_TO_HOST_CAPTURE = 0x10
79 enum blackbird_capture_end {
80 BLACKBIRD_END_AT_GOP, /* stop at the end of gop, generate irq */
81 BLACKBIRD_END_NOW, /* stop immediately, no irq */
83 enum blackbird_framerate {
84 BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */
85 BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */
87 enum blackbird_video_bitrate_type {
91 #define BLACKBIRD_PEAK_RATE_DIVISOR 400
92 enum blackbird_mux_rate {
93 BLACKBIRD_MUX_RATE_DEFAULT,
94 /* dvd mux rate: multiply by 400 to get the actual rate */
95 BLACKBIRD_MUX_RATE_DVD = 25200
97 enum blackbird_aspect_ratio {
98 BLACKBIRD_ASPECT_RATIO_FORBIDDEN,
99 BLACKBIRD_ASPECT_RATIO_1_1_SQUARE,
100 BLACKBIRD_ASPECT_RATIO_4_3,
101 BLACKBIRD_ASPECT_RATIO_16_9,
102 BLACKBIRD_ASPECT_RATIO_221_100,
103 BLACKBIRD_ASPECT_RATIO_RESERVED
105 enum blackbird_dnr_bits {
106 BLACKBIRD_DNR_BITS_MANUAL,
107 BLACKBIRD_DNR_BITS_AUTO_SPATIAL,
108 BLACKBIRD_DNR_BITS_AUTO_TEMPORAL,
109 BLACKBIRD_DNR_BITS_AUTO
111 enum blackbird_median_filter {
112 BLACKBIRD_MEDIAN_FILTER_DISABLED,
113 BLACKBIRD_MEDIAN_FILTER_HORIZONTAL,
114 BLACKBIRD_MEDIAN_FILTER_VERTICAL,
115 BLACKBIRD_MEDIAN_FILTER_HV,
116 BLACKBIRD_MEDIAN_FILTER_DIAGONAL
118 enum blackbird_spatial_filter_luma {
119 BLACKBIRD_SPATIAL_FILTER_LUMA_DISABLED,
120 BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ,
121 BLACKBIRD_SPATIAL_FILTER_LUMA_1D_VERT,
122 BLACKBIRD_SPATIAL_FILTER_LUMA_2D_HV, /* separable, default */
123 BLACKBIRD_SPATIAL_FILTER_LUMA_2D_SYMM /* symmetric non-separable */
125 enum blackbird_spatial_filter_chroma {
126 BLACKBIRD_SPATIAL_FILTER_CHROMA_DISABLED,
127 BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ /* default */
129 enum blackbird_pulldown {
130 BLACKBIRD_3_2_PULLDOWN_DISABLED,
131 BLACKBIRD_3_2_PULLDOWN_ENABLED
133 enum blackbird_vbi_line_bits {
134 BLACKBIRD_VBI_LINE_BITS_TOP_FIELD,
135 BLACKBIRD_VBI_LINE_BITS_BOT_FIELD = (1 << 31),
136 BLACKBIRD_VBI_LINE_BITS_ALL_LINES = 0xFFFFFFFF
138 enum blackbird_vbi_line {
139 BLACKBIRD_VBI_LINE_DISABLED,
140 BLACKBIRD_VBI_LINE_ENABLED
142 enum blackbird_vbi_slicing {
143 BLACKBIRD_VBI_SLICING_NONE,
144 BLACKBIRD_VBI_SLICING_CLOSED_CAPTION
146 enum blackbird_stream_type {
147 BLACKBIRD_STREAM_PROGRAM,
148 BLACKBIRD_STREAM_TRANSPORT,
149 BLACKBIRD_STREAM_MPEG1,
150 BLACKBIRD_STREAM_PES_AV,
151 BLACKBIRD_STREAM_UNKNOWN4,
152 BLACKBIRD_STREAM_PES_VIDEO,
153 BLACKBIRD_STREAM_UNKNOWN6,
154 BLACKBIRD_STREAM_PES_AUDIO,
155 BLACKBIRD_STREAM_UNKNOWN8,
156 BLACKBIRD_STREAM_UNKNOWN9, /* audio/pcm ? */
157 BLACKBIRD_STREAM_DVD,
158 BLACKBIRD_STREAM_VCD,
159 BLACKBIRD_STREAM_UNKNOWN12 /* svcd/xvcd ? */
161 enum blackbird_stream_port {
162 BLACKBIRD_OUTPUT_PORT_MEMORY,
163 BLACKBIRD_OUTPUT_PORT_STREAMING,
164 BLACKBIRD_OUTPUT_PORT_SERIAL
166 enum blackbird_audio_bits_sample_rate {
167 BLACKBIRD_AUDIO_BITS_44100HZ,
168 BLACKBIRD_AUDIO_BITS_48000HZ,
169 BLACKBIRD_AUDIO_BITS_32000HZ,
170 BLACKBIRD_AUDIO_BITS_RESERVED_HZ,
172 enum blackbird_audio_bits_encoding {
173 BLACKBIRD_AUDIO_BITS_LAYER_1 = 0x1 << 2,
174 BLACKBIRD_AUDIO_BITS_LAYER_2 = 0x2 << 2,
176 enum blackbird_audio_bits_bitrate_layer_1 {
177 BLACKBIRD_AUDIO_BITS_LAYER_1_FREE_FORMAT,
178 BLACKBIRD_AUDIO_BITS_LAYER_1_32 = 0x01 << 4,
179 BLACKBIRD_AUDIO_BITS_LAYER_1_64 = 0x02 << 4,
180 BLACKBIRD_AUDIO_BITS_LAYER_1_96 = 0x03 << 4,
181 BLACKBIRD_AUDIO_BITS_LAYER_1_128 = 0x04 << 4,
182 BLACKBIRD_AUDIO_BITS_LAYER_1_160 = 0x05 << 4,
183 BLACKBIRD_AUDIO_BITS_LAYER_1_192 = 0x06 << 4,
184 BLACKBIRD_AUDIO_BITS_LAYER_1_224 = 0x07 << 4,
185 BLACKBIRD_AUDIO_BITS_LAYER_1_256 = 0x08 << 4,
186 BLACKBIRD_AUDIO_BITS_LAYER_1_288 = 0x09 << 4,
187 BLACKBIRD_AUDIO_BITS_LAYER_1_320 = 0x0A << 4,
188 BLACKBIRD_AUDIO_BITS_LAYER_1_352 = 0x0B << 4,
189 BLACKBIRD_AUDIO_BITS_LAYER_1_384 = 0x0C << 4,
190 BLACKBIRD_AUDIO_BITS_LAYER_1_416 = 0x0D << 4,
191 BLACKBIRD_AUDIO_BITS_LAYER_1_448 = 0x0E << 4,
193 enum blackbird_audio_bits_bitrate_layer_2 {
194 BLACKBIRD_AUDIO_BITS_LAYER_2_FREE_FORMAT,
195 BLACKBIRD_AUDIO_BITS_LAYER_2_32 = 0x01 << 4,
196 BLACKBIRD_AUDIO_BITS_LAYER_2_48 = 0x02 << 4,
197 BLACKBIRD_AUDIO_BITS_LAYER_2_56 = 0x03 << 4,
198 BLACKBIRD_AUDIO_BITS_LAYER_2_64 = 0x04 << 4,
199 BLACKBIRD_AUDIO_BITS_LAYER_2_80 = 0x05 << 4,
200 BLACKBIRD_AUDIO_BITS_LAYER_2_96 = 0x06 << 4,
201 BLACKBIRD_AUDIO_BITS_LAYER_2_112 = 0x07 << 4,
202 BLACKBIRD_AUDIO_BITS_LAYER_2_128 = 0x08 << 4,
203 BLACKBIRD_AUDIO_BITS_LAYER_2_160 = 0x09 << 4,
204 BLACKBIRD_AUDIO_BITS_LAYER_2_192 = 0x0A << 4,
205 BLACKBIRD_AUDIO_BITS_LAYER_2_224 = 0x0B << 4,
206 BLACKBIRD_AUDIO_BITS_LAYER_2_256 = 0x0C << 4,
207 BLACKBIRD_AUDIO_BITS_LAYER_2_320 = 0x0D << 4,
208 BLACKBIRD_AUDIO_BITS_LAYER_2_384 = 0x0E << 4,
210 enum blackbird_audio_bits_mode {
211 BLACKBIRD_AUDIO_BITS_STEREO,
212 BLACKBIRD_AUDIO_BITS_JOINT_STEREO = 0x1 << 8,
213 BLACKBIRD_AUDIO_BITS_DUAL = 0x2 << 8,
214 BLACKBIRD_AUDIO_BITS_MONO = 0x3 << 8,
216 enum blackbird_audio_bits_mode_extension {
217 BLACKBIRD_AUDIO_BITS_BOUND_4,
218 BLACKBIRD_AUDIO_BITS_BOUND_8 = 0x1 << 10,
219 BLACKBIRD_AUDIO_BITS_BOUND_12 = 0x2 << 10,
220 BLACKBIRD_AUDIO_BITS_BOUND_16 = 0x3 << 10,
222 enum blackbird_audio_bits_emphasis {
223 BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE,
224 BLACKBIRD_AUDIO_BITS_EMPHASIS_50_15 = 0x1 << 12,
225 BLACKBIRD_AUDIO_BITS_EMPHASIS_RESERVED = 0x2 << 12,
226 BLACKBIRD_AUDIO_BITS_EMPHASIS_CCITT_J17 = 0x3 << 12,
228 enum blackbird_audio_bits_crc {
229 BLACKBIRD_AUDIO_BITS_CRC_OFF,
230 BLACKBIRD_AUDIO_BITS_CRC_ON = 0x1 << 14,
232 enum blackbird_audio_bits_copyright {
233 BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF,
234 BLACKBIRD_AUDIO_BITS_COPYRIGHT_ON = 0x1 << 15,
236 enum blackbird_audio_bits_original {
237 BLACKBIRD_AUDIO_BITS_COPY,
238 BLACKBIRD_AUDIO_BITS_ORIGINAL = 0x1 << 16,
240 enum blackbird_gop_closure {
241 BLACKBIRD_GOP_CLOSURE_OFF,
242 BLACKBIRD_GOP_CLOSURE_ON,
244 enum blackbird_data_xfer_status {
245 BLACKBIRD_MORE_BUFFERS_FOLLOW,
246 BLACKBIRD_LAST_BUFFER,
248 enum blackbird_picture_mask {
249 BLACKBIRD_PICTURE_MASK_NONE,
250 BLACKBIRD_PICTURE_MASK_I_FRAMES,
251 BLACKBIRD_PICTURE_MASK_I_P_FRAMES = 0x3,
252 BLACKBIRD_PICTURE_MASK_ALL_FRAMES = 0x7,
254 enum blackbird_vbi_mode_bits {
255 BLACKBIRD_VBI_BITS_SLICED,
256 BLACKBIRD_VBI_BITS_RAW,
258 enum blackbird_vbi_insertion_bits {
259 BLACKBIRD_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
260 BLACKBIRD_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
261 BLACKBIRD_VBI_BITS_SEPARATE_STREAM = 0x2 << 1,
262 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
263 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
265 enum blackbird_dma_unit {
267 BLACKBIRD_DMA_FRAMES,
269 enum blackbird_dma_transfer_status_bits {
270 BLACKBIRD_DMA_TRANSFER_BITS_DONE = 0x01,
271 BLACKBIRD_DMA_TRANSFER_BITS_ERROR = 0x04,
272 BLACKBIRD_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
274 enum blackbird_pause {
275 BLACKBIRD_PAUSE_ENCODING,
276 BLACKBIRD_RESUME_ENCODING,
278 enum blackbird_copyright {
279 BLACKBIRD_COPYRIGHT_OFF,
280 BLACKBIRD_COPYRIGHT_ON,
282 enum blackbird_notification_type {
283 BLACKBIRD_NOTIFICATION_REFRESH,
285 enum blackbird_notification_status {
286 BLACKBIRD_NOTIFICATION_OFF,
287 BLACKBIRD_NOTIFICATION_ON,
289 enum blackbird_notification_mailbox {
290 BLACKBIRD_NOTIFICATION_NO_MAILBOX = -1,
292 enum blackbird_field1_lines {
293 BLACKBIRD_FIELD1_SAA7114 = 0x00EF, /* 239 */
294 BLACKBIRD_FIELD1_SAA7115 = 0x00F0, /* 240 */
295 BLACKBIRD_FIELD1_MICRONAS = 0x0105, /* 261 */
297 enum blackbird_field2_lines {
298 BLACKBIRD_FIELD2_SAA7114 = 0x00EF, /* 239 */
299 BLACKBIRD_FIELD2_SAA7115 = 0x00F0, /* 240 */
300 BLACKBIRD_FIELD2_MICRONAS = 0x0106, /* 262 */
302 enum blackbird_custom_data_type {
303 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
304 BLACKBIRD_CUSTOM_PRIVATE_PACKET,
306 enum blackbird_mute {
310 enum blackbird_mute_video_mask {
311 BLACKBIRD_MUTE_VIDEO_V_MASK = 0x0000FF00,
312 BLACKBIRD_MUTE_VIDEO_U_MASK = 0x00FF0000,
313 BLACKBIRD_MUTE_VIDEO_Y_MASK = 0xFF000000,
315 enum blackbird_mute_video_shift {
316 BLACKBIRD_MUTE_VIDEO_V_SHIFT = 8,
317 BLACKBIRD_MUTE_VIDEO_U_SHIFT = 16,
318 BLACKBIRD_MUTE_VIDEO_Y_SHIFT = 24,
322 #define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8 /*| IVTV_REG_OFFSET*/)
323 #define IVTV_REG_ENC_SDRAM_PRECHARGE (0x07FC /*| IVTV_REG_OFFSET*/)
324 #define IVTV_REG_SPU (0x9050 /*| IVTV_REG_OFFSET*/)
325 #define IVTV_REG_HW_BLOCKS (0x9054 /*| IVTV_REG_OFFSET*/)
326 #define IVTV_REG_VPU (0x9058 /*| IVTV_REG_OFFSET*/)
327 #define IVTV_REG_APU (0xA064 /*| IVTV_REG_OFFSET*/)
329 /* ------------------------------------------------------------------ */
331 static void host_setup(struct cx88_core *core)
333 /* toggle reset of the host */
334 cx_write(MO_GPHST_SOFT_RST, 1);
336 cx_write(MO_GPHST_SOFT_RST, 0);
339 /* host port setup */
340 cx_write(MO_GPHST_WSC, 0x44444444U);
341 cx_write(MO_GPHST_XFR, 0);
342 cx_write(MO_GPHST_WDTH, 15);
343 cx_write(MO_GPHST_HDSHK, 0);
344 cx_write(MO_GPHST_MUX16, 0x44448888U);
345 cx_write(MO_GPHST_MODE, 0);
348 /* ------------------------------------------------------------------ */
350 #define P1_MDATA0 0x390000
351 #define P1_MDATA1 0x390001
352 #define P1_MDATA2 0x390002
353 #define P1_MDATA3 0x390003
354 #define P1_MADDR2 0x390004
355 #define P1_MADDR1 0x390005
356 #define P1_MADDR0 0x390006
357 #define P1_RDATA0 0x390008
358 #define P1_RDATA1 0x390009
359 #define P1_RDATA2 0x39000A
360 #define P1_RDATA3 0x39000B
361 #define P1_RADDR0 0x39000C
362 #define P1_RADDR1 0x39000D
363 #define P1_RRDWR 0x39000E
365 static int wait_ready_gpio0_bit1(struct cx88_core *core, u32 state)
367 unsigned long timeout = jiffies + msecs_to_jiffies(1);
370 need = state ? 2 : 0;
372 gpio0 = cx_read(MO_GP0_IO) & 2;
375 if (time_after(jiffies,timeout))
381 static int memory_write(struct cx88_core *core, u32 address, u32 value)
383 /* Warning: address is dword address (4 bytes) */
384 cx_writeb(P1_MDATA0, (unsigned int)value);
385 cx_writeb(P1_MDATA1, (unsigned int)(value >> 8));
386 cx_writeb(P1_MDATA2, (unsigned int)(value >> 16));
387 cx_writeb(P1_MDATA3, (unsigned int)(value >> 24));
388 cx_writeb(P1_MADDR2, (unsigned int)(address >> 16) | 0x40);
389 cx_writeb(P1_MADDR1, (unsigned int)(address >> 8));
390 cx_writeb(P1_MADDR0, (unsigned int)address);
394 return wait_ready_gpio0_bit1(core,1);
397 static int memory_read(struct cx88_core *core, u32 address, u32 *value)
402 /* Warning: address is dword address (4 bytes) */
403 cx_writeb(P1_MADDR2, (unsigned int)(address >> 16) & ~0xC0);
404 cx_writeb(P1_MADDR1, (unsigned int)(address >> 8));
405 cx_writeb(P1_MADDR0, (unsigned int)address);
408 retval = wait_ready_gpio0_bit1(core,1);
410 cx_writeb(P1_MDATA3, 0);
411 val = (unsigned char)cx_read(P1_MDATA3) << 24;
412 cx_writeb(P1_MDATA2, 0);
413 val |= (unsigned char)cx_read(P1_MDATA2) << 16;
414 cx_writeb(P1_MDATA1, 0);
415 val |= (unsigned char)cx_read(P1_MDATA1) << 8;
416 cx_writeb(P1_MDATA0, 0);
417 val |= (unsigned char)cx_read(P1_MDATA0);
423 static int register_write(struct cx88_core *core, u32 address, u32 value)
425 cx_writeb(P1_RDATA0, (unsigned int)value);
426 cx_writeb(P1_RDATA1, (unsigned int)(value >> 8));
427 cx_writeb(P1_RDATA2, (unsigned int)(value >> 16));
428 cx_writeb(P1_RDATA3, (unsigned int)(value >> 24));
429 cx_writeb(P1_RADDR0, (unsigned int)address);
430 cx_writeb(P1_RADDR1, (unsigned int)(address >> 8));
431 cx_writeb(P1_RRDWR, 1);
435 return wait_ready_gpio0_bit1(core,1);
439 static int register_read(struct cx88_core *core, u32 address, u32 *value)
444 cx_writeb(P1_RADDR0, (unsigned int)address);
445 cx_writeb(P1_RADDR1, (unsigned int)(address >> 8));
446 cx_writeb(P1_RRDWR, 0);
449 retval = wait_ready_gpio0_bit1(core,1);
450 val = (unsigned char)cx_read(P1_RDATA0);
451 val |= (unsigned char)cx_read(P1_RDATA1) << 8;
452 val |= (unsigned char)cx_read(P1_RDATA2) << 16;
453 val |= (unsigned char)cx_read(P1_RDATA3) << 24;
459 /* ------------------------------------------------------------------ */
461 /* We don't need to call the API often, so using just one mailbox will probably suffice */
462 static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command,
463 u32 inputcnt, u32 outputcnt, ...)
465 unsigned long timeout;
466 u32 value, flag, retval;
469 va_start(args, outputcnt);
471 dprintk(1,"%s: 0x%X\n", __FUNCTION__, command);
473 /* this may not be 100% safe if we can't read any memory location
474 without side effects */
475 memory_read(dev->core, dev->mailbox - 4, &value);
476 if (value != 0x12345678) {
477 dprintk(0, "Firmware and/or mailbox pointer not initialized or corrupted\n");
481 memory_read(dev->core, dev->mailbox, &flag);
483 dprintk(0, "ERROR: Mailbox appears to be in use (%x)\n", flag);
487 flag |= 1; /* tell 'em we're working on it */
488 memory_write(dev->core, dev->mailbox, flag);
490 /* write command + args + fill remaining with zeros */
491 memory_write(dev->core, dev->mailbox + 1, command); /* command code */
492 memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT); /* timeout */
493 for (i = 0; i < inputcnt ; i++) {
494 value = va_arg(args, int);
495 memory_write(dev->core, dev->mailbox + 4 + i, value);
496 dprintk(1, "API Input %d = %d\n", i, value);
499 memory_write(dev->core, dev->mailbox + 4 + i, 0);
501 flag |= 3; /* tell 'em we're done writing */
502 memory_write(dev->core, dev->mailbox, flag);
504 /* wait for firmware to handle the API command */
505 timeout = jiffies + msecs_to_jiffies(10);
507 memory_read(dev->core, dev->mailbox, &flag);
510 if (time_after(jiffies,timeout)) {
511 dprintk(0, "ERROR: API Mailbox timeout\n");
517 /* read output values */
518 for (i = 0; i < outputcnt ; i++) {
519 int *vptr = va_arg(args, int *);
520 memory_read(dev->core, dev->mailbox + 4 + i, vptr);
521 dprintk(1, "API Output %d = %d\n", i, *vptr);
525 memory_read(dev->core, dev->mailbox + 2, &retval);
526 dprintk(1, "API result = %d\n",retval);
529 memory_write(dev->core, dev->mailbox, flag);
534 static int blackbird_find_mailbox(struct cx8802_dev *dev)
536 u32 signature[4]={0x12345678, 0x34567812, 0x56781234, 0x78123456};
541 for (i = 0; i < BLACKBIRD_FIRM_IMAGE_SIZE; i++) {
542 memory_read(dev->core, i, &value);
543 if (value == signature[signaturecnt])
547 if (4 == signaturecnt) {
548 dprintk(1, "Mailbox signature found\n");
552 dprintk(0, "Mailbox signature values not found!\n");
556 static int blackbird_load_firmware(struct cx8802_dev *dev)
558 static const unsigned char magic[8] = {
559 0xa7, 0x0d, 0x00, 0x00, 0x66, 0xbb, 0x55, 0xaa
561 const struct firmware *firmware;
567 retval = register_write(dev->core, IVTV_REG_VPU, 0xFFFFFFED);
568 retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
569 retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_REFRESH, 0x80000640);
570 retval |= register_write(dev->core, IVTV_REG_ENC_SDRAM_PRECHARGE, 0x1A);
572 retval |= register_write(dev->core, IVTV_REG_APU, 0);
575 dprintk(0, "Error with register_write\n");
577 retval = request_firmware(&firmware, CX2341X_FIRM_ENC_FILENAME,
582 dprintk(0, "ERROR: Hotplug firmware request failed (%s).\n",
583 CX2341X_FIRM_ENC_FILENAME);
584 dprintk(0, "Please fix your hotplug setup, the board will "
585 "not work without firmware loaded!\n");
589 if (firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) {
590 dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d)\n",
591 firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE);
595 if (0 != memcmp(firmware->data, magic, 8)) {
596 dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n");
600 /* transfer to the chip */
601 dprintk(1,"Loading firmware ...\n");
602 dataptr = (u32*)firmware->data;
603 for (i = 0; i < (firmware->size >> 2); i++) {
606 memory_write(dev->core, i, value);
610 /* read back to verify with the checksum */
611 for (i--; i >= 0; i--) {
612 memory_read(dev->core, i, &value);
616 dprintk(0, "ERROR: Firmware load failed (checksum mismatch).\n");
619 release_firmware(firmware);
620 dprintk(0, "Firmware upload successful.\n");
622 retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
623 retval |= register_read(dev->core, IVTV_REG_SPU, &value);
624 retval |= register_write(dev->core, IVTV_REG_SPU, value & 0xFFFFFFFE);
627 retval |= register_read(dev->core, IVTV_REG_VPU, &value);
628 retval |= register_write(dev->core, IVTV_REG_VPU, value & 0xFFFFFFE8);
631 dprintk(0, "Error with register_write\n");
636 Settings used by the windows tv app for PVR2000:
637 =================================================================================================================
638 Profile | Codec | Resolution | CBR/VBR | Video Qlty | V. Bitrate | Frmrate | Audio Codec | A. Bitrate | A. Mode
639 -----------------------------------------------------------------------------------------------------------------
640 MPEG-1 | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 2000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
641 MPEG-2 | MPEG2 | 720x576PAL | VBR | 600 :Good | 4000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
642 VCD | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 1150 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
643 DVD | MPEG2 | 720x576PAL | VBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
644 DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
645 =================================================================================================================
649 static struct blackbird_dnr default_dnr_params = {
650 .mode = BLACKBIRD_DNR_BITS_MANUAL,
651 .type = BLACKBIRD_MEDIAN_FILTER_DISABLED,
655 static struct v4l2_mpeg_compression default_mpeg_params = {
656 .st_type = V4L2_MPEG_PS_2,
658 .mode = V4L2_BITRATE_CBR,
668 .au_type = V4L2_MPEG_AU_2_II,
670 .mode = V4L2_BITRATE_CBR,
675 .au_sample_rate = 44100,
677 .vi_type = V4L2_MPEG_VI_2,
678 .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3,
680 .mode = V4L2_BITRATE_CBR,
686 .vi_frames_per_gop = 15,
687 .vi_bframes_count = 2,
693 static enum blackbird_stream_type mpeg_stream_types[] = {
694 [V4L2_MPEG_SS_1] = BLACKBIRD_STREAM_MPEG1,
695 [V4L2_MPEG_PS_2] = BLACKBIRD_STREAM_PROGRAM,
696 [V4L2_MPEG_TS_2] = BLACKBIRD_STREAM_TRANSPORT,
697 [V4L2_MPEG_PS_DVD] = BLACKBIRD_STREAM_DVD,
699 static enum blackbird_aspect_ratio mpeg_stream_ratios[] = {
700 [V4L2_MPEG_ASPECT_SQUARE] = BLACKBIRD_ASPECT_RATIO_1_1_SQUARE,
701 [V4L2_MPEG_ASPECT_4_3] = BLACKBIRD_ASPECT_RATIO_4_3,
702 [V4L2_MPEG_ASPECT_16_9] = BLACKBIRD_ASPECT_RATIO_16_9,
703 [V4L2_MPEG_ASPECT_1_221] = BLACKBIRD_ASPECT_RATIO_221_100,
705 static enum blackbird_video_bitrate_type mpeg_video_bitrates[] = {
706 [V4L2_BITRATE_NONE] = BLACKBIRD_VIDEO_CBR,
707 [V4L2_BITRATE_CBR] = BLACKBIRD_VIDEO_CBR,
708 [V4L2_BITRATE_VBR] = BLACKBIRD_VIDEO_VBR,
710 /* find the best layer I/II bitrate to fit a given numeric value */
711 struct bitrate_bits {
712 u32 bits; /* layer bits for the best fit */
713 u32 rate; /* actual numeric value for the layer best fit */
715 struct bitrate_approximation {
716 u32 target; /* numeric value of the rate we want */
717 struct bitrate_bits layer[2];
719 static struct bitrate_approximation mpeg_audio_bitrates[] = {
720 /* target layer[0].bits layer[0].rate layer[1].bits layer[1].rate */
721 { 0, { { 0, 0, }, { 0, 0, }, }, },
722 { 32, { { BLACKBIRD_AUDIO_BITS_LAYER_1_32 , 32, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_32 , 32, }, }, },
723 { 48, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_48 , 48, }, }, },
724 { 56, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_56 , 56, }, }, },
725 { 64, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_64 , 64, }, }, },
726 { 80, { { BLACKBIRD_AUDIO_BITS_LAYER_1_96 , 96, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_80 , 80, }, }, },
727 { 96, { { BLACKBIRD_AUDIO_BITS_LAYER_1_96 , 96, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_96 , 96, }, }, },
728 { 112, { { BLACKBIRD_AUDIO_BITS_LAYER_1_128, 128, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_112, 112, }, }, },
729 { 128, { { BLACKBIRD_AUDIO_BITS_LAYER_1_128, 128, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_128, 128, }, }, },
730 { 160, { { BLACKBIRD_AUDIO_BITS_LAYER_1_160, 160, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_160, 160, }, }, },
731 { 192, { { BLACKBIRD_AUDIO_BITS_LAYER_1_192, 192, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_192, 192, }, }, },
732 { 224, { { BLACKBIRD_AUDIO_BITS_LAYER_1_224, 224, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_224, 224, }, }, },
733 { 256, { { BLACKBIRD_AUDIO_BITS_LAYER_1_256, 256, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_256, 256, }, }, },
734 { 288, { { BLACKBIRD_AUDIO_BITS_LAYER_1_288, 288, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_320, 320, }, }, },
735 { 320, { { BLACKBIRD_AUDIO_BITS_LAYER_1_320, 320, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_320, 320, }, }, },
736 { 352, { { BLACKBIRD_AUDIO_BITS_LAYER_1_352, 352, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, },
737 { 384, { { BLACKBIRD_AUDIO_BITS_LAYER_1_384, 384, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, },
738 { 416, { { BLACKBIRD_AUDIO_BITS_LAYER_1_416, 416, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, },
739 { 448, { { BLACKBIRD_AUDIO_BITS_LAYER_1_448, 448, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, },
741 static const int BITRATES_SIZE = ARRAY_SIZE(mpeg_audio_bitrates);
743 static void blackbird_set_default_params(struct cx8802_dev *dev)
745 struct v4l2_mpeg_compression *params = &dev->params;
748 /* assign stream type */
749 if( params->st_type >= ARRAY_SIZE(mpeg_stream_types) )
750 params->st_type = V4L2_MPEG_PS_2;
751 if( params->st_type == V4L2_MPEG_SS_1 )
752 params->vi_type = V4L2_MPEG_VI_1;
754 params->vi_type = V4L2_MPEG_VI_2;
755 blackbird_api_cmd(dev, CX2341X_ENC_SET_STREAM_TYPE, 1, 0, mpeg_stream_types[params->st_type]);
757 /* assign framerate */
758 if( params->vi_frame_rate <= 25 )
760 params->vi_frame_rate = 25;
761 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25);
765 params->vi_frame_rate = 30;
766 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_NTSC_30);
769 /* assign aspect ratio */
770 if( params->vi_aspect_ratio >= ARRAY_SIZE(mpeg_stream_ratios) )
771 params->vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3;
772 blackbird_api_cmd(dev, CX2341X_ENC_SET_ASPECT_RATIO, 1, 0, mpeg_stream_ratios[params->vi_aspect_ratio]);
774 /* assign gop properties */
775 blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 0, params->vi_frames_per_gop, params->vi_bframes_count+1);
777 /* assign gop closure */
778 blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_CLOSURE, 1, 0, params->closed_gops);
780 /* assign 3 2 pulldown */
781 blackbird_api_cmd(dev, CX2341X_ENC_SET_3_2_PULLDOWN, 1, 0, params->pulldown);
783 /* make sure the params are within bounds */
784 if( params->st_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) )
785 params->vi_bitrate.mode = V4L2_BITRATE_NONE;
786 if( params->vi_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) )
787 params->vi_bitrate.mode = V4L2_BITRATE_NONE;
788 if( params->au_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) )
789 params->au_bitrate.mode = V4L2_BITRATE_NONE;
791 /* assign audio properties */
792 /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */
793 au_params = BLACKBIRD_AUDIO_BITS_STEREO |
794 /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */
795 BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE |
796 BLACKBIRD_AUDIO_BITS_CRC_OFF |
797 BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF |
798 BLACKBIRD_AUDIO_BITS_COPY |
800 if( params->au_sample_rate <= 32000 )
802 params->au_sample_rate = 32000;
803 au_params |= BLACKBIRD_AUDIO_BITS_32000HZ;
805 else if( params->au_sample_rate <= 44100 )
807 params->au_sample_rate = 44100;
808 au_params |= BLACKBIRD_AUDIO_BITS_44100HZ;
812 params->au_sample_rate = 48000;
813 au_params |= BLACKBIRD_AUDIO_BITS_48000HZ;
815 if( params->au_type == V4L2_MPEG_AU_2_I )
817 au_params |= BLACKBIRD_AUDIO_BITS_LAYER_1;
821 /* TODO: try to handle the other formats more gracefully */
822 params->au_type = V4L2_MPEG_AU_2_II;
823 au_params |= BLACKBIRD_AUDIO_BITS_LAYER_2;
825 if( params->au_bitrate.mode )
829 if( params->au_bitrate.mode == V4L2_BITRATE_CBR )
830 params->au_bitrate.max = params->vi_bitrate.target;
832 params->au_bitrate.target = params->vi_bitrate.max;
834 layer = params->au_type;
835 if( params->au_bitrate.target == 0 )
837 /* TODO: use the minimum possible bitrate instead of 0 ? */
840 else if( params->au_bitrate.target >=
841 mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate )
843 /* clamp the bitrate to the max supported by the standard */
844 params->au_bitrate.target = mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate;
845 params->au_bitrate.max = params->au_bitrate.target;
846 au_params |= mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].bits;
850 /* round up to the nearest supported bitrate */
852 for(i = 1; i < BITRATES_SIZE; i++)
854 if( params->au_bitrate.target > mpeg_audio_bitrates[i-1].layer[layer].rate &&
855 params->au_bitrate.target <= mpeg_audio_bitrates[i].layer[layer].rate )
857 params->au_bitrate.target = mpeg_audio_bitrates[i].layer[layer].rate;
858 params->au_bitrate.max = params->au_bitrate.target;
859 au_params |= mpeg_audio_bitrates[i].layer[layer].bits;
868 params->au_bitrate.target = params->au_bitrate.max = 0;
871 blackbird_api_cmd(dev, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, 0, au_params );
873 /* assign bitrates */
874 if( params->vi_bitrate.mode )
876 /* bitrate is set, let's figure out the cbr/vbr mess */
877 if( params->vi_bitrate.max < params->vi_bitrate.target )
879 if( params->vi_bitrate.mode == V4L2_BITRATE_CBR )
880 params->vi_bitrate.max = params->vi_bitrate.target;
882 params->vi_bitrate.target = params->vi_bitrate.max;
887 if( params->st_bitrate.max < params->st_bitrate.target )
889 if( params->st_bitrate.mode == V4L2_BITRATE_VBR )
890 params->st_bitrate.target = params->st_bitrate.max;
892 params->st_bitrate.max = params->st_bitrate.target;
894 /* calculate vi_bitrate = st_bitrate - au_bitrate */
895 params->vi_bitrate.max = params->st_bitrate.max - params->au_bitrate.max;
896 params->vi_bitrate.target = params->st_bitrate.target - params->au_bitrate.target;
898 blackbird_api_cmd(dev, CX2341X_ENC_SET_BIT_RATE, 4, 0,
899 mpeg_video_bitrates[params->vi_bitrate.mode],
900 params->vi_bitrate.target * 1000, /* kbps -> bps */
901 params->vi_bitrate.max * 1000 / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */
902 BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */
904 /* TODO: implement the stream ID stuff:
905 ts_pid_pmt, ts_pid_audio, ts_pid_video, ts_pid_pcr,
906 ps_size, au_pesid, vi_pesid
909 #define CHECK_PARAM( name ) ( dev->params.name != params->name )
910 #define IF_PARAM( name ) if( CHECK_PARAM( name ) )
911 #define UPDATE_PARAM( name ) dev->params.name = params->name
912 void blackbird_set_params(struct cx8802_dev *dev, struct v4l2_mpeg_compression *params)
916 /* assign stream type */
917 if( params->st_type >= ARRAY_SIZE(mpeg_stream_types) )
918 params->st_type = V4L2_MPEG_PS_2;
919 if( params->st_type == V4L2_MPEG_SS_1 )
920 params->vi_type = V4L2_MPEG_VI_1;
922 params->vi_type = V4L2_MPEG_VI_2;
923 if( CHECK_PARAM( st_type ) || CHECK_PARAM( vi_type ) )
925 UPDATE_PARAM( st_type );
926 UPDATE_PARAM( vi_type );
927 blackbird_api_cmd(dev, CX2341X_ENC_SET_STREAM_TYPE, 1, 0, mpeg_stream_types[params->st_type]);
930 /* assign framerate */
931 if( params->vi_frame_rate <= 25 )
932 params->vi_frame_rate = 25;
934 params->vi_frame_rate = 30;
935 IF_PARAM( vi_frame_rate )
937 UPDATE_PARAM( vi_frame_rate );
938 if( params->vi_frame_rate == 25 )
939 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25);
941 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_NTSC_30);
944 /* assign aspect ratio */
945 if( params->vi_aspect_ratio >= ARRAY_SIZE(mpeg_stream_ratios) )
946 params->vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3;
947 IF_PARAM( vi_aspect_ratio )
949 UPDATE_PARAM( vi_aspect_ratio );
950 blackbird_api_cmd(dev, CX2341X_ENC_SET_ASPECT_RATIO, 1, 0, mpeg_stream_ratios[params->vi_aspect_ratio]);
953 /* assign gop properties */
954 if( CHECK_PARAM( vi_frames_per_gop ) || CHECK_PARAM( vi_bframes_count ) )
956 UPDATE_PARAM( vi_frames_per_gop );
957 UPDATE_PARAM( vi_bframes_count );
958 blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 0, params->vi_frames_per_gop, params->vi_bframes_count+1);
961 /* assign gop closure */
962 IF_PARAM( closed_gops )
964 UPDATE_PARAM( closed_gops );
965 blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_CLOSURE, 1, 0, params->closed_gops);
968 /* assign 3 2 pulldown */
971 UPDATE_PARAM( pulldown );
972 blackbird_api_cmd(dev, CX2341X_ENC_SET_3_2_PULLDOWN, 1, 0, params->pulldown);
975 /* make sure the params are within bounds */
976 if( params->st_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) )
977 params->vi_bitrate.mode = V4L2_BITRATE_NONE;
978 if( params->vi_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) )
979 params->vi_bitrate.mode = V4L2_BITRATE_NONE;
980 if( params->au_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) )
981 params->au_bitrate.mode = V4L2_BITRATE_NONE;
983 /* assign audio properties */
984 /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */
985 au_params = BLACKBIRD_AUDIO_BITS_STEREO |
986 /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */
987 BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE |
988 BLACKBIRD_AUDIO_BITS_CRC_OFF |
989 BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF |
990 BLACKBIRD_AUDIO_BITS_COPY |
992 if( params->au_sample_rate < 32000 )
994 params->au_sample_rate = 32000;
995 au_params |= BLACKBIRD_AUDIO_BITS_32000HZ;
997 else if( params->au_sample_rate < 44100 )
999 params->au_sample_rate = 44100;
1000 au_params |= BLACKBIRD_AUDIO_BITS_44100HZ;
1004 params->au_sample_rate = 48000;
1005 au_params |= BLACKBIRD_AUDIO_BITS_48000HZ;
1007 if( params->au_type == V4L2_MPEG_AU_2_I )
1009 au_params |= BLACKBIRD_AUDIO_BITS_LAYER_1;
1013 /* TODO: try to handle the other formats more gracefully */
1014 params->au_type = V4L2_MPEG_AU_2_II;
1015 au_params |= BLACKBIRD_AUDIO_BITS_LAYER_2;
1017 if( params->au_bitrate.mode )
1021 if( params->au_bitrate.mode == V4L2_BITRATE_CBR )
1022 params->au_bitrate.max = params->vi_bitrate.target;
1024 params->au_bitrate.target = params->vi_bitrate.max;
1026 layer = params->au_type;
1027 if( params->au_bitrate.target == 0 )
1029 /* TODO: use the minimum possible bitrate instead of 0 ? */
1032 else if( params->au_bitrate.target >=
1033 mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate )
1035 /* clamp the bitrate to the max supported by the standard */
1036 params->au_bitrate.target = mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate;
1037 params->au_bitrate.max = params->au_bitrate.target;
1038 au_params |= mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].bits;
1042 /* round up to the nearest supported bitrate */
1044 for(i = 1; i < BITRATES_SIZE; i++)
1046 if( params->au_bitrate.target > mpeg_audio_bitrates[i-1].layer[layer].rate &&
1047 params->au_bitrate.target <= mpeg_audio_bitrates[i].layer[layer].rate )
1049 params->au_bitrate.target = mpeg_audio_bitrates[i].layer[layer].rate;
1050 params->au_bitrate.max = params->au_bitrate.target;
1051 au_params |= mpeg_audio_bitrates[i].layer[layer].bits;
1060 params->au_bitrate.target = params->au_bitrate.max = 0;
1063 if( CHECK_PARAM( au_type ) || CHECK_PARAM( au_sample_rate )
1064 || CHECK_PARAM( au_bitrate.mode ) || CHECK_PARAM( au_bitrate.max )
1065 || CHECK_PARAM( au_bitrate.target )
1068 UPDATE_PARAM( au_type );
1069 UPDATE_PARAM( au_sample_rate );
1070 UPDATE_PARAM( au_bitrate );
1071 blackbird_api_cmd(dev, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, 0, au_params );
1074 /* assign bitrates */
1075 if( params->vi_bitrate.mode )
1077 /* bitrate is set, let's figure out the cbr/vbr mess */
1078 if( params->vi_bitrate.max < params->vi_bitrate.target )
1080 if( params->vi_bitrate.mode == V4L2_BITRATE_CBR )
1081 params->vi_bitrate.max = params->vi_bitrate.target;
1083 params->vi_bitrate.target = params->vi_bitrate.max;
1088 if( params->st_bitrate.max < params->st_bitrate.target )
1090 if( params->st_bitrate.mode == V4L2_BITRATE_VBR )
1091 params->st_bitrate.target = params->st_bitrate.max;
1093 params->st_bitrate.max = params->st_bitrate.target;
1095 /* calculate vi_bitrate = st_bitrate - au_bitrate */
1096 params->vi_bitrate.max = params->st_bitrate.max - params->au_bitrate.max;
1097 params->vi_bitrate.target = params->st_bitrate.target - params->au_bitrate.target;
1099 UPDATE_PARAM( st_bitrate );
1100 if( CHECK_PARAM( vi_bitrate.mode ) || CHECK_PARAM( vi_bitrate.max )
1101 || CHECK_PARAM( vi_bitrate.target )
1104 UPDATE_PARAM( vi_bitrate );
1105 blackbird_api_cmd(dev, CX2341X_ENC_SET_BIT_RATE, 4, 0,
1106 mpeg_video_bitrates[params->vi_bitrate.mode],
1107 params->vi_bitrate.target * 1000, /* kbps -> bps */
1108 params->vi_bitrate.max * 1000 / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */
1109 BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */
1112 /* TODO: implement the stream ID stuff:
1113 ts_pid_pmt, ts_pid_audio, ts_pid_video, ts_pid_pcr,
1114 ps_size, au_pesid, vi_pesid
1116 UPDATE_PARAM( ts_pid_pmt );
1117 UPDATE_PARAM( ts_pid_audio );
1118 UPDATE_PARAM( ts_pid_video );
1119 UPDATE_PARAM( ts_pid_pcr );
1120 UPDATE_PARAM( ps_size );
1121 UPDATE_PARAM( au_pesid );
1122 UPDATE_PARAM( vi_pesid );
1125 static void blackbird_set_default_dnr_params(struct cx8802_dev *dev)
1127 /* assign dnr filter mode */
1128 if( dev->dnr_params.mode > BLACKBIRD_DNR_BITS_AUTO )
1129 dev->dnr_params.mode = BLACKBIRD_DNR_BITS_MANUAL;
1130 if( dev->dnr_params.type > BLACKBIRD_MEDIAN_FILTER_DIAGONAL )
1131 dev->dnr_params.type = BLACKBIRD_MEDIAN_FILTER_DISABLED;
1132 blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 0,
1133 dev->dnr_params.mode,
1134 dev->dnr_params.type
1137 /* assign dnr filter props*/
1138 if( dev->dnr_params.spatial > 15 )
1139 dev->dnr_params.spatial = 15;
1140 if( dev->dnr_params.temporal > 31 )
1141 dev->dnr_params.temporal = 31;
1142 blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 0,
1143 dev->dnr_params.spatial,
1144 dev->dnr_params.temporal
1147 #define CHECK_DNR_PARAM( name ) ( dev->dnr_params.name != dnr_params->name )
1148 #define UPDATE_DNR_PARAM( name ) dev->dnr_params.name = dnr_params->name
1149 void blackbird_set_dnr_params(struct cx8802_dev *dev, struct blackbird_dnr* dnr_params)
1151 /* assign dnr filter mode */
1153 if( dnr_params->mode > BLACKBIRD_DNR_BITS_AUTO )
1154 dnr_params->mode = BLACKBIRD_DNR_BITS_MANUAL;
1155 if( dnr_params->type > BLACKBIRD_MEDIAN_FILTER_DIAGONAL )
1156 dnr_params->type = BLACKBIRD_MEDIAN_FILTER_DISABLED;
1157 /* check if the params actually changed */
1158 if( CHECK_DNR_PARAM( mode ) || CHECK_DNR_PARAM( type ) )
1160 UPDATE_DNR_PARAM( mode );
1161 UPDATE_DNR_PARAM( type );
1162 blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 0, dnr_params->mode, dnr_params->type);
1165 /* assign dnr filter props*/
1166 if( dnr_params->spatial > 15 )
1167 dnr_params->spatial = 15;
1168 if( dnr_params->temporal > 31 )
1169 dnr_params->temporal = 31;
1170 if( CHECK_DNR_PARAM( spatial ) || CHECK_DNR_PARAM( temporal ) )
1172 UPDATE_DNR_PARAM( spatial );
1173 UPDATE_DNR_PARAM( temporal );
1174 blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 0, dnr_params->spatial, dnr_params->temporal);
1178 static void blackbird_codec_settings(struct cx8802_dev *dev)
1181 /* assign output port */
1182 blackbird_api_cmd(dev, CX2341X_ENC_SET_OUTPUT_PORT, 1, 0, BLACKBIRD_OUTPUT_PORT_STREAMING); /* Host */
1184 /* assign frame size */
1185 blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
1186 dev->height, dev->width);
1188 /* assign coring levels (luma_h, luma_l, chroma_h, chroma_l) */
1189 blackbird_api_cmd(dev, CX2341X_ENC_SET_CORING_LEVELS, 4, 0, 0, 255, 0, 255);
1191 /* assign spatial filter type: luma_t: horiz_only, chroma_t: horiz_only */
1192 blackbird_api_cmd(dev, CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, 2, 0,
1193 BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ,
1194 BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ
1197 /* assign frame drop rate */
1198 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAME_DROP_RATE, 1, 0, 0); */
1200 blackbird_set_default_params(dev);
1201 blackbird_set_default_dnr_params(dev);
1204 static int blackbird_initialize_codec(struct cx8802_dev *dev)
1206 struct cx88_core *core = dev->core;
1210 dprintk(1,"Initialize codec\n");
1211 retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
1213 /* ping was not successful, reset and upload firmware */
1214 cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */
1216 cx_write(MO_SRST_IO, 1); /* SYS_RSTO=1 */
1218 retval = blackbird_load_firmware(dev);
1222 dev->mailbox = blackbird_find_mailbox(dev);
1223 if (dev->mailbox < 0)
1226 retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
1228 dprintk(0, "ERROR: Firmware ping failed!\n");
1232 retval = blackbird_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1, &version);
1234 dprintk(0, "ERROR: Firmware get encoder version failed!\n");
1237 dprintk(0, "Firmware version is 0x%08x\n", version);
1241 cx_write(MO_PINMUX_IO, 0x88); /* 656-8bit IO and enable MPEG parallel IO */
1242 cx_clear(MO_INPUT_FORMAT, 0x100); /* chroma subcarrier lock to normal? */
1243 cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */
1244 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */
1246 blackbird_codec_settings(dev);
1249 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xef, 0xef);
1250 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xf0, 0xf0);
1251 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0x180, 0x180); */
1252 blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
1253 BLACKBIRD_FIELD1_SAA7115,
1254 BLACKBIRD_FIELD2_SAA7115
1257 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_PLACEHOLDER, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); */
1258 blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
1259 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
1260 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1262 /* initialize the video input */
1263 blackbird_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0);
1267 blackbird_api_cmd(dev, CX2341X_ENC_MUTE_VIDEO, 1, 0, BLACKBIRD_UNMUTE);
1269 blackbird_api_cmd(dev, CX2341X_ENC_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE);
1272 /* start capturing to the host interface */
1273 /* blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0, 0, 0x13); */
1274 blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
1275 BLACKBIRD_MPEG_CAPTURE,
1276 BLACKBIRD_RAW_BITS_NONE
1280 blackbird_api_cmd(dev, CX2341X_ENC_REFRESH_INPUT, 0,0);
1284 /* ------------------------------------------------------------------ */
1286 static int bb_buf_setup(struct videobuf_queue *q,
1287 unsigned int *count, unsigned int *size)
1289 struct cx8802_fh *fh = q->priv_data;
1291 fh->dev->ts_packet_size = 188 * 4; /* was: 512 */
1292 fh->dev->ts_packet_count = mpegbufs; /* was: 100 */
1294 *size = fh->dev->ts_packet_size * fh->dev->ts_packet_count;
1295 *count = fh->dev->ts_packet_count;
1300 bb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
1301 enum v4l2_field field)
1303 struct cx8802_fh *fh = q->priv_data;
1304 return cx8802_buf_prepare(q, fh->dev, (struct cx88_buffer*)vb, field);
1308 bb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1310 struct cx8802_fh *fh = q->priv_data;
1311 cx8802_buf_queue(fh->dev, (struct cx88_buffer*)vb);
1315 bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1317 cx88_free_buffer(q, (struct cx88_buffer*)vb);
1320 static struct videobuf_queue_ops blackbird_qops = {
1321 .buf_setup = bb_buf_setup,
1322 .buf_prepare = bb_buf_prepare,
1323 .buf_queue = bb_buf_queue,
1324 .buf_release = bb_buf_release,
1327 /* ------------------------------------------------------------------ */
1329 static int mpeg_do_ioctl(struct inode *inode, struct file *file,
1330 unsigned int cmd, void *arg)
1332 struct cx8802_fh *fh = file->private_data;
1333 struct cx8802_dev *dev = fh->dev;
1334 struct cx88_core *core = dev->core;
1337 v4l_print_ioctl(core->name,cmd);
1341 /* --- capabilities ------------------------------------------ */
1342 case VIDIOC_QUERYCAP:
1344 struct v4l2_capability *cap = arg;
1346 memset(cap,0,sizeof(*cap));
1347 strcpy(cap->driver, "cx88_blackbird");
1348 strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
1349 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1350 cap->version = CX88_VERSION_CODE;
1352 V4L2_CAP_VIDEO_CAPTURE |
1353 V4L2_CAP_READWRITE |
1354 V4L2_CAP_STREAMING |
1356 if (UNSET != core->tuner_type)
1357 cap->capabilities |= V4L2_CAP_TUNER;
1362 /* --- capture ioctls ---------------------------------------- */
1363 case VIDIOC_ENUM_FMT:
1365 struct v4l2_fmtdesc *f = arg;
1372 memset(f,0,sizeof(*f));
1374 strlcpy(f->description, "MPEG", sizeof(f->description));
1375 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1376 f->pixelformat = V4L2_PIX_FMT_MPEG;
1381 struct v4l2_format *f = arg;
1383 memset(f,0,sizeof(*f));
1384 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1385 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1386 f->fmt.pix.bytesperline = 0;
1387 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
1388 f->fmt.pix.colorspace = 0;
1389 f->fmt.pix.width = dev->width;
1390 f->fmt.pix.height = dev->height;
1391 f->fmt.pix.field = fh->mpegq.field;
1392 dprintk(0,"VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
1393 dev->width, dev->height, fh->mpegq.field );
1396 case VIDIOC_TRY_FMT:
1398 struct v4l2_format *f = arg;
1400 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1401 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1402 f->fmt.pix.bytesperline = 0;
1403 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
1404 f->fmt.pix.colorspace = 0;
1405 dprintk(0,"VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
1406 dev->width, dev->height, fh->mpegq.field );
1411 struct v4l2_format *f = arg;
1413 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1414 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1415 f->fmt.pix.bytesperline = 0;
1416 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
1417 f->fmt.pix.colorspace = 0;
1418 dprintk(0,"VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
1419 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field );
1423 /* --- streaming capture ------------------------------------- */
1424 case VIDIOC_REQBUFS:
1425 return videobuf_reqbufs(&fh->mpegq, arg);
1427 case VIDIOC_QUERYBUF:
1428 return videobuf_querybuf(&fh->mpegq, arg);
1431 return videobuf_qbuf(&fh->mpegq, arg);
1434 return videobuf_dqbuf(&fh->mpegq, arg,
1435 file->f_flags & O_NONBLOCK);
1437 case VIDIOC_STREAMON:
1438 return videobuf_streamon(&fh->mpegq);
1440 case VIDIOC_STREAMOFF:
1441 return videobuf_streamoff(&fh->mpegq);
1443 /* --- mpeg compression -------------------------------------- */
1444 case VIDIOC_G_MPEGCOMP:
1446 struct v4l2_mpeg_compression *f = arg;
1448 memcpy(f,&dev->params,sizeof(*f));
1451 case VIDIOC_S_MPEGCOMP:
1453 struct v4l2_mpeg_compression *f = arg;
1455 blackbird_set_params(dev, f);
1458 case VIDIOC_S_FREQUENCY:
1460 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1462 BLACKBIRD_MPEG_CAPTURE,
1463 BLACKBIRD_RAW_BITS_NONE);
1465 cx88_do_ioctl( inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook );
1467 blackbird_initialize_codec(dev);
1468 cx88_set_scale(dev->core, dev->width, dev->height,
1474 return cx88_do_ioctl( inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook );
1479 int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
1480 unsigned int cmd, void *arg);
1481 unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
1483 static unsigned int mpeg_translate_ioctl(unsigned int cmd)
1488 static int mpeg_ioctl(struct inode *inode, struct file *file,
1489 unsigned int cmd, unsigned long arg)
1491 cmd = cx88_ioctl_translator( cmd );
1492 return video_usercopy(inode, file, cmd, arg, cx88_ioctl_hook);
1495 static int mpeg_open(struct inode *inode, struct file *file)
1497 int minor = iminor(inode);
1498 struct cx8802_dev *h,*dev = NULL;
1499 struct cx8802_fh *fh;
1500 struct list_head *list;
1502 list_for_each(list,&cx8802_devlist) {
1503 h = list_entry(list, struct cx8802_dev, devlist);
1504 if (h->mpeg_dev->minor == minor)
1510 if (blackbird_initialize_codec(dev) < 0)
1512 dprintk(1,"open minor=%d\n",minor);
1514 /* allocate + initialize per filehandle data */
1515 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1518 file->private_data = fh;
1521 videobuf_queue_init(&fh->mpegq, &blackbird_qops,
1522 dev->pci, &dev->slock,
1523 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1524 V4L2_FIELD_INTERLACED,
1525 sizeof(struct cx88_buffer),
1528 /* FIXME: locking against other video device */
1529 cx88_set_scale(dev->core, dev->width, dev->height,
1535 static int mpeg_release(struct inode *inode, struct file *file)
1537 struct cx8802_fh *fh = file->private_data;
1539 /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
1540 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1542 BLACKBIRD_MPEG_CAPTURE,
1543 BLACKBIRD_RAW_BITS_NONE
1546 cx8802_cancel_buffers(fh->dev);
1547 /* stop mpeg capture */
1548 if (fh->mpegq.streaming)
1549 videobuf_streamoff(&fh->mpegq);
1550 if (fh->mpegq.reading)
1551 videobuf_read_stop(&fh->mpegq);
1553 videobuf_mmap_free(&fh->mpegq);
1554 file->private_data = NULL;
1560 mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1562 struct cx8802_fh *fh = file->private_data;
1564 return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
1565 file->f_flags & O_NONBLOCK);
1569 mpeg_poll(struct file *file, struct poll_table_struct *wait)
1571 struct cx8802_fh *fh = file->private_data;
1573 return videobuf_poll_stream(file, &fh->mpegq, wait);
1577 mpeg_mmap(struct file *file, struct vm_area_struct * vma)
1579 struct cx8802_fh *fh = file->private_data;
1581 return videobuf_mmap_mapper(&fh->mpegq, vma);
1584 static struct file_operations mpeg_fops =
1586 .owner = THIS_MODULE,
1588 .release = mpeg_release,
1592 .ioctl = mpeg_ioctl,
1593 .llseek = no_llseek,
1596 static struct video_device cx8802_mpeg_template =
1599 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
1605 /* ------------------------------------------------------------------ */
1607 static void blackbird_unregister_video(struct cx8802_dev *dev)
1609 if (dev->mpeg_dev) {
1610 if (-1 != dev->mpeg_dev->minor)
1611 video_unregister_device(dev->mpeg_dev);
1613 video_device_release(dev->mpeg_dev);
1614 dev->mpeg_dev = NULL;
1618 static int blackbird_register_video(struct cx8802_dev *dev)
1622 dev->mpeg_dev = cx88_vdev_init(dev->core,dev->pci,
1623 &cx8802_mpeg_template,"mpeg");
1624 err = video_register_device(dev->mpeg_dev,VFL_TYPE_GRABBER, -1);
1626 printk(KERN_INFO "%s/2: can't register mpeg device\n",
1630 printk(KERN_INFO "%s/2: registered device video%d [mpeg]\n",
1631 dev->core->name,dev->mpeg_dev->minor & 0x1f);
1635 /* ----------------------------------------------------------- */
1637 static int __devinit blackbird_probe(struct pci_dev *pci_dev,
1638 const struct pci_device_id *pci_id)
1640 struct cx8802_dev *dev;
1641 struct cx88_core *core;
1645 core = cx88_core_get(pci_dev);
1650 if (!cx88_boards[core->board].blackbird)
1654 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
1661 memcpy(&dev->params,&default_mpeg_params,sizeof(default_mpeg_params));
1662 memcpy(&dev->dnr_params,&default_dnr_params,sizeof(default_dnr_params));
1664 switch (core->board) {
1665 case CX88_BOARD_HAUPPAUGE_ROSLYN:
1666 if (core->tuner_formats & V4L2_STD_525_60) {
1668 dev->params.vi_frame_rate = 30;
1671 dev->params.vi_frame_rate = 25;
1674 case CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT:
1675 if (core->tvnorm->id & V4L2_STD_525_60) {
1677 dev->params.vi_frame_rate = 30;
1680 dev->params.vi_frame_rate = 25;
1685 err = cx8802_init_common(dev);
1689 /* blackbird stuff */
1690 printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",
1692 host_setup(dev->core);
1694 list_add_tail(&dev->devlist,&cx8802_devlist);
1695 blackbird_register_video(dev);
1697 /* initial device configuration: needed ? */
1704 cx88_core_put(core,pci_dev);
1708 static void __devexit blackbird_remove(struct pci_dev *pci_dev)
1710 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
1713 blackbird_unregister_video(dev);
1714 list_del(&dev->devlist);
1717 cx8802_fini_common(dev);
1718 cx88_core_put(dev->core,dev->pci);
1722 static struct pci_device_id cx8802_pci_tbl[] = {
1726 .subvendor = PCI_ANY_ID,
1727 .subdevice = PCI_ANY_ID,
1729 /* --- end of list --- */
1732 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
1734 static struct pci_driver blackbird_pci_driver = {
1735 .name = "cx88-blackbird",
1736 .id_table = cx8802_pci_tbl,
1737 .probe = blackbird_probe,
1738 .remove = __devexit_p(blackbird_remove),
1739 .suspend = cx8802_suspend_common,
1740 .resume = cx8802_resume_common,
1743 static int blackbird_init(void)
1745 printk(KERN_INFO "cx2388x blackbird driver version %d.%d.%d loaded\n",
1746 (CX88_VERSION_CODE >> 16) & 0xff,
1747 (CX88_VERSION_CODE >> 8) & 0xff,
1748 CX88_VERSION_CODE & 0xff);
1750 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
1751 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1753 cx88_ioctl_hook = mpeg_do_ioctl;
1754 cx88_ioctl_translator = mpeg_translate_ioctl;
1755 return pci_register_driver(&blackbird_pci_driver);
1758 static void blackbird_fini(void)
1760 pci_unregister_driver(&blackbird_pci_driver);
1763 module_init(blackbird_init);
1764 module_exit(blackbird_fini);
1766 EXPORT_SYMBOL(cx88_ioctl_hook);
1767 EXPORT_SYMBOL(cx88_ioctl_translator);
1768 EXPORT_SYMBOL(blackbird_set_params);
1769 EXPORT_SYMBOL(blackbird_set_dnr_params);
1771 /* ----------------------------------------------------------- */
1776 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off