aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/ivtv
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/ivtv')
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c13
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h19
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c8
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c4
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c9
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c4
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c36
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c35
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.c31
9 files changed, 83 insertions, 76 deletions
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index efc66355339a..4c93466a89e5 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -181,7 +181,7 @@ MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC");
181MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K"); 181MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K");
182MODULE_PARM_DESC(debug, 182MODULE_PARM_DESC(debug,
183 "Debug level (bitmask). Default: errors only\n" 183 "Debug level (bitmask). Default: errors only\n"
184 "\t\t\t(debug = 511 gives full debugging)"); 184 "\t\t\t(debug = 1023 gives full debugging)");
185MODULE_PARM_DESC(ivtv_pci_latency, 185MODULE_PARM_DESC(ivtv_pci_latency,
186 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" 186 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
187 "\t\t\tDefault: Yes"); 187 "\t\t\tDefault: Yes");
@@ -339,6 +339,7 @@ static void ivtv_process_eeprom(struct ivtv *itv)
339 /* In a few cases the PCI subsystem IDs do not correctly 339 /* In a few cases the PCI subsystem IDs do not correctly
340 identify the card. A better method is to check the 340 identify the card. A better method is to check the
341 model number from the eeprom instead. */ 341 model number from the eeprom instead. */
342 case 30012 ... 30039: /* Low profile PVR250 */
342 case 32000 ... 32999: 343 case 32000 ... 32999:
343 case 48000 ... 48099: /* 48??? range are PVR250s with a cx23415 */ 344 case 48000 ... 48099: /* 48??? range are PVR250s with a cx23415 */
344 case 48400 ... 48599: 345 case 48400 ... 48599:
@@ -622,6 +623,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
622 itv->enc_mbox.max_mbox = 2; /* the encoder has 3 mailboxes (0-2) */ 623 itv->enc_mbox.max_mbox = 2; /* the encoder has 3 mailboxes (0-2) */
623 itv->dec_mbox.max_mbox = 1; /* the decoder has 2 mailboxes (0-1) */ 624 itv->dec_mbox.max_mbox = 1; /* the decoder has 2 mailboxes (0-1) */
624 625
626 mutex_init(&itv->serialize_lock);
625 mutex_init(&itv->i2c_bus_lock); 627 mutex_init(&itv->i2c_bus_lock);
626 mutex_init(&itv->udma.lock); 628 mutex_init(&itv->udma.lock);
627 629
@@ -1288,10 +1290,7 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1288 1290
1289 IVTV_DEBUG_INFO(" Releasing irq.\n"); 1291 IVTV_DEBUG_INFO(" Releasing irq.\n");
1290 free_irq(itv->dev->irq, (void *)itv); 1292 free_irq(itv->dev->irq, (void *)itv);
1291 1293 ivtv_iounmap(itv);
1292 if (itv->dev) {
1293 ivtv_iounmap(itv);
1294 }
1295 1294
1296 IVTV_DEBUG_INFO(" Releasing mem.\n"); 1295 IVTV_DEBUG_INFO(" Releasing mem.\n");
1297 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE); 1296 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
@@ -1326,9 +1325,9 @@ static int module_start(void)
1326 return -1; 1325 return -1;
1327 } 1326 }
1328 1327
1329 if (ivtv_debug < 0 || ivtv_debug > 511) { 1328 if (ivtv_debug < 0 || ivtv_debug > 1023) {
1330 ivtv_debug = 0; 1329 ivtv_debug = 0;
1331 printk(KERN_INFO "ivtv: debug value must be >= 0 and <= 511!\n"); 1330 printk(KERN_INFO "ivtv: debug value must be >= 0 and <= 1023!\n");
1332 } 1331 }
1333 1332
1334 if (pci_register_driver(&ivtv_pci_driver)) { 1333 if (pci_register_driver(&ivtv_pci_driver)) {
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index e6e56f175f3f..6c1a85f1ee1b 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -268,6 +268,8 @@ extern const u32 yuv_offset[4];
268#define IVTV_DBGFLG_IRQ (1 << 6) 268#define IVTV_DBGFLG_IRQ (1 << 6)
269#define IVTV_DBGFLG_DEC (1 << 7) 269#define IVTV_DBGFLG_DEC (1 << 7)
270#define IVTV_DBGFLG_YUV (1 << 8) 270#define IVTV_DBGFLG_YUV (1 << 8)
271/* Flag to turn on high volume debugging */
272#define IVTV_DBGFLG_HIGHVOL (1 << 9)
271 273
272/* NOTE: extra space before comma in 'itv->num , ## args' is required for 274/* NOTE: extra space before comma in 'itv->num , ## args' is required for
273 gcc-2.95, otherwise it won't compile. */ 275 gcc-2.95, otherwise it won't compile. */
@@ -286,6 +288,21 @@ extern const u32 yuv_offset[4];
286#define IVTV_DEBUG_DEC(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args) 288#define IVTV_DEBUG_DEC(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
287#define IVTV_DEBUG_YUV(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 289#define IVTV_DEBUG_YUV(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
288 290
291#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \
292 do { \
293 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \
294 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \
295 } while (0)
296#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warning", fmt , ## args)
297#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info",fmt , ## args)
298#define IVTV_DEBUG_HI_API(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_API, "api", fmt , ## args)
299#define IVTV_DEBUG_HI_DMA(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DMA, "dma", fmt , ## args)
300#define IVTV_DEBUG_HI_IOCTL(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args)
301#define IVTV_DEBUG_HI_I2C(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_I2C, "i2c", fmt , ## args)
302#define IVTV_DEBUG_HI_IRQ(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IRQ, "irq", fmt , ## args)
303#define IVTV_DEBUG_HI_DEC(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
304#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
305
289#define IVTV_FB_DEBUG(x, type, fmt, args...) \ 306#define IVTV_FB_DEBUG(x, type, fmt, args...) \
290 do { \ 307 do { \
291 if ((x) & ivtv_debug) \ 308 if ((x) & ivtv_debug) \
@@ -650,7 +667,6 @@ struct vbi_info {
650 /* convenience pointer to sliced struct in vbi_in union */ 667 /* convenience pointer to sliced struct in vbi_in union */
651 struct v4l2_sliced_vbi_format *sliced_in; 668 struct v4l2_sliced_vbi_format *sliced_in;
652 u32 service_set_in; 669 u32 service_set_in;
653 u32 service_set_out;
654 int insert_mpeg; 670 int insert_mpeg;
655 671
656 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines. 672 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines.
@@ -723,6 +739,7 @@ struct ivtv {
723 int search_pack_header; 739 int search_pack_header;
724 740
725 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */ 741 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */
742 struct mutex serialize_lock; /* lock used to serialize starting streams */
726 743
727 /* User based DMA for OSD */ 744 /* User based DMA for OSD */
728 struct ivtv_user_dma udma; 745 struct ivtv_user_dma udma;
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 555d5e6369c3..ee7e884e9c4f 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -406,7 +406,7 @@ static ssize_t ivtv_read_pos(struct ivtv_stream *s, char __user *ubuf, size_t co
406 ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0; 406 ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0;
407 struct ivtv *itv = s->itv; 407 struct ivtv *itv = s->itv;
408 408
409 IVTV_DEBUG_INFO("read %zd from %s, got %zd\n", count, s->name, rc); 409 IVTV_DEBUG_HI_INFO("read %zd from %s, got %zd\n", count, s->name, rc);
410 if (rc > 0) 410 if (rc > 0)
411 pos += rc; 411 pos += rc;
412 return rc; 412 return rc;
@@ -497,7 +497,7 @@ ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_
497 struct ivtv_stream *s = &itv->streams[id->type]; 497 struct ivtv_stream *s = &itv->streams[id->type];
498 int rc; 498 int rc;
499 499
500 IVTV_DEBUG_IOCTL("read %zd bytes from %s\n", count, s->name); 500 IVTV_DEBUG_HI_IOCTL("read %zd bytes from %s\n", count, s->name);
501 501
502 rc = ivtv_start_capture(id); 502 rc = ivtv_start_capture(id);
503 if (rc) 503 if (rc)
@@ -535,7 +535,7 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
535 int rc; 535 int rc;
536 DEFINE_WAIT(wait); 536 DEFINE_WAIT(wait);
537 537
538 IVTV_DEBUG_IOCTL("write %zd bytes to %s\n", count, s->name); 538 IVTV_DEBUG_HI_IOCTL("write %zd bytes to %s\n", count, s->name);
539 539
540 if (s->type != IVTV_DEC_STREAM_TYPE_MPG && 540 if (s->type != IVTV_DEC_STREAM_TYPE_MPG &&
541 s->type != IVTV_DEC_STREAM_TYPE_YUV && 541 s->type != IVTV_DEC_STREAM_TYPE_YUV &&
@@ -643,7 +643,7 @@ retry:
643 to transfer the rest. */ 643 to transfer the rest. */
644 if (count && !(filp->f_flags & O_NONBLOCK)) 644 if (count && !(filp->f_flags & O_NONBLOCK))
645 goto retry; 645 goto retry;
646 IVTV_DEBUG_INFO("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused); 646 IVTV_DEBUG_HI_INFO("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused);
647 return bytes_written; 647 return bytes_written;
648} 648}
649 649
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index d4c910b782af..2b6208a6a108 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -56,9 +56,7 @@ retry:
56 volatile u32 __iomem *dst = (volatile u32 __iomem *)mem; 56 volatile u32 __iomem *dst = (volatile u32 __iomem *)mem;
57 const u32 *src = (const u32 *)fw->data; 57 const u32 *src = (const u32 *)fw->data;
58 58
59 /* temporarily allow 256 KB encoding firmwares as well for 59 if (fw->size != size) {
60 compatibility with blackbird cards */
61 if (fw->size != size && fw->size != 256 * 1024) {
62 /* Due to race conditions in firmware loading (esp. with udev <0.95) 60 /* Due to race conditions in firmware loading (esp. with udev <0.95)
63 the wrong file was sometimes loaded. So we check filesizes to 61 the wrong file was sometimes loaded. So we check filesizes to
64 see if at least the right-sized file was loaded. If not, then we 62 see if at least the right-sized file was loaded. If not, then we
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index bc8f8ca2961f..676418cbaaad 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -115,8 +115,7 @@ void ivtv_reset_ir_gpio(struct ivtv *itv)
115 curout = (curout & ~0xF) | 1; 115 curout = (curout & ~0xF) | 1;
116 write_reg(curout, IVTV_REG_GPIO_OUT); 116 write_reg(curout, IVTV_REG_GPIO_OUT);
117 /* We could use something else for smaller time */ 117 /* We could use something else for smaller time */
118 current->state = TASK_INTERRUPTIBLE; 118 schedule_timeout_interruptible(msecs_to_jiffies(1));
119 schedule_timeout(1);
120 curout |= 2; 119 curout |= 2;
121 write_reg(curout, IVTV_REG_GPIO_OUT); 120 write_reg(curout, IVTV_REG_GPIO_OUT);
122 curdir &= ~0x80; 121 curdir &= ~0x80;
@@ -138,13 +137,11 @@ int ivtv_reset_tuner_gpio(enum v4l2_tuner_type mode, void *priv, int ptr)
138 137
139 curout &= ~(1 << 12); 138 curout &= ~(1 << 12);
140 write_reg(curout, IVTV_REG_GPIO_OUT); 139 write_reg(curout, IVTV_REG_GPIO_OUT);
141 current->state = TASK_INTERRUPTIBLE; 140 schedule_timeout_interruptible(msecs_to_jiffies(1));
142 schedule_timeout(1);
143 141
144 curout |= (1 << 12); 142 curout |= (1 << 12);
145 write_reg(curout, IVTV_REG_GPIO_OUT); 143 write_reg(curout, IVTV_REG_GPIO_OUT);
146 current->state = TASK_INTERRUPTIBLE; 144 schedule_timeout_interruptible(msecs_to_jiffies(1));
147 schedule_timeout(1);
148 145
149 return 0; 146 return 0;
150} 147}
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 57af1762de1f..4773453e8dab 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -1159,7 +1159,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1159 1159
1160 memset(fb, 0, sizeof(*fb)); 1160 memset(fb, 0, sizeof(*fb));
1161 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) 1161 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1162 break; 1162 return -EINVAL;
1163 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY | 1163 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY |
1164 V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_GLOBAL_ALPHA; 1164 V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_GLOBAL_ALPHA;
1165 fb->fmt.pixelformat = itv->osd_pixelformat; 1165 fb->fmt.pixelformat = itv->osd_pixelformat;
@@ -1179,7 +1179,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1179 struct v4l2_framebuffer *fb = arg; 1179 struct v4l2_framebuffer *fb = arg;
1180 1180
1181 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) 1181 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1182 break; 1182 return -EINVAL;
1183 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0; 1183 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0;
1184 itv->osd_local_alpha_state = (fb->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) != 0; 1184 itv->osd_local_alpha_state = (fb->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) != 0;
1185 itv->osd_color_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0; 1185 itv->osd_color_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0;
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index ba98bf054f2e..1a3ee464a826 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -48,7 +48,7 @@ static void ivtv_pio_work_handler(struct ivtv *itv)
48 struct list_head *p; 48 struct list_head *p;
49 int i = 0; 49 int i = 0;
50 50
51 IVTV_DEBUG_DMA("ivtv_pio_work_handler\n"); 51 IVTV_DEBUG_HI_DMA("ivtv_pio_work_handler\n");
52 if (itv->cur_pio_stream < 0 || itv->cur_pio_stream >= IVTV_MAX_STREAMS || 52 if (itv->cur_pio_stream < 0 || itv->cur_pio_stream >= IVTV_MAX_STREAMS ||
53 s->v4l2dev == NULL || !ivtv_use_pio(s)) { 53 s->v4l2dev == NULL || !ivtv_use_pio(s)) {
54 itv->cur_pio_stream = -1; 54 itv->cur_pio_stream = -1;
@@ -56,7 +56,7 @@ static void ivtv_pio_work_handler(struct ivtv *itv)
56 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44); 56 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44);
57 return; 57 return;
58 } 58 }
59 IVTV_DEBUG_DMA("Process PIO %s\n", s->name); 59 IVTV_DEBUG_HI_DMA("Process PIO %s\n", s->name);
60 buf = list_entry(s->q_dma.list.next, struct ivtv_buffer, list); 60 buf = list_entry(s->q_dma.list.next, struct ivtv_buffer, list);
61 list_for_each(p, &s->q_dma.list) { 61 list_for_each(p, &s->q_dma.list) {
62 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list); 62 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list);
@@ -187,7 +187,7 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
187 bytes_needed += UVsize; 187 bytes_needed += UVsize;
188 } 188 }
189 189
190 IVTV_DEBUG_DMA("%s %s: 0x%08x bytes at 0x%08x\n", 190 IVTV_DEBUG_HI_DMA("%s %s: 0x%08x bytes at 0x%08x\n",
191 ivtv_use_pio(s) ? "PIO" : "DMA", s->name, bytes_needed, offset); 191 ivtv_use_pio(s) ? "PIO" : "DMA", s->name, bytes_needed, offset);
192 192
193 rc = ivtv_queue_move(s, &s->q_free, &s->q_full, &s->q_predma, bytes_needed); 193 rc = ivtv_queue_move(s, &s->q_free, &s->q_full, &s->q_predma, bytes_needed);
@@ -242,7 +242,7 @@ static void dma_post(struct ivtv_stream *s)
242 u32 *u32buf; 242 u32 *u32buf;
243 int x = 0; 243 int x = 0;
244 244
245 IVTV_DEBUG_DMA("%s %s completed (%x)\n", ivtv_use_pio(s) ? "PIO" : "DMA", 245 IVTV_DEBUG_HI_DMA("%s %s completed (%x)\n", ivtv_use_pio(s) ? "PIO" : "DMA",
246 s->name, s->dma_offset); 246 s->name, s->dma_offset);
247 list_for_each(p, &s->q_dma.list) { 247 list_for_each(p, &s->q_dma.list) {
248 buf = list_entry(p, struct ivtv_buffer, list); 248 buf = list_entry(p, struct ivtv_buffer, list);
@@ -321,7 +321,7 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
321 unsigned long flags = 0; 321 unsigned long flags = 0;
322 int idx = 0; 322 int idx = 0;
323 323
324 IVTV_DEBUG_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset); 324 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset);
325 buf = list_entry(s->q_predma.list.next, struct ivtv_buffer, list); 325 buf = list_entry(s->q_predma.list.next, struct ivtv_buffer, list);
326 list_for_each(p, &s->q_predma.list) { 326 list_for_each(p, &s->q_predma.list) {
327 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list); 327 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list);
@@ -368,7 +368,7 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
368 struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; 368 struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
369 int i; 369 int i;
370 370
371 IVTV_DEBUG_DMA("start %s for %s\n", ivtv_use_dma(s) ? "DMA" : "PIO", s->name); 371 IVTV_DEBUG_HI_DMA("start %s for %s\n", ivtv_use_dma(s) ? "DMA" : "PIO", s->name);
372 372
373 if (s->q_predma.bytesused) 373 if (s->q_predma.bytesused)
374 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused); 374 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused);
@@ -397,7 +397,7 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
397 itv->vbi.dma_offset = s_vbi->dma_offset; 397 itv->vbi.dma_offset = s_vbi->dma_offset;
398 s_vbi->SG_length = 0; 398 s_vbi->SG_length = 0;
399 set_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags); 399 set_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags);
400 IVTV_DEBUG_DMA("include DMA for %s\n", s->name); 400 IVTV_DEBUG_HI_DMA("include DMA for %s\n", s->name);
401 } 401 }
402 402
403 /* Mark last buffer size for Interrupt flag */ 403 /* Mark last buffer size for Interrupt flag */
@@ -431,7 +431,7 @@ static void ivtv_dma_dec_start(struct ivtv_stream *s)
431 431
432 if (s->q_predma.bytesused) 432 if (s->q_predma.bytesused)
433 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused); 433 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused);
434 IVTV_DEBUG_DMA("start DMA for %s\n", s->name); 434 IVTV_DEBUG_HI_DMA("start DMA for %s\n", s->name);
435 /* put SG Handle into register 0x0c */ 435 /* put SG Handle into register 0x0c */
436 write_reg(s->SG_handle, IVTV_REG_DECDMAADDR); 436 write_reg(s->SG_handle, IVTV_REG_DECDMAADDR);
437 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER); 437 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER);
@@ -447,7 +447,7 @@ static void ivtv_irq_dma_read(struct ivtv *itv)
447 struct ivtv_buffer *buf; 447 struct ivtv_buffer *buf;
448 int hw_stream_type; 448 int hw_stream_type;
449 449
450 IVTV_DEBUG_IRQ("DEC DMA READ\n"); 450 IVTV_DEBUG_HI_IRQ("DEC DMA READ\n");
451 del_timer(&itv->dma_timer); 451 del_timer(&itv->dma_timer);
452 if (read_reg(IVTV_REG_DMASTATUS) & 0x14) { 452 if (read_reg(IVTV_REG_DMASTATUS) & 0x14) {
453 IVTV_DEBUG_WARN("DEC DMA ERROR %x\n", read_reg(IVTV_REG_DMASTATUS)); 453 IVTV_DEBUG_WARN("DEC DMA ERROR %x\n", read_reg(IVTV_REG_DMASTATUS));
@@ -462,7 +462,7 @@ static void ivtv_irq_dma_read(struct ivtv *itv)
462 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG]; 462 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
463 hw_stream_type = 0; 463 hw_stream_type = 0;
464 } 464 }
465 IVTV_DEBUG_DMA("DEC DATA READ %s: %d\n", s->name, s->q_dma.bytesused); 465 IVTV_DEBUG_HI_DMA("DEC DATA READ %s: %d\n", s->name, s->q_dma.bytesused);
466 466
467 ivtv_stream_sync_for_cpu(s); 467 ivtv_stream_sync_for_cpu(s);
468 468
@@ -495,7 +495,7 @@ static void ivtv_irq_enc_dma_complete(struct ivtv *itv)
495 495
496 del_timer(&itv->dma_timer); 496 del_timer(&itv->dma_timer);
497 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data); 497 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data);
498 IVTV_DEBUG_IRQ("ENC DMA COMPLETE %x %d\n", data[0], data[1]); 498 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d\n", data[0], data[1]);
499 if (test_and_clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags)) 499 if (test_and_clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags))
500 data[1] = 3; 500 data[1] = 3;
501 else if (data[1] > 2) 501 else if (data[1] > 2)
@@ -532,7 +532,7 @@ static void ivtv_irq_enc_pio_complete(struct ivtv *itv)
532 return; 532 return;
533 } 533 }
534 s = &itv->streams[itv->cur_pio_stream]; 534 s = &itv->streams[itv->cur_pio_stream];
535 IVTV_DEBUG_IRQ("ENC PIO COMPLETE %s\n", s->name); 535 IVTV_DEBUG_HI_IRQ("ENC PIO COMPLETE %s\n", s->name);
536 s->SG_length = 0; 536 s->SG_length = 0;
537 clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags); 537 clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags);
538 clear_bit(IVTV_F_I_PIO, &itv->i_flags); 538 clear_bit(IVTV_F_I_PIO, &itv->i_flags);
@@ -590,7 +590,7 @@ static void ivtv_irq_enc_start_cap(struct ivtv *itv)
590 590
591 /* Get DMA destination and size arguments from card */ 591 /* Get DMA destination and size arguments from card */
592 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA, data); 592 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA, data);
593 IVTV_DEBUG_IRQ("ENC START CAP %d: %08x %08x\n", data[0], data[1], data[2]); 593 IVTV_DEBUG_HI_IRQ("ENC START CAP %d: %08x %08x\n", data[0], data[1], data[2]);
594 594
595 if (data[0] > 2 || data[1] == 0 || data[2] == 0) { 595 if (data[0] > 2 || data[1] == 0 || data[2] == 0) {
596 IVTV_DEBUG_WARN("Unknown input: %08x %08x %08x\n", 596 IVTV_DEBUG_WARN("Unknown input: %08x %08x %08x\n",
@@ -610,7 +610,7 @@ static void ivtv_irq_enc_vbi_cap(struct ivtv *itv)
610 u32 data[CX2341X_MBOX_MAX_DATA]; 610 u32 data[CX2341X_MBOX_MAX_DATA];
611 struct ivtv_stream *s; 611 struct ivtv_stream *s;
612 612
613 IVTV_DEBUG_IRQ("ENC START VBI CAP\n"); 613 IVTV_DEBUG_HI_IRQ("ENC START VBI CAP\n");
614 s = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; 614 s = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
615 615
616 /* If more than two VBI buffers are pending, then 616 /* If more than two VBI buffers are pending, then
@@ -644,7 +644,7 @@ static void ivtv_irq_dec_vbi_reinsert(struct ivtv *itv)
644 u32 data[CX2341X_MBOX_MAX_DATA]; 644 u32 data[CX2341X_MBOX_MAX_DATA];
645 struct ivtv_stream *s = &itv->streams[IVTV_DEC_STREAM_TYPE_VBI]; 645 struct ivtv_stream *s = &itv->streams[IVTV_DEC_STREAM_TYPE_VBI];
646 646
647 IVTV_DEBUG_IRQ("DEC VBI REINSERT\n"); 647 IVTV_DEBUG_HI_IRQ("DEC VBI REINSERT\n");
648 if (test_bit(IVTV_F_S_CLAIMED, &s->s_flags) && 648 if (test_bit(IVTV_F_S_CLAIMED, &s->s_flags) &&
649 !stream_enc_dma_append(s, data)) { 649 !stream_enc_dma_append(s, data)) {
650 set_bit(IVTV_F_S_PIO_PENDING, &s->s_flags); 650 set_bit(IVTV_F_S_PIO_PENDING, &s->s_flags);
@@ -669,7 +669,7 @@ static void ivtv_irq_dec_data_req(struct ivtv *itv)
669 itv->dma_data_req_offset = data[1]; 669 itv->dma_data_req_offset = data[1];
670 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG]; 670 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
671 } 671 }
672 IVTV_DEBUG_IRQ("DEC DATA REQ %s: %d %08x %u\n", s->name, s->q_full.bytesused, 672 IVTV_DEBUG_HI_IRQ("DEC DATA REQ %s: %d %08x %u\n", s->name, s->q_full.bytesused,
673 itv->dma_data_req_offset, itv->dma_data_req_size); 673 itv->dma_data_req_offset, itv->dma_data_req_size);
674 if (itv->dma_data_req_size == 0 || s->q_full.bytesused < itv->dma_data_req_size) { 674 if (itv->dma_data_req_size == 0 || s->q_full.bytesused < itv->dma_data_req_size) {
675 set_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags); 675 set_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags);
@@ -791,10 +791,10 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
791 /* Exclude interrupts noted below from the output, otherwise the log is flooded with 791 /* Exclude interrupts noted below from the output, otherwise the log is flooded with
792 these messages */ 792 these messages */
793 if (combo & ~0xff6d0400) 793 if (combo & ~0xff6d0400)
794 IVTV_DEBUG_IRQ("======= valid IRQ bits: 0x%08x ======\n", combo); 794 IVTV_DEBUG_HI_IRQ("======= valid IRQ bits: 0x%08x ======\n", combo);
795 795
796 if (combo & IVTV_IRQ_DEC_DMA_COMPLETE) { 796 if (combo & IVTV_IRQ_DEC_DMA_COMPLETE) {
797 IVTV_DEBUG_IRQ("DEC DMA COMPLETE\n"); 797 IVTV_DEBUG_HI_IRQ("DEC DMA COMPLETE\n");
798 } 798 }
799 799
800 if (combo & IVTV_IRQ_DMA_READ) { 800 if (combo & IVTV_IRQ_DMA_READ) {
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 6af88ae9295f..287117187499 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -446,6 +446,9 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
446 if (s->v4l2dev == NULL) 446 if (s->v4l2dev == NULL)
447 return -EINVAL; 447 return -EINVAL;
448 448
449 /* Big serialization lock to ensure no two streams are started
450 simultaneously: that can give all sorts of weird results. */
451 mutex_lock(&itv->serialize_lock);
449 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name); 452 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name);
450 453
451 switch (s->type) { 454 switch (s->type) {
@@ -487,6 +490,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
487 0, sizeof(itv->vbi.sliced_mpeg_size)); 490 0, sizeof(itv->vbi.sliced_mpeg_size));
488 break; 491 break;
489 default: 492 default:
493 mutex_unlock(&itv->serialize_lock);
490 return -EINVAL; 494 return -EINVAL;
491 } 495 }
492 s->subtype = subtype; 496 s->subtype = subtype;
@@ -568,6 +572,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
568 if (ivtv_vapi(itv, CX2341X_ENC_START_CAPTURE, 2, captype, subtype)) 572 if (ivtv_vapi(itv, CX2341X_ENC_START_CAPTURE, 2, captype, subtype))
569 { 573 {
570 IVTV_DEBUG_WARN( "Error starting capture!\n"); 574 IVTV_DEBUG_WARN( "Error starting capture!\n");
575 mutex_unlock(&itv->serialize_lock);
571 return -EINVAL; 576 return -EINVAL;
572 } 577 }
573 578
@@ -583,6 +588,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
583 588
584 /* you're live! sit back and await interrupts :) */ 589 /* you're live! sit back and await interrupts :) */
585 atomic_inc(&itv->capturing); 590 atomic_inc(&itv->capturing);
591 mutex_unlock(&itv->serialize_lock);
586 return 0; 592 return 0;
587} 593}
588 594
@@ -762,17 +768,6 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
762 /* when: 0 = end of GOP 1 = NOW!, type: 0 = mpeg, subtype: 3 = video+audio */ 768 /* when: 0 = end of GOP 1 = NOW!, type: 0 = mpeg, subtype: 3 = video+audio */
763 ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, stopmode, cap_type, s->subtype); 769 ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, stopmode, cap_type, s->subtype);
764 770
765 /* only run these if we're shutting down the last cap */
766 if (atomic_read(&itv->capturing) - 1 == 0) {
767 /* event notification (off) */
768 if (test_and_clear_bit(IVTV_F_I_DIG_RST, &itv->i_flags)) {
769 /* type: 0 = refresh */
770 /* on/off: 0 = off, intr: 0x10000000, mbox_id: -1: none */
771 ivtv_vapi(itv, CX2341X_ENC_SET_EVENT_NOTIFICATION, 4, 0, 0, IVTV_IRQ_ENC_VIM_RST, -1);
772 ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VIM_RST);
773 }
774 }
775
776 then = jiffies; 771 then = jiffies;
777 772
778 if (!test_bit(IVTV_F_S_PASSTHROUGH, &s->s_flags)) { 773 if (!test_bit(IVTV_F_S_PASSTHROUGH, &s->s_flags)) {
@@ -812,7 +807,6 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
812 then = jiffies; 807 then = jiffies;
813 /* Make sure DMA is complete */ 808 /* Make sure DMA is complete */
814 add_wait_queue(&s->waitq, &wait); 809 add_wait_queue(&s->waitq, &wait);
815 set_current_state(TASK_INTERRUPTIBLE);
816 do { 810 do {
817 /* check if DMA is pending */ 811 /* check if DMA is pending */
818 if ((s->type == IVTV_ENC_STREAM_TYPE_MPG) && /* MPG Only */ 812 if ((s->type == IVTV_ENC_STREAM_TYPE_MPG) && /* MPG Only */
@@ -827,9 +821,7 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
827 } else if (read_reg(IVTV_REG_DMASTATUS) & 0x02) { 821 } else if (read_reg(IVTV_REG_DMASTATUS) & 0x02) {
828 break; 822 break;
829 } 823 }
830 824 } while (!ivtv_sleep_timeout(HZ / 100, 1) && then + HZ * 2 > jiffies);
831 ivtv_sleep_timeout(HZ / 100, 1);
832 } while (then + HZ * 2 > jiffies);
833 825
834 set_current_state(TASK_RUNNING); 826 set_current_state(TASK_RUNNING);
835 remove_wait_queue(&s->waitq, &wait); 827 remove_wait_queue(&s->waitq, &wait);
@@ -840,17 +832,30 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
840 /* Clear capture and no-read bits */ 832 /* Clear capture and no-read bits */
841 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); 833 clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
842 834
835 /* ensure these global cleanup actions are done only once */
836 mutex_lock(&itv->serialize_lock);
837
843 if (s->type == IVTV_ENC_STREAM_TYPE_VBI) 838 if (s->type == IVTV_ENC_STREAM_TYPE_VBI)
844 ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VBI_CAP); 839 ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VBI_CAP);
845 840
846 if (atomic_read(&itv->capturing) > 0) { 841 if (atomic_read(&itv->capturing) > 0) {
842 mutex_unlock(&itv->serialize_lock);
847 return 0; 843 return 0;
848 } 844 }
849 845
850 /* Set the following Interrupt mask bits for capture */ 846 /* Set the following Interrupt mask bits for capture */
851 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE); 847 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
852 848
849 /* event notification (off) */
850 if (test_and_clear_bit(IVTV_F_I_DIG_RST, &itv->i_flags)) {
851 /* type: 0 = refresh */
852 /* on/off: 0 = off, intr: 0x10000000, mbox_id: -1: none */
853 ivtv_vapi(itv, CX2341X_ENC_SET_EVENT_NOTIFICATION, 4, 0, 0, IVTV_IRQ_ENC_VIM_RST, -1);
854 ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VIM_RST);
855 }
856
853 wake_up(&s->waitq); 857 wake_up(&s->waitq);
858 mutex_unlock(&itv->serialize_lock);
854 859
855 return 0; 860 return 0;
856} 861}
diff --git a/drivers/media/video/ivtv/ivtv-vbi.c b/drivers/media/video/ivtv/ivtv-vbi.c
index 3ba46e07ea1f..a7282a91bd97 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.c
+++ b/drivers/media/video/ivtv/ivtv-vbi.c
@@ -219,31 +219,23 @@ ssize_t ivtv_write_vbi(struct ivtv *itv, const char __user *ubuf, size_t count)
219 int found_cc = 0; 219 int found_cc = 0;
220 int cc_pos = itv->vbi.cc_pos; 220 int cc_pos = itv->vbi.cc_pos;
221 221
222 if (itv->vbi.service_set_out == 0)
223 return -EPERM;
224
225 while (count >= sizeof(struct v4l2_sliced_vbi_data)) { 222 while (count >= sizeof(struct v4l2_sliced_vbi_data)) {
226 switch (p->id) { 223 switch (p->id) {
227 case V4L2_SLICED_CAPTION_525: 224 case V4L2_SLICED_CAPTION_525:
228 if (p->id == V4L2_SLICED_CAPTION_525 && 225 if (p->line == 21) {
229 p->line == 21 && 226 found_cc = 1;
230 (itv->vbi.service_set_out & 227 if (p->field) {
231 V4L2_SLICED_CAPTION_525) == 0) { 228 cc[2] = p->data[0];
232 break; 229 cc[3] = p->data[1];
233 } 230 } else {
234 found_cc = 1; 231 cc[0] = p->data[0];
235 if (p->field) { 232 cc[1] = p->data[1];
236 cc[2] = p->data[0]; 233 }
237 cc[3] = p->data[1];
238 } else {
239 cc[0] = p->data[0];
240 cc[1] = p->data[1];
241 } 234 }
242 break; 235 break;
243 236
244 case V4L2_SLICED_VPS: 237 case V4L2_SLICED_VPS:
245 if (p->line == 16 && p->field == 0 && 238 if (p->line == 16 && p->field == 0) {
246 (itv->vbi.service_set_out & V4L2_SLICED_VPS)) {
247 itv->vbi.vps[0] = p->data[2]; 239 itv->vbi.vps[0] = p->data[2];
248 itv->vbi.vps[1] = p->data[8]; 240 itv->vbi.vps[1] = p->data[8];
249 itv->vbi.vps[2] = p->data[9]; 241 itv->vbi.vps[2] = p->data[9];
@@ -255,8 +247,7 @@ ssize_t ivtv_write_vbi(struct ivtv *itv, const char __user *ubuf, size_t count)
255 break; 247 break;
256 248
257 case V4L2_SLICED_WSS_625: 249 case V4L2_SLICED_WSS_625:
258 if (p->line == 23 && p->field == 0 && 250 if (p->line == 23 && p->field == 0) {
259 (itv->vbi.service_set_out & V4L2_SLICED_WSS_625)) {
260 /* No lock needed for WSS */ 251 /* No lock needed for WSS */
261 itv->vbi.wss = p->data[0] | (p->data[1] << 8); 252 itv->vbi.wss = p->data[0] | (p->data[1] << 8);
262 itv->vbi.wss_found = 1; 253 itv->vbi.wss_found = 1;