
From: Michael Hunold <hunold@linuxtv.org>

- saa7146: prefix IER_DISABLE and IER_ENABLE with SAA7146_, add
  SAA7146_ISR_CLEAR

- dvb-bt8xx/dst: fix typo

- cinergyT2: locking in SET_PARAMETERS and some VDR compatibility code for
  GET_EVENT (thanks to Stefan Lucke)

Signed-off-by: Michael Hunold <hunold@linuxtv.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/media/common/saa7146_core.c     |    4 +-
 25-akpm/drivers/media/common/saa7146_i2c.c      |    2 -
 25-akpm/drivers/media/common/saa7146_vbi.c      |    8 ++--
 25-akpm/drivers/media/common/saa7146_video.c    |    4 +-
 25-akpm/drivers/media/dvb/bt8xx/dst.c           |    4 +-
 25-akpm/drivers/media/dvb/cinergyT2/cinergyT2.c |   43 ++++++++++++++++++++----
 25-akpm/include/media/saa7146.h                 |    6 ++-
 7 files changed, 52 insertions(+), 19 deletions(-)

diff -puN drivers/media/common/saa7146_core.c~dvb-saa7146-driver-misc-updates drivers/media/common/saa7146_core.c
--- 25/drivers/media/common/saa7146_core.c~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/drivers/media/common/saa7146_core.c	Fri Dec 10 15:14:10 2004
@@ -292,7 +292,7 @@ static irqreturn_t interrupt_hw(int irq,
 	if (0 != (isr & (MASK_16|MASK_17))) {
 		u32 status = saa7146_read(dev, I2C_STATUS);
 		if( (0x3 == (status & 0x3)) || (0 == (status & 0x1)) ) {
-			IER_DISABLE(dev, MASK_16|MASK_17);
+			SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
 			/* only wake up if we expect something */
 			if( 0 != dev->i2c_op ) {
 				u32 psr = (saa7146_read(dev, PSR) >> 16) & 0x2;
@@ -311,7 +311,7 @@ static irqreturn_t interrupt_hw(int irq,
 	if( 0 != isr ) {
 		ERR(("warning: interrupt enabled, but not handled properly.(0x%08x)\n",isr));
 		ERR(("disabling interrupt source(s)!\n"));
-		IER_DISABLE(dev,isr);
+		SAA7146_IER_DISABLE(dev,isr);
 	}
 	return IRQ_HANDLED;
 }
diff -puN drivers/media/common/saa7146_i2c.c~dvb-saa7146-driver-misc-updates drivers/media/common/saa7146_i2c.c
--- 25/drivers/media/common/saa7146_i2c.c~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/drivers/media/common/saa7146_i2c.c	Fri Dec 10 15:14:10 2004
@@ -190,7 +190,7 @@ static int saa7146_i2c_writeout(struct s
 		saa7146_write(dev, I2C_TRANSFER, *dword);
 
 		dev->i2c_op = 1;
-		IER_ENABLE(dev, MASK_16|MASK_17);
+		SAA7146_IER_ENABLE(dev, MASK_16|MASK_17);
 		saa7146_write(dev, MC2, (MASK_00 | MASK_16));
 
 		wait_event_interruptible(dev->i2c_wq, dev->i2c_op == 0);
diff -puN drivers/media/common/saa7146_vbi.c~dvb-saa7146-driver-misc-updates drivers/media/common/saa7146_vbi.c
--- 25/drivers/media/common/saa7146_vbi.c~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/drivers/media/common/saa7146_vbi.c	Fri Dec 10 15:14:10 2004
@@ -91,7 +91,7 @@ static int vbi_workaround(struct saa7146
 		saa7146_write(dev, MC2, MASK_04|MASK_20);
 	
 		/* enable rps1 irqs */
-		IER_ENABLE(dev,MASK_28);
+		SAA7146_IER_ENABLE(dev,MASK_28);
 
 		/* prepare to wait to be woken up by the irq-handler */
 		add_wait_queue(&vv->vbi_wq, &wait);
@@ -109,7 +109,7 @@ static int vbi_workaround(struct saa7146
 		current->state = TASK_RUNNING;
 
 		/* disable rps1 irqs */
-		IER_DISABLE(dev,MASK_28);
+		SAA7146_IER_DISABLE(dev,MASK_28);
 
 		/* stop video-dma3 */
 		saa7146_write(dev, MC1, MASK_20);
@@ -190,7 +190,7 @@ static void saa7146_set_vbi_capture(stru
 	WRITE_RPS1(CMD_STOP);					
 
 	/* enable rps1 irqs */
-	IER_ENABLE(dev, MASK_28);
+	SAA7146_IER_ENABLE(dev, MASK_28);
 
 	/* write the address of the rps-program */
 	saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
@@ -325,7 +325,7 @@ static void vbi_stop(struct saa7146_fh *
 	saa7146_write(dev, MC1, MASK_29);
 
 	/* disable rps1 irqs */
-	IER_DISABLE(dev, MASK_28);
+	SAA7146_IER_DISABLE(dev, MASK_28);
 
 	/* shut down dma 3 transfers */
 	saa7146_write(dev, MC1, MASK_20);
diff -puN drivers/media/common/saa7146_video.c~dvb-saa7146-driver-misc-updates drivers/media/common/saa7146_video.c
--- 25/drivers/media/common/saa7146_video.c~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/drivers/media/common/saa7146_video.c	Fri Dec 10 15:14:10 2004
@@ -760,7 +760,7 @@ static int video_begin(struct saa7146_fh
 	saa7146_write(dev, MC2, MASK_27 );
 
 	/* enable rps0 irqs */
-	IER_ENABLE(dev, MASK_27);
+	SAA7146_IER_ENABLE(dev, MASK_27);
 
 	vv->video_fh = fh;
 	vv->video_status = STATUS_CAPTURE;
@@ -805,7 +805,7 @@ static int video_end(struct saa7146_fh *
 	saa7146_write(dev, MC1, MASK_28);
 
 	/* disable rps0 irqs */
-	IER_DISABLE(dev, MASK_27);
+	SAA7146_IER_DISABLE(dev, MASK_27);
 
 	/* shut down all used video dma transfers */
 	saa7146_write(dev, MC1, dmas);
diff -puN drivers/media/dvb/bt8xx/dst.c~dvb-saa7146-driver-misc-updates drivers/media/dvb/bt8xx/dst.c
--- 25/drivers/media/dvb/bt8xx/dst.c~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/drivers/media/dvb/bt8xx/dst.c	Fri Dec 10 15:14:10 2004
@@ -476,10 +476,10 @@ static int dst_type_print(u8 type)
 		otype = "satellite";
 		break;
 	case DST_TYPE_IS_TERR:
-		otype = "terrestial TV";
+		otype = "terrestrial";
 		break;
 	case DST_TYPE_IS_CABLE:
-		otype = "terrestial TV";
+		otype = "cable";
 		break;
 	default:
 		printk("%s: invalid dst type %d\n", __FUNCTION__, type);
diff -puN drivers/media/dvb/cinergyT2/cinergyT2.c~dvb-saa7146-driver-misc-updates drivers/media/dvb/cinergyT2/cinergyT2.c
--- 25/drivers/media/dvb/cinergyT2/cinergyT2.c~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/drivers/media/dvb/cinergyT2/cinergyT2.c	Fri Dec 10 15:14:10 2004
@@ -139,6 +139,7 @@ struct cinergyt2 {
 	struct work_struct query_work;
 
 	wait_queue_head_t poll_wq;
+	int pending_fe_events;
 
 	void *streambuf;
 	dma_addr_t streambuf_dmahandle;
@@ -204,7 +205,7 @@ static const uint32_t rc_keys [] = {
 
 static int cinergyt2_command (struct cinergyt2 *cinergyt2,
 		    char *send_buf, int send_buf_len,
-		    char *rec_buf, int rec_buf_len)
+			      char *recv_buf, int recv_buf_len)
 {
 	int actual_len;
 	char dummy;
@@ -216,11 +217,11 @@ static int cinergyt2_command (struct cin
 	if (ret)
 		dprintk(1, "usb_bulk_msg (send) failed, err %i\n", ret);
 
-	if (!rec_buf)
-		rec_buf = &dummy;
+	if (!recv_buf)
+		recv_buf = &dummy;
 
 	ret = usb_bulk_msg(cinergyt2->udev, usb_rcvbulkpipe(cinergyt2->udev, 1),
-			   rec_buf, rec_buf_len, &actual_len, HZ);
+			   recv_buf, recv_buf_len, &actual_len, HZ);
 
 	if (ret)
 		dprintk(1, "usb_bulk_msg (read) failed, err %i\n", ret);
@@ -325,7 +326,7 @@ static void cinergyt2_stop_stream_xfer (
 
 	for (i=0; i<STREAM_URB_COUNT; i++)
 		if (cinergyt2->stream_urb[i])
-			usb_unlink_urb(cinergyt2->stream_urb[i]);
+			usb_kill_urb(cinergyt2->stream_urb[i]);
 }
 
 static int cinergyt2_start_stream_xfer (struct cinergyt2 *cinergyt2)
@@ -586,15 +587,24 @@ static int cinergyt2_ioctl (struct inode
 		if (copy_from_user(&p, (void *) arg, sizeof(p)))
 			return -EFAULT;
 
+		if (down_interruptible(&cinergyt2->sem))
+			return -ERESTARTSYS;
+
 		param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
 		param->tps = cpu_to_le16(compute_tps(&p));
 		param->freq = cpu_to_le32(p.frequency / 1000);
 		param->bandwidth = 8 - p.u.ofdm.bandwidth - BANDWIDTH_8_MHZ;
 
+		stat->lock_bits = 0;
+		cinergyt2->pending_fe_events++;
+		wake_up_interruptible(&cinergyt2->poll_wq);
+
 		err = cinergyt2_command(cinergyt2,
 					(char *) param, sizeof(*param),
 					NULL, 0);
 
+		up(&cinergyt2->sem);
+
 		return (err < 0) ? err : 0;
 	}
 
@@ -608,6 +618,24 @@ static int cinergyt2_ioctl (struct inode
 		 */
 		break;
 
+	case FE_GET_EVENT:
+	{
+		/**
+		 *  for now we only fill the status field. the parameters
+		 *  are trivial to fill as soon FE_GET_FRONTEND is done.
+		 */
+		struct dvb_frontend_event *e = (void *) arg;
+		if (cinergyt2->pending_fe_events == 0) {
+			if (file->f_flags & O_NONBLOCK)
+				return -EWOULDBLOCK;
+			wait_event_interruptible(cinergyt2->poll_wq,
+						 cinergyt2->pending_fe_events > 0);
+		}
+		cinergyt2->pending_fe_events = 0;
+		return cinergyt2_ioctl(inode, file, FE_READ_STATUS,
+					(unsigned long) &e->status);
+	}
+
 	default:
 		;
 	}
@@ -734,8 +762,10 @@ static void cinergyt2_query (void *data)
 	unc += le32_to_cpu(s->uncorrected_block_count);
 	s->uncorrected_block_count = unc;
 
-	if (lock_bits != s->lock_bits)
+	if (lock_bits != s->lock_bits) {
 		wake_up_interruptible(&cinergyt2->poll_wq);
+		cinergyt2->pending_fe_events++;
+	}
 
 	schedule_delayed_work(&cinergyt2->query_work,
 			      msecs_to_jiffies(QUERY_INTERVAL));
@@ -762,6 +792,7 @@ static int cinergyt2_probe (struct usb_i
 	INIT_WORK(&cinergyt2->query_work, cinergyt2_query, cinergyt2);
 
 	cinergyt2->udev = interface_to_usbdev(intf);
+	cinergyt2->param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
 	
 	if (cinergyt2_alloc_stream_urbs (cinergyt2) < 0) {
 		dprintk(1, "unable to allocate stream urbs\n");
diff -puN include/media/saa7146.h~dvb-saa7146-driver-misc-updates include/media/saa7146.h
--- 25/include/media/saa7146.h~dvb-saa7146-driver-misc-updates	Fri Dec 10 15:14:10 2004
+++ 25-akpm/include/media/saa7146.h	Fri Dec 10 15:14:10 2004
@@ -51,10 +51,12 @@ extern unsigned int saa7146_debug;
 #define DEB_INT(x)  if (0!=(DEBUG_VARIABLE&0x20)) { DEBUG_PROLOG; printk x; } /* interrupt debug messages */
 #define DEB_CAP(x)  if (0!=(DEBUG_VARIABLE&0x40)) { DEBUG_PROLOG; printk x; } /* capture debug messages */
 
-#define IER_DISABLE(x,y) \
+#define SAA7146_IER_DISABLE(x,y) \
 	saa7146_write(x, IER, saa7146_read(x, IER) & ~(y));
-#define IER_ENABLE(x,y) \
+#define SAA7146_IER_ENABLE(x,y) \
 	saa7146_write(x, IER, saa7146_read(x, IER) | (y));
+#define SAA7146_ISR_CLEAR(x,y) \
+	saa7146_write(x, ISR, (y));
 
 struct saa7146_dev;
 struct saa7146_extension;
_
