V4L/DVB (6252): Adapt drivers to use the newer videobuf modules
[powerpc.git] / drivers / media / video / saa7134 / saa7134-video.c
index 557530a..cf40a96 100644 (file)
@@ -23,9 +23,9 @@
 #include <linux/init.h>
 #include <linux/list.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/sort.h>
 
 #include "saa7134-reg.h"
 #include "saa7134.h"
@@ -516,14 +516,12 @@ static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int
        return 1;
 }
 
-static
-int res_check(struct saa7134_fh *fh, unsigned int bit)
+static int res_check(struct saa7134_fh *fh, unsigned int bit)
 {
        return (fh->resources & bit);
 }
 
-static
-int res_locked(struct saa7134_dev *dev, unsigned int bit)
+static int res_locked(struct saa7134_dev *dev, unsigned int bit)
 {
        return (dev->resources & bit);
 }
@@ -603,7 +601,14 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
        saa_writeb(SAA7134_RAW_DATA_GAIN,         0x40);
        saa_writeb(SAA7134_RAW_DATA_OFFSET,       0x80);
 
-       saa7134_i2c_call_clients(dev,VIDIOC_S_STD,&norm->id);
+       /* only tell the tuner if this is a tv input */
+       if (card_in(dev,dev->ctl_input).tv) {
+               if ((card(dev).tuner_type == TUNER_PHILIPS_TDA8290)
+                               && ((card(dev).tuner_config == 1)
+                               ||  (card(dev).tuner_config == 2)))
+                       saa7134_set_gpio(dev, 22, 5);
+               saa7134_i2c_call_clients(dev,VIDIOC_S_STD,&norm->id);
+       }
 }
 
 static void video_mux(struct saa7134_dev *dev, int input)
@@ -732,25 +737,6 @@ struct cliplist {
        __u8  disable;
 };
 
-static void sort_cliplist(struct cliplist *cl, int entries)
-{
-       struct cliplist swap;
-       int i,j,n;
-
-       for (i = entries-2; i >= 0; i--) {
-               for (n = 0, j = 0; j <= i; j++) {
-                       if (cl[j].position > cl[j+1].position) {
-                               swap = cl[j];
-                               cl[j] = cl[j+1];
-                               cl[j+1] = swap;
-                               n++;
-                       }
-               }
-               if (0 == n)
-                       break;
-       }
-}
-
 static void set_cliplist(struct saa7134_dev *dev, int reg,
                        struct cliplist *cl, int entries, char *name)
 {
@@ -784,15 +770,27 @@ static int clip_range(int val)
        return val;
 }
 
+/* Sort into smallest position first order */
+static int cliplist_cmp(const void *a, const void *b)
+{
+       const struct cliplist *cla = a;
+       const struct cliplist *clb = b;
+       if (cla->position < clb->position)
+               return -1;
+       if (cla->position > clb->position)
+               return 1;
+       return 0;
+}
+
 static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
                          int nclips, int interlace)
 {
        struct cliplist col[16], row[16];
-       int cols, rows, i;
+       int cols = 0, rows = 0, i;
        int div = interlace ? 2 : 1;
 
-       memset(col,0,sizeof(col)); cols = 0;
-       memset(row,0,sizeof(row)); rows = 0;
+       memset(col, 0, sizeof(col));
+       memset(row, 0, sizeof(row));
        for (i = 0; i < nclips && i < 8; i++) {
                col[cols].position = clip_range(clips[i].c.left);
                col[cols].enable   = (1 << i);
@@ -808,8 +806,8 @@ static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
                row[rows].disable  = (1 << i);
                rows++;
        }
-       sort_cliplist(col,cols);
-       sort_cliplist(row,rows);
+       sort(col, cols, sizeof col[0], cliplist_cmp, NULL);
+       sort(row, rows, sizeof row[0], cliplist_cmp, NULL);
        set_cliplist(dev,0x380,col,cols,"cols");
        set_cliplist(dev,0x384,row,rows,"rows");
        return 0;
@@ -1039,6 +1037,8 @@ static int buffer_prepare(struct videobuf_queue *q,
        }
 
        if (STATE_NEEDS_INIT == buf->vb.state) {
+               struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
+
                buf->vb.width  = fh->width;
                buf->vb.height = fh->height;
                buf->vb.size   = size;
@@ -1050,8 +1050,8 @@ static int buffer_prepare(struct videobuf_queue *q,
                if (err)
                        goto oops;
                err = saa7134_pgtable_build(dev->pci,buf->pt,
-                                           buf->vb.dma.sglist,
-                                           buf->vb.dma.sglen,
+                                           dma->sglist,
+                                           dma->sglen,
                                            saa7134_buffer_startpage(buf));
                if (err)
                        goto oops;
@@ -1261,19 +1261,14 @@ static struct videobuf_queue* saa7134_queue(struct saa7134_fh *fh)
 
 static int saa7134_resource(struct saa7134_fh *fh)
 {
-       int res = 0;
+       if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return RESOURCE_VIDEO;
 
-       switch (fh->type) {
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               res = RESOURCE_VIDEO;
-               break;
-       case V4L2_BUF_TYPE_VBI_CAPTURE:
-               res = RESOURCE_VBI;
-               break;
-       default:
-               BUG();
-       }
-       return res;
+       if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
+               return RESOURCE_VBI;
+
+       BUG();
+       return 0;
 }
 
 static int video_open(struct inode *inode, struct file *file)
@@ -1316,13 +1311,13 @@ static int video_open(struct inode *inode, struct file *file)
        fh->height   = 576;
        v4l2_prio_open(&dev->prio,&fh->prio);
 
-       videobuf_queue_init(&fh->cap, &video_qops,
+       videobuf_queue_pci_init(&fh->cap, &video_qops,
                            dev->pci, &dev->slock,
                            V4L2_BUF_TYPE_VIDEO_CAPTURE,
                            V4L2_FIELD_INTERLACED,
                            sizeof(struct saa7134_buf),
                            fh);
-       videobuf_queue_init(&fh->vbi, &saa7134_vbi_qops,
+       videobuf_queue_pci_init(&fh->vbi, &saa7134_vbi_qops,
                            dev->pci, &dev->slock,
                            V4L2_BUF_TYPE_VBI_CAPTURE,
                            V4L2_FIELD_SEQ_TB,
@@ -1461,8 +1456,7 @@ static int video_release(struct inode *inode, struct file *file)
        return 0;
 }
 
-static int
-video_mmap(struct file *file, struct vm_area_struct * vma)
+static int video_mmap(struct file *file, struct vm_area_struct * vma)
 {
        struct saa7134_fh *fh = file->private_data;
 
@@ -1820,15 +1814,18 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
                                        break;
                if (i == TVNORMS)
                        return -EINVAL;
-               if (*id & V4L2_STD_SECAM) {
-                       if (secam[0] == 'L' || secam[0] == 'l')
+               if ((*id & V4L2_STD_SECAM) && (secam[0] != '-')) {
+                       if (secam[0] == 'L' || secam[0] == 'l') {
                                if (secam[1] == 'C' || secam[1] == 'c')
                                        fixup = V4L2_STD_SECAM_LC;
                                else
                                        fixup = V4L2_STD_SECAM_L;
-                       else
+                       } else {
                                if (secam[0] == 'D' || secam[0] == 'd')
                                        fixup = V4L2_STD_SECAM_DK;
+                               else
+                                       fixup = V4L2_STD_SECAM;
+                       }
                        for (i = 0; i < TVNORMS; i++)
                                if (fixup == tvnorms[i].id)
                                        break;
@@ -2142,29 +2139,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
        }
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
        case VIDIOCGMBUF:
-       {
-               struct video_mbuf *mbuf = arg;
-               struct videobuf_queue *q;
-               struct v4l2_requestbuffers req;
-               unsigned int i;
-
-               q = saa7134_queue(fh);
-               memset(&req,0,sizeof(req));
-               req.type   = q->type;
-               req.count  = gbuffers;
-               req.memory = V4L2_MEMORY_MMAP;
-               err = videobuf_reqbufs(q,&req);
-               if (err < 0)
-                       return err;
-               memset(mbuf,0,sizeof(*mbuf));
-               mbuf->frames = req.count;
-               mbuf->size   = 0;
-               for (i = 0; i < mbuf->frames; i++) {
-                       mbuf->offsets[i]  = q->bufs[i]->boff;
-                       mbuf->size       += q->bufs[i]->bsize;
-               }
-               return 0;
-       }
+               return videobuf_cgmbuf(saa7134_queue(fh), arg, gbuffers);
 #endif
        case VIDIOC_REQBUFS:
                return videobuf_reqbufs(saa7134_queue(fh),arg);
@@ -2245,7 +2220,11 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
                t->type = V4L2_TUNER_RADIO;
 
                saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
-
+               if (dev->input->amux == TV) {
+                       t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11);
+                       t->rxsubchans = (saa_readb(0x529) & 0x08) ?
+                                       V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
+               }
                return 0;
        }
        case VIDIOC_S_TUNER:
@@ -2329,7 +2308,7 @@ static int radio_ioctl(struct inode *inode, struct file *file,
        return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
 }
 
-static struct file_operations video_fops =
+static const struct file_operations video_fops =
 {
        .owner    = THIS_MODULE,
        .open     = video_open,
@@ -2342,7 +2321,7 @@ static struct file_operations video_fops =
        .llseek   = no_llseek,
 };
 
-static struct file_operations radio_fops =
+static const struct file_operations radio_fops =
 {
        .owner    = THIS_MODULE,
        .open     = video_open,
@@ -2454,12 +2433,6 @@ int saa7134_video_init2(struct saa7134_dev *dev)
        return 0;
 }
 
-int saa7134_video_fini(struct saa7134_dev *dev)
-{
-       /* nothing */
-       return 0;
-}
-
 void saa7134_irq_video_intl(struct saa7134_dev *dev)
 {
        static const char *st[] = {