2 * V4L2 Driver for PXA camera host
4 * Copyright (C) 2006, Sascha Hauer, Pengutronix
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/errno.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
24 #include <linux/moduleparam.h>
25 #include <linux/time.h>
26 #include <linux/version.h>
27 #include <linux/device.h>
28 #include <linux/platform_device.h>
29 #include <linux/mutex.h>
30 #include <linux/clk.h>
32 #include <media/v4l2-common.h>
33 #include <media/v4l2-dev.h>
34 #include <media/soc_camera.h>
36 #include <linux/videodev2.h>
39 #include <asm/arch/pxa-regs.h>
40 #include <asm/arch/camera.h>
42 #define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5)
43 #define PXA_CAM_DRV_NAME "pxa27x-camera"
45 #define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \
46 CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \
47 CICR0_EOFM | CICR0_FOM)
49 static DEFINE_MUTEX(camera_lock);
55 /* buffer for one video frame */
57 /* common v4l buffer stuff -- must be first */
58 struct videobuf_buffer vb;
60 const struct soc_camera_data_format *fmt;
62 /* our descriptor list needed for the PXA DMA engine */
64 struct pxa_dma_desc *sg_cpu;
69 struct pxa_framebuffer_queue {
70 dma_addr_t sg_last_dma;
71 struct pxa_dma_desc *sg_last_cpu;
74 struct pxa_camera_dev {
76 /* PXA27x is only supposed to handle one camera on its Quick Capture
77 * interface. If anyone ever builds hardware to enable more than
78 * one camera, they will have to modify this driver too */
79 struct soc_camera_device *icd;
84 unsigned int dma_chan_y;
86 enum v4l2_buf_type type;
88 struct pxacamera_platform_data *pdata;
90 unsigned long platform_flags;
91 unsigned long platform_mclk_10khz;
93 struct list_head capture;
99 struct pxa_buffer *active;
102 static const char *pxa_cam_driver_description = "PXA_Camera";
104 static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
107 * Videobuf operations
110 pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
113 struct soc_camera_device *icd = vq->priv_data;
115 dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
117 *size = icd->width * icd->height * ((icd->current_fmt->depth + 7) >> 3);
121 while (*size * *count > vid_limit * 1024 * 1024)
127 static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
129 struct soc_camera_device *icd = vq->priv_data;
130 struct soc_camera_host *ici =
131 to_soc_camera_host(icd->dev.parent);
132 struct pxa_camera_dev *pcdev = ici->priv;
133 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
135 BUG_ON(in_interrupt());
137 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__,
138 &buf->vb, buf->vb.baddr, buf->vb.bsize);
140 /* This waits until this buffer is out of danger, i.e., until it is no
141 * longer in STATE_QUEUED or STATE_ACTIVE */
142 videobuf_waiton(&buf->vb, 0, 0);
143 videobuf_dma_unmap(vq, dma);
144 videobuf_dma_free(dma);
147 dma_free_coherent(pcdev->dev, buf->sg_size, buf->sg_cpu,
151 buf->vb.state = VIDEOBUF_NEEDS_INIT;
155 pxa_videobuf_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
156 enum v4l2_field field)
158 struct soc_camera_device *icd = vq->priv_data;
159 struct soc_camera_host *ici =
160 to_soc_camera_host(icd->dev.parent);
161 struct pxa_camera_dev *pcdev = ici->priv;
162 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
165 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__,
166 vb, vb->baddr, vb->bsize);
168 /* Added list head initialization on alloc */
169 WARN_ON(!list_empty(&vb->queue));
172 /* This can be useful if you want to see if we actually fill
173 * the buffer with something */
174 memset((void *)vb->baddr, 0xaa, vb->bsize);
177 BUG_ON(NULL == icd->current_fmt);
179 /* I think, in buf_prepare you only have to protect global data,
180 * the actual buffer is yours */
183 if (buf->fmt != icd->current_fmt ||
184 vb->width != icd->width ||
185 vb->height != icd->height ||
186 vb->field != field) {
187 buf->fmt = icd->current_fmt;
188 vb->width = icd->width;
189 vb->height = icd->height;
191 vb->state = VIDEOBUF_NEEDS_INIT;
194 vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
195 if (0 != vb->baddr && vb->bsize < vb->size) {
200 if (vb->state == VIDEOBUF_NEEDS_INIT) {
201 unsigned int size = vb->size;
202 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
204 ret = videobuf_iolock(vq, vb, NULL);
209 dma_free_coherent(pcdev->dev, buf->sg_size, buf->sg_cpu,
212 buf->sg_size = (dma->sglen + 1) * sizeof(struct pxa_dma_desc);
213 buf->sg_cpu = dma_alloc_coherent(pcdev->dev, buf->sg_size,
214 &buf->sg_dma, GFP_KERNEL);
220 dev_dbg(&icd->dev, "nents=%d size: %d sg=0x%p\n",
221 dma->sglen, size, dma->sglist);
222 for (i = 0; i < dma->sglen; i++) {
223 struct scatterlist *sg = dma->sglist;
224 unsigned int dma_len = sg_dma_len(&sg[i]), xfer_len;
227 buf->sg_cpu[i].dsadr = pcdev->res->start + 0x28;
228 buf->sg_cpu[i].dtadr = sg_dma_address(&sg[i]);
229 /* PXA270 Developer's Manual 27.4.4.1:
230 * round up to 8 bytes */
231 xfer_len = (min(dma_len, size) + 7) & ~7;
233 dev_err(&icd->dev, "Unaligned buffer: "
234 "dma_len %u, size %u\n", dma_len, size);
235 buf->sg_cpu[i].dcmd = DCMD_FLOWSRC | DCMD_BURST8 |
236 DCMD_INCTRGADDR | xfer_len;
238 buf->sg_cpu[i].ddadr = buf->sg_dma + (i + 1) *
239 sizeof(struct pxa_dma_desc);
241 buf->sg_cpu[dma->sglen - 1].ddadr = DDADR_STOP;
242 buf->sg_cpu[dma->sglen - 1].dcmd |= DCMD_ENDIRQEN;
244 vb->state = VIDEOBUF_PREPARED;
252 free_buffer(vq, buf);
259 pxa_videobuf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
261 struct soc_camera_device *icd = vq->priv_data;
262 struct soc_camera_host *ici =
263 to_soc_camera_host(icd->dev.parent);
264 struct pxa_camera_dev *pcdev = ici->priv;
265 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
266 struct pxa_buffer *active = pcdev->active;
267 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
268 int nents = dma->sglen;
271 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__,
272 vb, vb->baddr, vb->bsize);
273 spin_lock_irqsave(&pcdev->lock, flags);
275 list_add_tail(&vb->queue, &pcdev->capture);
277 vb->state = VIDEOBUF_ACTIVE;
279 if (!pcdev->active) {
280 CIFR |= CIFR_RESET_F;
281 DDADR(pcdev->dma_chan_y) = buf->sg_dma;
282 DCSR(pcdev->dma_chan_y) = DCSR_RUN;
286 struct videobuf_dmabuf *active_dma =
287 videobuf_to_dma(&active->vb);
288 /* Stop DMA engine */
289 DCSR(pcdev->dma_chan_y) = 0;
291 /* Add the descriptors we just initialized to the currently
294 active->sg_cpu[active_dma->sglen - 1].ddadr = buf->sg_dma;
296 /* Setup a dummy descriptor with the DMA engines current
300 buf->sg_cpu[nents].dsadr = pcdev->res->start + 0x28;
301 buf->sg_cpu[nents].dtadr = DTADR(pcdev->dma_chan_y);
302 buf->sg_cpu[nents].dcmd = DCMD(pcdev->dma_chan_y);
304 if (DDADR(pcdev->dma_chan_y) == DDADR_STOP) {
305 /* The DMA engine is on the last descriptor, set the
306 * next descriptors address to the descriptors
307 * we just initialized
309 buf->sg_cpu[nents].ddadr = buf->sg_dma;
311 buf->sg_cpu[nents].ddadr = DDADR(pcdev->dma_chan_y);
314 /* The next descriptor is the dummy descriptor */
315 DDADR(pcdev->dma_chan_y) = buf->sg_dma + nents *
316 sizeof(struct pxa_dma_desc);
319 if (CISR & CISR_IFO_0) {
320 dev_warn(pcdev->dev, "FIFO overrun\n");
321 DDADR(pcdev->dma_chan_y) = pcdev->active->sg_dma;
324 CIFR |= CIFR_RESET_F;
325 DCSR(pcdev->dma_chan_y) = DCSR_RUN;
329 DCSR(pcdev->dma_chan_y) = DCSR_RUN;
332 spin_unlock_irqrestore(&pcdev->lock, flags);
336 static void pxa_videobuf_release(struct videobuf_queue *vq,
337 struct videobuf_buffer *vb)
339 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
341 struct soc_camera_device *icd = vq->priv_data;
343 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__,
344 vb, vb->baddr, vb->bsize);
347 case VIDEOBUF_ACTIVE:
348 dev_dbg(&icd->dev, "%s (active)\n", __FUNCTION__);
350 case VIDEOBUF_QUEUED:
351 dev_dbg(&icd->dev, "%s (queued)\n", __FUNCTION__);
353 case VIDEOBUF_PREPARED:
354 dev_dbg(&icd->dev, "%s (prepared)\n", __FUNCTION__);
357 dev_dbg(&icd->dev, "%s (unknown)\n", __FUNCTION__);
362 free_buffer(vq, buf);
365 static void pxa_camera_dma_irq_y(int channel, void *data)
367 struct pxa_camera_dev *pcdev = data;
368 struct pxa_buffer *buf;
371 struct videobuf_buffer *vb;
373 spin_lock_irqsave(&pcdev->lock, flags);
375 status = DCSR(pcdev->dma_chan_y);
376 if (status & DCSR_BUSERR) {
377 dev_err(pcdev->dev, "%s: Bus Error\n", __FUNCTION__);
378 DCSR(pcdev->dma_chan_y) |= DCSR_BUSERR;
382 if (!(status & DCSR_ENDINTR)) {
383 dev_err(pcdev->dev, "%s: unknown dma interrupt source. "
384 "status: 0x%08x\n", __FUNCTION__, status);
388 DCSR(pcdev->dma_chan_y) |= DCSR_ENDINTR;
390 if (!pcdev->active) {
391 dev_err(pcdev->dev, "%s: no active buf\n", __FUNCTION__);
395 vb = &pcdev->active->vb;
396 buf = container_of(vb, struct pxa_buffer, vb);
397 WARN_ON(buf->inwork || list_empty(&vb->queue));
398 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __FUNCTION__,
399 vb, vb->baddr, vb->bsize);
401 /* _init is used to debug races, see comment in pxa_is_reqbufs() */
402 list_del_init(&vb->queue);
403 vb->state = VIDEOBUF_DONE;
404 do_gettimeofday(&vb->ts);
408 if (list_empty(&pcdev->capture)) {
409 pcdev->active = NULL;
410 DCSR(pcdev->dma_chan_y) = 0;
415 pcdev->active = list_entry(pcdev->capture.next, struct pxa_buffer,
419 spin_unlock_irqrestore(&pcdev->lock, flags);
422 static struct videobuf_queue_ops pxa_video_ops = {
423 .buf_setup = pxa_videobuf_setup,
424 .buf_prepare = pxa_videobuf_prepare,
425 .buf_queue = pxa_videobuf_queue,
426 .buf_release = pxa_videobuf_release,
429 static int mclk_get_divisor(struct pxa_camera_dev *pcdev)
431 unsigned int mclk_10khz = pcdev->platform_mclk_10khz;
433 unsigned long lcdclk;
435 lcdclk = clk_get_rate(pcdev->clk) / 10000;
437 /* We verify platform_mclk_10khz != 0, so if anyone breaks it, here
438 * they get a nice Oops */
439 div = (lcdclk + 2 * mclk_10khz - 1) / (2 * mclk_10khz) - 1;
441 dev_dbg(pcdev->dev, "LCD clock %lukHz, target freq %dkHz, "
442 "divisor %lu\n", lcdclk * 10, mclk_10khz * 10, div);
447 static void pxa_is_activate(struct pxa_camera_dev *pcdev)
449 struct pxacamera_platform_data *pdata = pcdev->pdata;
452 dev_dbg(pcdev->dev, "Registered platform device at %p data %p\n",
455 if (pdata && pdata->init) {
456 dev_dbg(pcdev->dev, "%s: Init gpios\n", __FUNCTION__);
457 pdata->init(pcdev->dev);
460 if (pdata && pdata->power) {
461 dev_dbg(pcdev->dev, "%s: Power on camera\n", __FUNCTION__);
462 pdata->power(pcdev->dev, 1);
465 if (pdata && pdata->reset) {
466 dev_dbg(pcdev->dev, "%s: Releasing camera reset\n",
468 pdata->reset(pcdev->dev, 1);
471 CICR0 = 0x3FF; /* disable all interrupts */
473 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
474 cicr4 |= CICR4_PCLK_EN;
475 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
476 cicr4 |= CICR4_MCLK_EN;
477 if (pcdev->platform_flags & PXA_CAMERA_PCP)
479 if (pcdev->platform_flags & PXA_CAMERA_HSP)
481 if (pcdev->platform_flags & PXA_CAMERA_VSP)
484 CICR4 = mclk_get_divisor(pcdev) | cicr4;
486 clk_enable(pcdev->clk);
489 static void pxa_is_deactivate(struct pxa_camera_dev *pcdev)
491 struct pxacamera_platform_data *board = pcdev->pdata;
493 clk_disable(pcdev->clk);
495 if (board && board->reset) {
496 dev_dbg(pcdev->dev, "%s: Asserting camera reset\n",
498 board->reset(pcdev->dev, 0);
501 if (board && board->power) {
502 dev_dbg(pcdev->dev, "%s: Power off camera\n", __FUNCTION__);
503 board->power(pcdev->dev, 0);
507 static irqreturn_t pxa_camera_irq(int irq, void *data)
509 struct pxa_camera_dev *pcdev = data;
510 unsigned int status = CISR;
512 dev_dbg(pcdev->dev, "Camera interrupt status 0x%x\n", status);
519 /* The following two functions absolutely depend on the fact, that
520 * there can be only one camera on PXA quick capture interface */
521 static int pxa_is_add_device(struct soc_camera_device *icd)
523 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
524 struct pxa_camera_dev *pcdev = ici->priv;
527 mutex_lock(&camera_lock);
534 dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
537 pxa_is_activate(pcdev);
538 ret = icd->ops->init(icd);
544 mutex_unlock(&camera_lock);
549 static void pxa_is_remove_device(struct soc_camera_device *icd)
551 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
552 struct pxa_camera_dev *pcdev = ici->priv;
554 BUG_ON(icd != pcdev->icd);
556 dev_info(&icd->dev, "PXA Camera driver detached from camera %d\n",
559 /* disable capture, disable interrupts */
561 /* Stop DMA engine */
562 DCSR(pcdev->dma_chan_y) = 0;
564 icd->ops->release(icd);
566 pxa_is_deactivate(pcdev);
571 static int pxa_is_set_capture_format(struct soc_camera_device *icd,
572 __u32 pixfmt, struct v4l2_rect *rect)
574 struct soc_camera_host *ici =
575 to_soc_camera_host(icd->dev.parent);
576 struct pxa_camera_dev *pcdev = ici->priv;
577 unsigned int datawidth = 0, dw, bpp;
578 u32 cicr0, cicr4 = 0;
581 /* If requested data width is supported by the platform, use it */
582 switch (icd->cached_datawidth) {
584 if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10)
585 datawidth = IS_DATAWIDTH_10;
588 if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9)
589 datawidth = IS_DATAWIDTH_9;
592 if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8)
593 datawidth = IS_DATAWIDTH_8;
598 ret = icd->ops->set_capture_format(icd, pixfmt, rect,
600 (pcdev->platform_flags & PXA_CAMERA_MASTER ?
602 (pcdev->platform_flags & PXA_CAMERA_HSP ?
603 0 : IS_HSYNC_ACTIVE_HIGH) |
604 (pcdev->platform_flags & PXA_CAMERA_VSP ?
605 0 : IS_VSYNC_ACTIVE_HIGH) |
606 (pcdev->platform_flags & PXA_CAMERA_PCP ?
607 0 : IS_PCLK_SAMPLE_RISING));
611 /* Datawidth is now guaranteed to be equal to one of the three values.
612 * We fix bit-per-pixel equal to data-width... */
614 case IS_DATAWIDTH_10:
615 icd->cached_datawidth = 10;
620 icd->cached_datawidth = 9;
625 /* Actually it can only be 8 now,
626 * default is just to silence compiler warnings */
628 icd->cached_datawidth = 8;
633 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
634 cicr4 |= CICR4_PCLK_EN;
635 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
636 cicr4 |= CICR4_MCLK_EN;
637 if (pcdev->platform_flags & PXA_CAMERA_PCP)
639 if (pcdev->platform_flags & PXA_CAMERA_HSP)
641 if (pcdev->platform_flags & PXA_CAMERA_VSP)
645 if (cicr0 & CICR0_ENB)
646 CICR0 = cicr0 & ~CICR0_ENB;
647 CICR1 = CICR1_PPL_VAL(rect->width - 1) | bpp | dw;
649 CICR3 = CICR3_LPF_VAL(rect->height - 1) |
650 CICR3_BFW_VAL(min((unsigned short)255, icd->y_skip_top));
651 CICR4 = mclk_get_divisor(pcdev) | cicr4;
653 /* CIF interrupts are not used, only DMA */
654 CICR0 = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
655 0 : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) |
656 CICR0_DMAEN | CICR0_IRQ_MASK | (cicr0 & CICR0_ENB);
661 static int pxa_is_try_fmt_cap(struct soc_camera_host *ici,
662 struct v4l2_format *f)
664 /* limit to pxa hardware capabilities */
665 if (f->fmt.pix.height < 32)
666 f->fmt.pix.height = 32;
667 if (f->fmt.pix.height > 2048)
668 f->fmt.pix.height = 2048;
669 if (f->fmt.pix.width < 48)
670 f->fmt.pix.width = 48;
671 if (f->fmt.pix.width > 2048)
672 f->fmt.pix.width = 2048;
673 f->fmt.pix.width &= ~0x01;
678 static int pxa_is_reqbufs(struct soc_camera_file *icf,
679 struct v4l2_requestbuffers *p)
683 /* This is for locking debugging only. I removed spinlocks and now I
684 * check whether .prepare is ever called on a linked buffer, or whether
685 * a dma IRQ can occur for an in-work or unlinked buffer. Until now
686 * it hadn't triggered */
687 for (i = 0; i < p->count; i++) {
688 struct pxa_buffer *buf = container_of(icf->vb_vidq.bufs[i],
689 struct pxa_buffer, vb);
691 INIT_LIST_HEAD(&buf->vb.queue);
697 static unsigned int pxa_is_poll(struct file *file, poll_table *pt)
699 struct soc_camera_file *icf = file->private_data;
700 struct pxa_buffer *buf;
702 buf = list_entry(icf->vb_vidq.stream.next, struct pxa_buffer,
705 poll_wait(file, &buf->vb.done, pt);
707 if (buf->vb.state == VIDEOBUF_DONE ||
708 buf->vb.state == VIDEOBUF_ERROR)
709 return POLLIN|POLLRDNORM;
714 static int pxa_is_querycap(struct soc_camera_host *ici,
715 struct v4l2_capability *cap)
717 /* cap->name is set by the firendly caller:-> */
718 strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card));
719 cap->version = PXA_CAM_VERSION_CODE;
720 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
725 /* Should beallocated dynamically too, but we have only one. */
726 static struct soc_camera_host pxa_soc_camera_host = {
727 .drv_name = PXA_CAM_DRV_NAME,
728 .vbq_ops = &pxa_video_ops,
729 .add = pxa_is_add_device,
730 .remove = pxa_is_remove_device,
731 .msize = sizeof(struct pxa_buffer),
732 .set_capture_format = pxa_is_set_capture_format,
733 .try_fmt_cap = pxa_is_try_fmt_cap,
734 .reqbufs = pxa_is_reqbufs,
736 .querycap = pxa_is_querycap,
739 static int pxa_camera_probe(struct platform_device *pdev)
741 struct pxa_camera_dev *pcdev;
742 struct resource *res;
747 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
748 irq = platform_get_irq(pdev, 0);
754 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
756 dev_err(&pdev->dev, "%s: Could not allocate pcdev\n",
762 pcdev->clk = clk_get(&pdev->dev, "CAMCLK");
763 if (IS_ERR(pcdev->clk)) {
764 err = PTR_ERR(pcdev->clk);
768 dev_set_drvdata(&pdev->dev, pcdev);
771 pcdev->pdata = pdev->dev.platform_data;
772 pcdev->platform_flags = pcdev->pdata->flags;
773 if (!pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 |
774 PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10)) {
775 /* Platform hasn't set available data widths. This is bad.
776 * Warn and use a default. */
777 dev_warn(&pdev->dev, "WARNING! Platform hasn't set available "
778 "data widths, using default 10 bit\n");
779 pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10;
781 pcdev->platform_mclk_10khz = pcdev->pdata->mclk_10khz;
782 if (!pcdev->platform_mclk_10khz) {
784 "mclk_10khz == 0! Please, fix your platform data. "
785 "Using default 20MHz\n");
786 pcdev->platform_mclk_10khz = 2000;
789 INIT_LIST_HEAD(&pcdev->capture);
790 spin_lock_init(&pcdev->lock);
793 * Request the regions.
795 if (!request_mem_region(res->start, res->end - res->start + 1,
801 base = ioremap(res->start, res->end - res->start + 1);
808 pcdev->dev = &pdev->dev;
811 pcdev->dma_chan_y = pxa_request_dma("CI_Y", DMA_PRIO_HIGH,
812 pxa_camera_dma_irq_y, pcdev);
813 if (pcdev->dma_chan_y < 0) {
814 dev_err(pcdev->dev, "Can't request DMA for Y\n");
818 dev_dbg(pcdev->dev, "got DMA channel %d\n", pcdev->dma_chan_y);
820 DRCMR68 = pcdev->dma_chan_y | DRCMR_MAPVLD;
823 err = request_irq(pcdev->irq, pxa_camera_irq, 0, PXA_CAM_DRV_NAME,
826 dev_err(pcdev->dev, "Camera interrupt register failed \n");
830 pxa_soc_camera_host.priv = pcdev;
831 pxa_soc_camera_host.dev.parent = &pdev->dev;
832 pxa_soc_camera_host.nr = pdev->id;
833 err = soc_camera_host_register(&pxa_soc_camera_host, THIS_MODULE);
840 free_irq(pcdev->irq, pcdev);
842 pxa_free_dma(pcdev->dma_chan_y);
846 release_mem_region(res->start, res->end - res->start + 1);
855 static int __devexit pxa_camera_remove(struct platform_device *pdev)
857 struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
858 struct resource *res;
862 pxa_free_dma(pcdev->dma_chan_y);
863 free_irq(pcdev->irq, pcdev);
865 soc_camera_host_unregister(&pxa_soc_camera_host);
867 iounmap(pcdev->base);
870 release_mem_region(res->start, res->end - res->start + 1);
874 dev_info(&pdev->dev, "%s: PXA Camera driver unloaded\n", __FUNCTION__);
880 * Suspend the Camera Module.
882 static int pxa_camera_suspend(struct platform_device *pdev, pm_message_t level)
884 struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
886 dev_info(&pdev->dev, "camera suspend\n");
887 disable_irq(pcdev->irq);
892 * Resume the Camera Module.
894 static int pxa_camera_resume(struct platform_device *pdev)
896 struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
898 dev_info(&pdev->dev, "camera resume\n");
899 enable_irq(pcdev->irq);
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; */
911 static struct platform_driver pxa_camera_driver = {
913 .name = PXA_CAM_DRV_NAME,
915 .probe = pxa_camera_probe,
916 .remove = __exit_p(pxa_camera_remove),
917 .suspend = pxa_camera_suspend,
918 .resume = pxa_camera_resume,
922 static int __devinit pxa_camera_init(void)
924 return platform_driver_register(&pxa_camera_driver);
927 static void __exit pxa_camera_exit(void)
929 return platform_driver_unregister(&pxa_camera_driver);
932 module_init(pxa_camera_init);
933 module_exit(pxa_camera_exit);
935 MODULE_DESCRIPTION("PXA27x SoC Camera Host driver");
936 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
937 MODULE_LICENSE("GPL");