V4L/DVB (13645): soc-camera: fix multi-line comment coding style
[safe/jmp/linux-2.6] / drivers / media / video / sh_mobile_ceu_camera.c
index afdea0d..3271944 100644 (file)
@@ -153,6 +153,40 @@ static u32 ceu_read(struct sh_mobile_ceu_dev *priv, unsigned long reg_offs)
        return ioread32(priv->base + reg_offs);
 }
 
+static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
+{
+       int i, success = 0;
+       struct soc_camera_device *icd = pcdev->icd;
+
+       ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
+
+       /* wait CSTSR.CPTON bit */
+       for (i = 0; i < 1000; i++) {
+               if (!(ceu_read(pcdev, CSTSR) & 1)) {
+                       success++;
+                       break;
+               }
+               udelay(1);
+       }
+
+       /* wait CAPSR.CPKIL bit */
+       for (i = 0; i < 1000; i++) {
+               if (!(ceu_read(pcdev, CAPSR) & (1 << 16))) {
+                       success++;
+                       break;
+               }
+               udelay(1);
+       }
+
+
+       if (2 != success) {
+               dev_warn(&icd->dev, "soft reset time out\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
 /*
  *  Videobuf operations
  */
@@ -202,26 +236,46 @@ static void free_buffer(struct videobuf_queue *vq,
 #define CEU_CETCR_MAGIC 0x0317f313 /* acknowledge magical interrupt sources */
 #define CEU_CETCR_IGRW (1 << 4) /* prohibited register access interrupt bit */
 #define CEU_CEIER_CPEIE (1 << 0) /* one-frame capture end interrupt */
+#define CEU_CEIER_VBP   (1 << 20) /* vbp error */
 #define CEU_CAPCR_CTNCP (1 << 16) /* continuous capture mode (if set) */
+#define CEU_CEIER_MASK (CEU_CEIER_CPEIE | CEU_CEIER_VBP)
 
 
-static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
+/*
+ * return value doesn't reflex the success/failure to queue the new buffer,
+ * but rather the status of the previous buffer.
+ */
+static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
 {
        struct soc_camera_device *icd = pcdev->icd;
        dma_addr_t phys_addr_top, phys_addr_bottom;
+       u32 status;
+       int ret = 0;
 
-       /* The hardware is _very_ picky about this sequence. Especially
+       /*
+        * The hardware is _very_ picky about this sequence. Especially
         * the CEU_CETCR_MAGIC value. It seems like we need to acknowledge
         * several not-so-well documented interrupt sources in CETCR.
         */
-       ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~CEU_CEIER_CPEIE);
-       ceu_write(pcdev, CETCR, ~ceu_read(pcdev, CETCR) & CEU_CETCR_MAGIC);
-       ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | CEU_CEIER_CPEIE);
+       ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~CEU_CEIER_MASK);
+       status = ceu_read(pcdev, CETCR);
+       ceu_write(pcdev, CETCR, ~status & CEU_CETCR_MAGIC);
+       ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | CEU_CEIER_MASK);
        ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~CEU_CAPCR_CTNCP);
        ceu_write(pcdev, CETCR, CEU_CETCR_MAGIC ^ CEU_CETCR_IGRW);
 
+       /*
+        * When a VBP interrupt occurs, a capture end interrupt does not occur
+        * and the image of that frame is not captured correctly. So, soft reset
+        * is needed here.
+        */
+       if (status & CEU_CEIER_VBP) {
+               sh_mobile_ceu_soft_reset(pcdev);
+               ret = -EIO;
+       }
+
        if (!pcdev->active)
-               return;
+               return ret;
 
        phys_addr_top = videobuf_to_dma_contig(pcdev->active);
        ceu_write(pcdev, CDAYR, phys_addr_top);
@@ -247,6 +301,8 @@ static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
 
        pcdev->active->state = VIDEOBUF_ACTIVE;
        ceu_write(pcdev, CAPSR, 0x1); /* start capture */
+
+       return ret;
 }
 
 static int sh_mobile_ceu_videobuf_prepare(struct videobuf_queue *vq,
@@ -266,8 +322,10 @@ static int sh_mobile_ceu_videobuf_prepare(struct videobuf_queue *vq,
        WARN_ON(!list_empty(&vb->queue));
 
 #ifdef DEBUG
-       /* This can be useful if you want to see if we actually fill
-        * the buffer with something */
+       /*
+        * This can be useful if you want to see if we actually fill
+        * the buffer with something
+        */
        memset((void *)vb->baddr, 0xaa, vb->bsize);
 #endif
 
@@ -319,6 +377,11 @@ static void sh_mobile_ceu_videobuf_queue(struct videobuf_queue *vq,
        list_add_tail(&vb->queue, &pcdev->capture);
 
        if (!pcdev->active) {
+               /*
+                * Because there were no active buffer at this moment,
+                * we are not interested in the return value of
+                * sh_mobile_ceu_capture here.
+                */
                pcdev->active = vb;
                sh_mobile_ceu_capture(pcdev);
        }
@@ -379,9 +442,8 @@ static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
        else
                pcdev->active = NULL;
 
-       sh_mobile_ceu_capture(pcdev);
-
-       vb->state = VIDEOBUF_DONE;
+       vb->state = (sh_mobile_ceu_capture(pcdev) < 0) ?
+               VIDEOBUF_ERROR : VIDEOBUF_DONE;
        do_gettimeofday(&vb->ts);
        vb->field_count++;
        wake_up(&vb->done);
@@ -407,13 +469,9 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
 
        pm_runtime_get_sync(ici->v4l2_dev.dev);
 
-       ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
-       while (ceu_read(pcdev, CSTSR) & 1)
-               msleep(1);
-
        pcdev->icd = icd;
 
-       return 0;
+       return sh_mobile_ceu_soft_reset(pcdev);
 }
 
 /* Called with .video_lock held */
@@ -427,7 +485,7 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
 
        /* disable capture, disable interrupts */
        ceu_write(pcdev, CEIER, 0);
-       ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
+       sh_mobile_ceu_soft_reset(pcdev);
 
        /* make sure active buffer is canceled */
        spin_lock_irqsave(&pcdev->lock, flags);
@@ -654,7 +712,8 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
 
        ceu_write(pcdev, CFLCR, pcdev->cflcr);
 
-       /* A few words about byte order (observed in Big Endian mode)
+       /*
+        * A few words about byte order (observed in Big Endian mode)
         *
         * In data fetch mode bytes are received in chunks of 8 bytes.
         * D0, D1, D2, D3, D4, D5, D6, D7 (D0 received first)
@@ -1518,10 +1577,12 @@ static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf,
 {
        int i;
 
-       /* This is for locking debugging only. I removed spinlocks and now I
+       /*
+        * This is for locking debugging only. I removed spinlocks and now I
         * check whether .prepare is ever called on a linked buffer, or whether
         * a dma IRQ can occur for an in-work or unlinked buffer. Until now
-        * it hadn't triggered */
+        * it hadn't triggered
+        */
        for (i = 0; i < p->count; i++) {
                struct sh_mobile_ceu_buffer *buf;
 
@@ -1730,7 +1791,6 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
 
 exit_free_clk:
        pm_runtime_disable(&pdev->dev);
-exit_free_irq:
        free_irq(pcdev->irq, pcdev);
 exit_release_mem:
        if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
@@ -1771,7 +1831,7 @@ static int sh_mobile_ceu_runtime_nop(struct device *dev)
        return 0;
 }
 
-static struct dev_pm_ops sh_mobile_ceu_dev_pm_ops = {
+static const struct dev_pm_ops sh_mobile_ceu_dev_pm_ops = {
        .runtime_suspend = sh_mobile_ceu_runtime_nop,
        .runtime_resume = sh_mobile_ceu_runtime_nop,
 };
@@ -1782,7 +1842,7 @@ static struct platform_driver sh_mobile_ceu_driver = {
                .pm     = &sh_mobile_ceu_dev_pm_ops,
        },
        .probe          = sh_mobile_ceu_probe,
-       .remove         = __exit_p(sh_mobile_ceu_remove),
+       .remove         = __devexit_p(sh_mobile_ceu_remove),
 };
 
 static int __init sh_mobile_ceu_init(void)