V4L/DVB (5469a): Copyright and maintainer tweaks
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / cafe_ccic.c
index b223efdc9ee329d711932dc6d564c7de1685cea7..59fd760a52ace8c7e361c74b52fedb667a80d0f5 100644 (file)
@@ -4,6 +4,7 @@
  * sensor.
  *
  * Copyright 2006 One Laptop Per Child Association, Inc.
+ * Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
  *
  * Written by Jonathan Corbet, corbet@lwn.net.
  *
@@ -37,7 +38,7 @@
 
 #include "cafe_ccic-regs.h"
 
-#define CAFE_VERSION 0x000001
+#define CAFE_VERSION 0x000002
 
 
 /*
@@ -705,7 +706,13 @@ static void cafe_ctlr_init(struct cafe_camera *cam)
        cafe_reg_write(cam, REG_GL_CSR, GCSR_SRS|GCSR_MRS); /* Needed? */
        cafe_reg_write(cam, REG_GL_CSR, GCSR_SRC|GCSR_MRC);
        cafe_reg_write(cam, REG_GL_CSR, GCSR_SRC|GCSR_MRS);
+       /*
+        * Here we must wait a bit for the controller to come around.
+        */
+       spin_unlock_irqrestore(&cam->dev_lock, flags);
        mdelay(5);      /* FIXME revisit this */
+       spin_lock_irqsave(&cam->dev_lock, flags);
+
        cafe_reg_write(cam, REG_GL_CSR, GCSR_CCIC_EN|GCSR_SRC|GCSR_MRC);
        cafe_reg_set_bit(cam, REG_GL_IMASK, GIMSK_CCIC_EN);
        /*
@@ -773,9 +780,9 @@ static void cafe_ctlr_power_up(struct cafe_camera *cam)
         * Control 1 is power down, set to 0 to operate.
         */
        cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */
-       mdelay(1); /* Marvell says 1ms will do it */
+//     mdelay(1); /* Marvell says 1ms will do it */
        cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
-       mdelay(1); /* Enough? */
+//     mdelay(1); /* Enough? */
        spin_unlock_irqrestore(&cam->dev_lock, flags);
 }
 
@@ -1796,18 +1803,19 @@ static void cafe_frame_tasklet(unsigned long data)
                if (list_empty(&cam->sb_avail))
                        break;  /* Leave it valid, hope for better later */
                clear_bit(bufno, &cam->flags);
-               /*
-                * We could perhaps drop the spinlock during this
-                * big copy.  Something to consider.
-                */
                sbuf = list_entry(cam->sb_avail.next,
                                struct cafe_sio_buffer, list);
+               /*
+                * Drop the lock during the big copy.  This *should* be safe...
+                */
+               spin_unlock_irqrestore(&cam->dev_lock, flags);
                memcpy(sbuf->buffer, cam->dma_bufs[bufno],
                                cam->pix_format.sizeimage);
                sbuf->v4lbuf.bytesused = cam->pix_format.sizeimage;
                sbuf->v4lbuf.sequence = cam->buf_seq[bufno];
                sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_QUEUED;
                sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_DONE;
+               spin_lock_irqsave(&cam->dev_lock, flags);
                list_move_tail(&sbuf->list, &cam->sb_full);
        }
        if (! list_empty(&cam->sb_full))
@@ -2181,10 +2189,48 @@ static void cafe_pci_remove(struct pci_dev *pdev)
 }
 
 
+#ifdef CONFIG_PM
+/*
+ * Basic power management.
+ */
+static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       struct cafe_camera *cam = cafe_find_by_pdev(pdev);
+       int ret;
+
+       ret = pci_save_state(pdev);
+       if (ret)
+               return ret;
+       cafe_ctlr_stop_dma(cam);
+       cafe_ctlr_power_down(cam);
+       pci_disable_device(pdev);
+       return 0;
+}
+
+
+static int cafe_pci_resume(struct pci_dev *pdev)
+{
+       struct cafe_camera *cam = cafe_find_by_pdev(pdev);
+       int ret = 0;
+
+       ret = pci_restore_state(pdev);
+       if (ret)
+               return ret;
+       pci_enable_device(pdev);
+       cafe_ctlr_init(cam);
+       cafe_ctlr_power_up(cam);
+       set_bit(CF_CONFIG_NEEDED, &cam->flags);
+       if (cam->state == S_SPECREAD)
+               cam->state = S_IDLE;  /* Don't bother restarting */
+       else if (cam->state == S_SINGLEREAD || cam->state == S_STREAMING)
+               ret = cafe_read_setup(cam, cam->state);
+       return ret;
+}
+
+#endif  /* CONFIG_PM */
 
 
 static struct pci_device_id cafe_ids[] = {
-       { PCI_DEVICE(0x1148, 0x4340) }, /* Temporary ID on devel board */
        { PCI_DEVICE(0x11ab, 0x4100) }, /* Eventual real ID */
        { PCI_DEVICE(0x11ab, 0x4102) }, /* Really eventual real ID */
        { 0, }
@@ -2197,6 +2243,10 @@ static struct pci_driver cafe_pci_driver = {
        .id_table = cafe_ids,
        .probe = cafe_pci_probe,
        .remove = cafe_pci_remove,
+#ifdef CONFIG_PM
+       .suspend = cafe_pci_suspend,
+       .resume = cafe_pci_resume,
+#endif
 };