aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pxa_camera.c
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@pengutronix.de>2008-04-15 01:57:48 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 13:07:44 -0400
commit7102b773d538c1f064da22ae9a1fb86704747388 (patch)
treeab91cdb525dc47dabc707161e2d990ddd8635f4b /drivers/media/video/pxa_camera.c
parentbb55de3b0e3523469491a48c51dcf7c6738162b2 (diff)
V4L/DVB (7250): Clean up pxa-camera driver, remove non-functional and never tested pm-support
This patch addresses most issues pointed out by Russell and Erik, moves recently introduced into pxa-regs.h camera-specific defines into pxa_camera.c, removes dummy power-management functions, improves function-naming, etc. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de> Acked-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/pxa_camera.c')
-rw-r--r--drivers/media/video/pxa_camera.c150
1 files changed, 64 insertions, 86 deletions
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index 11aecad769cc..a34a193249f6 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -10,10 +10,9 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 */ 11 */
12 12
13#include <asm/io.h>
14
15#include <linux/init.h> 13#include <linux/init.h>
16#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/io.h>
17#include <linux/delay.h> 16#include <linux/delay.h>
18#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
19#include <linux/errno.h> 18#include <linux/errno.h>
@@ -42,6 +41,26 @@
42#define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5) 41#define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5)
43#define PXA_CAM_DRV_NAME "pxa27x-camera" 42#define PXA_CAM_DRV_NAME "pxa27x-camera"
44 43
44#define CICR0_SIM_MP (0 << 24)
45#define CICR0_SIM_SP (1 << 24)
46#define CICR0_SIM_MS (2 << 24)
47#define CICR0_SIM_EP (3 << 24)
48#define CICR0_SIM_ES (4 << 24)
49
50#define CICR1_DW_VAL(x) ((x) & CICR1_DW) /* Data bus width */
51#define CICR1_PPL_VAL(x) (((x) << 15) & CICR1_PPL) /* Pixels per line */
52
53#define CICR2_BLW_VAL(x) (((x) << 24) & CICR2_BLW) /* Beginning-of-line pixel clock wait count */
54#define CICR2_ELW_VAL(x) (((x) << 16) & CICR2_ELW) /* End-of-line pixel clock wait count */
55#define CICR2_HSW_VAL(x) (((x) << 10) & CICR2_HSW) /* Horizontal sync pulse width */
56#define CICR2_BFPW_VAL(x) (((x) << 3) & CICR2_BFPW) /* Beginning-of-frame pixel clock wait count */
57#define CICR2_FSW_VAL(x) (((x) << 0) & CICR2_FSW) /* Frame stabilization wait count */
58
59#define CICR3_BFW_VAL(x) (((x) << 24) & CICR3_BFW) /* Beginning-of-frame line clock wait count */
60#define CICR3_EFW_VAL(x) (((x) << 16) & CICR3_EFW) /* End-of-frame line clock wait count */
61#define CICR3_VSW_VAL(x) (((x) << 11) & CICR3_VSW) /* Vertical sync pulse width */
62#define CICR3_LPF_VAL(x) (((x) << 0) & CICR3_LPF) /* Lines per frame */
63
45#define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \ 64#define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \
46 CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \ 65 CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \
47 CICR0_EOFM | CICR0_FOM) 66 CICR0_EOFM | CICR0_FOM)
@@ -83,8 +102,6 @@ struct pxa_camera_dev {
83 void __iomem *base; 102 void __iomem *base;
84 unsigned int dma_chan_y; 103 unsigned int dma_chan_y;
85 104
86 enum v4l2_buf_type type;
87
88 struct pxacamera_platform_data *pdata; 105 struct pxacamera_platform_data *pdata;
89 struct resource *res; 106 struct resource *res;
90 unsigned long platform_flags; 107 unsigned long platform_flags;
@@ -94,8 +111,6 @@ struct pxa_camera_dev {
94 111
95 spinlock_t lock; 112 spinlock_t lock;
96 113
97 int dma_running;
98
99 struct pxa_buffer *active; 114 struct pxa_buffer *active;
100}; 115};
101 116
@@ -106,9 +121,8 @@ static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
106/* 121/*
107 * Videobuf operations 122 * Videobuf operations
108 */ 123 */
109static int 124static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
110pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, 125 unsigned int *size)
111 unsigned int *size)
112{ 126{
113 struct soc_camera_device *icd = vq->priv_data; 127 struct soc_camera_device *icd = vq->priv_data;
114 128
@@ -151,9 +165,8 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
151 buf->vb.state = VIDEOBUF_NEEDS_INIT; 165 buf->vb.state = VIDEOBUF_NEEDS_INIT;
152} 166}
153 167
154static int 168static int pxa_videobuf_prepare(struct videobuf_queue *vq,
155pxa_videobuf_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, 169 struct videobuf_buffer *vb, enum v4l2_field field)
156 enum v4l2_field field)
157{ 170{
158 struct soc_camera_device *icd = vq->priv_data; 171 struct soc_camera_device *icd = vq->priv_data;
159 struct soc_camera_host *ici = 172 struct soc_camera_host *ici =
@@ -255,15 +268,15 @@ out:
255 return ret; 268 return ret;
256} 269}
257 270
258static void 271static void pxa_videobuf_queue(struct videobuf_queue *vq,
259pxa_videobuf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 272 struct videobuf_buffer *vb)
260{ 273{
261 struct soc_camera_device *icd = vq->priv_data; 274 struct soc_camera_device *icd = vq->priv_data;
262 struct soc_camera_host *ici = 275 struct soc_camera_host *ici =
263 to_soc_camera_host(icd->dev.parent); 276 to_soc_camera_host(icd->dev.parent);
264 struct pxa_camera_dev *pcdev = ici->priv; 277 struct pxa_camera_dev *pcdev = ici->priv;
265 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); 278 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
266 struct pxa_buffer *active = pcdev->active; 279 struct pxa_buffer *active;
267 struct videobuf_dmabuf *dma = videobuf_to_dma(vb); 280 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
268 int nents = dma->sglen; 281 int nents = dma->sglen;
269 unsigned long flags; 282 unsigned long flags;
@@ -275,8 +288,9 @@ pxa_videobuf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
275 list_add_tail(&vb->queue, &pcdev->capture); 288 list_add_tail(&vb->queue, &pcdev->capture);
276 289
277 vb->state = VIDEOBUF_ACTIVE; 290 vb->state = VIDEOBUF_ACTIVE;
291 active = pcdev->active;
278 292
279 if (!pcdev->active) { 293 if (!active) {
280 CIFR |= CIFR_RESET_F; 294 CIFR |= CIFR_RESET_F;
281 DDADR(pcdev->dma_chan_y) = buf->sg_dma; 295 DDADR(pcdev->dma_chan_y) = buf->sg_dma;
282 DCSR(pcdev->dma_chan_y) = DCSR_RUN; 296 DCSR(pcdev->dma_chan_y) = DCSR_RUN;
@@ -373,22 +387,21 @@ static void pxa_camera_dma_irq_y(int channel, void *data)
373 spin_lock_irqsave(&pcdev->lock, flags); 387 spin_lock_irqsave(&pcdev->lock, flags);
374 388
375 status = DCSR(pcdev->dma_chan_y); 389 status = DCSR(pcdev->dma_chan_y);
390 DCSR(pcdev->dma_chan_y) = status;
391
376 if (status & DCSR_BUSERR) { 392 if (status & DCSR_BUSERR) {
377 dev_err(pcdev->dev, "%s: Bus Error\n", __FUNCTION__); 393 dev_err(pcdev->dev, "DMA Bus Error IRQ!\n");
378 DCSR(pcdev->dma_chan_y) |= DCSR_BUSERR;
379 goto out; 394 goto out;
380 } 395 }
381 396
382 if (!(status & DCSR_ENDINTR)) { 397 if (!(status & DCSR_ENDINTR)) {
383 dev_err(pcdev->dev, "%s: unknown dma interrupt source. " 398 dev_err(pcdev->dev, "Unknown DMA IRQ source, "
384 "status: 0x%08x\n", __FUNCTION__, status); 399 "status: 0x%08x\n", status);
385 goto out; 400 goto out;
386 } 401 }
387 402
388 DCSR(pcdev->dma_chan_y) |= DCSR_ENDINTR;
389
390 if (!pcdev->active) { 403 if (!pcdev->active) {
391 dev_err(pcdev->dev, "%s: no active buf\n", __FUNCTION__); 404 dev_err(pcdev->dev, "DMA End IRQ with no active buffer!\n");
392 goto out; 405 goto out;
393 } 406 }
394 407
@@ -398,7 +411,7 @@ static void pxa_camera_dma_irq_y(int channel, void *data)
398 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__, 411 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__,
399 vb, vb->baddr, vb->bsize); 412 vb, vb->baddr, vb->bsize);
400 413
401 /* _init is used to debug races, see comment in pxa_is_reqbufs() */ 414 /* _init is used to debug races, see comment in pxa_camera_reqbufs() */
402 list_del_init(&vb->queue); 415 list_del_init(&vb->queue);
403 vb->state = VIDEOBUF_DONE; 416 vb->state = VIDEOBUF_DONE;
404 do_gettimeofday(&vb->ts); 417 do_gettimeofday(&vb->ts);
@@ -419,7 +432,7 @@ out:
419 spin_unlock_irqrestore(&pcdev->lock, flags); 432 spin_unlock_irqrestore(&pcdev->lock, flags);
420} 433}
421 434
422static struct videobuf_queue_ops pxa_video_ops = { 435static struct videobuf_queue_ops pxa_videobuf_ops = {
423 .buf_setup = pxa_videobuf_setup, 436 .buf_setup = pxa_videobuf_setup,
424 .buf_prepare = pxa_videobuf_prepare, 437 .buf_prepare = pxa_videobuf_prepare,
425 .buf_queue = pxa_videobuf_queue, 438 .buf_queue = pxa_videobuf_queue,
@@ -444,7 +457,7 @@ static int mclk_get_divisor(struct pxa_camera_dev *pcdev)
444 return div; 457 return div;
445} 458}
446 459
447static void pxa_is_activate(struct pxa_camera_dev *pcdev) 460static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
448{ 461{
449 struct pxacamera_platform_data *pdata = pcdev->pdata; 462 struct pxacamera_platform_data *pdata = pcdev->pdata;
450 u32 cicr4 = 0; 463 u32 cicr4 = 0;
@@ -486,7 +499,7 @@ static void pxa_is_activate(struct pxa_camera_dev *pcdev)
486 clk_enable(pcdev->clk); 499 clk_enable(pcdev->clk);
487} 500}
488 501
489static void pxa_is_deactivate(struct pxa_camera_dev *pcdev) 502static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev)
490{ 503{
491 struct pxacamera_platform_data *board = pcdev->pdata; 504 struct pxacamera_platform_data *board = pcdev->pdata;
492 505
@@ -518,7 +531,7 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
518 531
519/* The following two functions absolutely depend on the fact, that 532/* The following two functions absolutely depend on the fact, that
520 * there can be only one camera on PXA quick capture interface */ 533 * there can be only one camera on PXA quick capture interface */
521static int pxa_is_add_device(struct soc_camera_device *icd) 534static int pxa_camera_add_device(struct soc_camera_device *icd)
522{ 535{
523 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 536 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
524 struct pxa_camera_dev *pcdev = ici->priv; 537 struct pxa_camera_dev *pcdev = ici->priv;
@@ -534,7 +547,7 @@ static int pxa_is_add_device(struct soc_camera_device *icd)
534 dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n", 547 dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
535 icd->devnum); 548 icd->devnum);
536 549
537 pxa_is_activate(pcdev); 550 pxa_camera_activate(pcdev);
538 ret = icd->ops->init(icd); 551 ret = icd->ops->init(icd);
539 552
540 if (!ret) 553 if (!ret)
@@ -546,7 +559,7 @@ ebusy:
546 return ret; 559 return ret;
547} 560}
548 561
549static void pxa_is_remove_device(struct soc_camera_device *icd) 562static void pxa_camera_remove_device(struct soc_camera_device *icd)
550{ 563{
551 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 564 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
552 struct pxa_camera_dev *pcdev = ici->priv; 565 struct pxa_camera_dev *pcdev = ici->priv;
@@ -563,13 +576,13 @@ static void pxa_is_remove_device(struct soc_camera_device *icd)
563 576
564 icd->ops->release(icd); 577 icd->ops->release(icd);
565 578
566 pxa_is_deactivate(pcdev); 579 pxa_camera_deactivate(pcdev);
567 580
568 pcdev->icd = NULL; 581 pcdev->icd = NULL;
569} 582}
570 583
571static int pxa_is_set_capture_format(struct soc_camera_device *icd, 584static int pxa_camera_set_capture_format(struct soc_camera_device *icd,
572 __u32 pixfmt, struct v4l2_rect *rect) 585 __u32 pixfmt, struct v4l2_rect *rect)
573{ 586{
574 struct soc_camera_host *ici = 587 struct soc_camera_host *ici =
575 to_soc_camera_host(icd->dev.parent); 588 to_soc_camera_host(icd->dev.parent);
@@ -652,14 +665,14 @@ static int pxa_is_set_capture_format(struct soc_camera_device *icd,
652 665
653 /* CIF interrupts are not used, only DMA */ 666 /* CIF interrupts are not used, only DMA */
654 CICR0 = (pcdev->platform_flags & PXA_CAMERA_MASTER ? 667 CICR0 = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
655 0 : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) | 668 CICR0_SIM_MP : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) |
656 CICR0_DMAEN | CICR0_IRQ_MASK | (cicr0 & CICR0_ENB); 669 CICR0_DMAEN | CICR0_IRQ_MASK | (cicr0 & CICR0_ENB);
657 670
658 return 0; 671 return 0;
659} 672}
660 673
661static int pxa_is_try_fmt_cap(struct soc_camera_host *ici, 674static int pxa_camera_try_fmt_cap(struct soc_camera_host *ici,
662 struct v4l2_format *f) 675 struct v4l2_format *f)
663{ 676{
664 /* limit to pxa hardware capabilities */ 677 /* limit to pxa hardware capabilities */
665 if (f->fmt.pix.height < 32) 678 if (f->fmt.pix.height < 32)
@@ -675,8 +688,8 @@ static int pxa_is_try_fmt_cap(struct soc_camera_host *ici,
675 return 0; 688 return 0;
676} 689}
677 690
678static int pxa_is_reqbufs(struct soc_camera_file *icf, 691static int pxa_camera_reqbufs(struct soc_camera_file *icf,
679 struct v4l2_requestbuffers *p) 692 struct v4l2_requestbuffers *p)
680{ 693{
681 int i; 694 int i;
682 695
@@ -694,7 +707,7 @@ static int pxa_is_reqbufs(struct soc_camera_file *icf,
694 return 0; 707 return 0;
695} 708}
696 709
697static unsigned int pxa_is_poll(struct file *file, poll_table *pt) 710static unsigned int pxa_camera_poll(struct file *file, poll_table *pt)
698{ 711{
699 struct soc_camera_file *icf = file->private_data; 712 struct soc_camera_file *icf = file->private_data;
700 struct pxa_buffer *buf; 713 struct pxa_buffer *buf;
@@ -711,8 +724,8 @@ static unsigned int pxa_is_poll(struct file *file, poll_table *pt)
711 return 0; 724 return 0;
712} 725}
713 726
714static int pxa_is_querycap(struct soc_camera_host *ici, 727static int pxa_camera_querycap(struct soc_camera_host *ici,
715 struct v4l2_capability *cap) 728 struct v4l2_capability *cap)
716{ 729{
717 /* cap->name is set by the firendly caller:-> */ 730 /* cap->name is set by the firendly caller:-> */
718 strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card)); 731 strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card));
@@ -725,15 +738,15 @@ static int pxa_is_querycap(struct soc_camera_host *ici,
725/* Should beallocated dynamically too, but we have only one. */ 738/* Should beallocated dynamically too, but we have only one. */
726static struct soc_camera_host pxa_soc_camera_host = { 739static struct soc_camera_host pxa_soc_camera_host = {
727 .drv_name = PXA_CAM_DRV_NAME, 740 .drv_name = PXA_CAM_DRV_NAME,
728 .vbq_ops = &pxa_video_ops, 741 .vbq_ops = &pxa_videobuf_ops,
729 .add = pxa_is_add_device, 742 .add = pxa_camera_add_device,
730 .remove = pxa_is_remove_device, 743 .remove = pxa_camera_remove_device,
731 .msize = sizeof(struct pxa_buffer), 744 .msize = sizeof(struct pxa_buffer),
732 .set_capture_format = pxa_is_set_capture_format, 745 .set_capture_format = pxa_camera_set_capture_format,
733 .try_fmt_cap = pxa_is_try_fmt_cap, 746 .try_fmt_cap = pxa_camera_try_fmt_cap,
734 .reqbufs = pxa_is_reqbufs, 747 .reqbufs = pxa_camera_reqbufs,
735 .poll = pxa_is_poll, 748 .poll = pxa_camera_poll,
736 .querycap = pxa_is_querycap, 749 .querycap = pxa_camera_querycap,
737}; 750};
738 751
739static int pxa_camera_probe(struct platform_device *pdev) 752static int pxa_camera_probe(struct platform_device *pdev)
@@ -753,8 +766,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
753 766
754 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL); 767 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
755 if (!pcdev) { 768 if (!pcdev) {
756 dev_err(&pdev->dev, "%s: Could not allocate pcdev\n", 769 dev_err(&pdev->dev, "Could not allocate pcdev\n");
757 __FUNCTION__);
758 err = -ENOMEM; 770 err = -ENOMEM;
759 goto exit; 771 goto exit;
760 } 772 }
@@ -871,51 +883,17 @@ static int __devexit pxa_camera_remove(struct platform_device *pdev)
871 883
872 kfree(pcdev); 884 kfree(pcdev);
873 885
874 dev_info(&pdev->dev, "%s: PXA Camera driver unloaded\n", __FUNCTION__); 886 dev_info(&pdev->dev, "PXA Camera driver unloaded\n");
875
876 return 0;
877}
878
879/*
880 * Suspend the Camera Module.
881 */
882static int pxa_camera_suspend(struct platform_device *pdev, pm_message_t level)
883{
884 struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
885 887
886 dev_info(&pdev->dev, "camera suspend\n");
887 disable_irq(pcdev->irq);
888 return 0; 888 return 0;
889} 889}
890 890
891/*
892 * Resume the Camera Module.
893 */
894static int pxa_camera_resume(struct platform_device *pdev)
895{
896 struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
897
898 dev_info(&pdev->dev, "camera resume\n");
899 enable_irq(pcdev->irq);
900
901/* if (pcdev) { */ /* FIXME: dev in use? */
902/* DRCMR68 = pcdev->dma_chan_y | DRCMR_MAPVLD; */
903/* DRCMR69 = pcdev->dma_chan_cb | DRCMR_MAPVLD; */
904/* DRCMR70 = pcdev->dma_chan_cr | DRCMR_MAPVLD; */
905/* } */
906
907 return 0;
908}
909
910
911static struct platform_driver pxa_camera_driver = { 891static struct platform_driver pxa_camera_driver = {
912 .driver = { 892 .driver = {
913 .name = PXA_CAM_DRV_NAME, 893 .name = PXA_CAM_DRV_NAME,
914 }, 894 },
915 .probe = pxa_camera_probe, 895 .probe = pxa_camera_probe,
916 .remove = __exit_p(pxa_camera_remove), 896 .remove = __exit_p(pxa_camera_remove),
917 .suspend = pxa_camera_suspend,
918 .resume = pxa_camera_resume,
919}; 897};
920 898
921 899