2 * V4L2 Driver for i.MXL/i.MXL camera (CSI) host
4 * Copyright (C) 2008, Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
5 * Copyright (C) 2009, Darius Augulis <augulis.darius@gmail.com>
7 * Based on PXA SoC camera driver
8 * Copyright (C) 2006, Sascha Hauer, Pengutronix
9 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/clk.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
25 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/mutex.h>
30 #include <linux/platform_device.h>
31 #include <linux/time.h>
32 #include <linux/version.h>
33 #include <linux/videodev2.h>
35 #include <media/soc_camera.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-dev.h>
38 #include <media/videobuf-dma-contig.h>
42 #include <mach/dma-mx1-mx2.h>
43 #include <mach/hardware.h>
44 #include <mach/mx1_camera.h>
49 #define DMA_CCR(x) (0x8c + ((x) << 6)) /* Control Registers */
50 #define DMA_DIMR 0x08 /* Interrupt mask Register */
51 #define CSICR1 0x00 /* CSI Control Register 1 */
52 #define CSISR 0x08 /* CSI Status Register */
53 #define CSIRXR 0x10 /* CSI RxFIFO Register */
55 #define CSICR1_RXFF_LEVEL(x) (((x) & 0x3) << 19)
56 #define CSICR1_SOF_POL (1 << 17)
57 #define CSICR1_SOF_INTEN (1 << 16)
58 #define CSICR1_MCLKDIV(x) (((x) & 0xf) << 12)
59 #define CSICR1_MCLKEN (1 << 9)
60 #define CSICR1_FCC (1 << 8)
61 #define CSICR1_BIG_ENDIAN (1 << 7)
62 #define CSICR1_CLR_RXFIFO (1 << 5)
63 #define CSICR1_GCLK_MODE (1 << 4)
64 #define CSICR1_DATA_POL (1 << 2)
65 #define CSICR1_REDGE (1 << 1)
66 #define CSICR1_EN (1 << 0)
68 #define CSISR_SFF_OR_INT (1 << 25)
69 #define CSISR_RFF_OR_INT (1 << 24)
70 #define CSISR_STATFF_INT (1 << 21)
71 #define CSISR_RXFF_INT (1 << 18)
72 #define CSISR_SOF_INT (1 << 16)
73 #define CSISR_DRDY (1 << 0)
75 #define VERSION_CODE KERNEL_VERSION(0, 0, 1)
76 #define DRIVER_NAME "mx1-camera"
78 #define CSI_IRQ_MASK (CSISR_SFF_OR_INT | CSISR_RFF_OR_INT | \
79 CSISR_STATFF_INT | CSISR_RXFF_INT | CSISR_SOF_INT)
81 #define CSI_BUS_FLAGS (SOCAM_MASTER | SOCAM_HSYNC_ACTIVE_HIGH | \
82 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW | \
83 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \
84 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_LOW | \
87 #define MAX_VIDEO_MEM 16 /* Video memory limit in megabytes */
93 /* buffer for one video frame */
95 /* common v4l buffer stuff -- must be first */
96 struct videobuf_buffer vb
;
97 const struct soc_camera_data_format
*fmt
;
101 /* i.MX1/i.MXL is only supposed to handle one camera on its Camera Sensor
102 * Interface. If anyone ever builds hardware to enable more than
103 * one camera, they will have to modify this driver too */
104 struct mx1_camera_dev
{
105 struct soc_camera_device
*icd
;
106 struct mx1_camera_pdata
*pdata
;
107 struct mx1_buffer
*active
;
109 struct resource
*res
;
111 struct list_head capture
;
122 * Videobuf operations
124 static int mx1_videobuf_setup(struct videobuf_queue
*vq
, unsigned int *count
,
127 struct soc_camera_device
*icd
= vq
->priv_data
;
129 *size
= icd
->width
* icd
->height
*
130 ((icd
->current_fmt
->depth
+ 7) >> 3);
135 while (*size
* *count
> MAX_VIDEO_MEM
* 1024 * 1024)
138 dev_dbg(&icd
->dev
, "count=%d, size=%d\n", *count
, *size
);
143 static void free_buffer(struct videobuf_queue
*vq
, struct mx1_buffer
*buf
)
145 struct soc_camera_device
*icd
= vq
->priv_data
;
146 struct videobuf_buffer
*vb
= &buf
->vb
;
148 BUG_ON(in_interrupt());
150 dev_dbg(&icd
->dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
151 vb
, vb
->baddr
, vb
->bsize
);
153 /* This waits until this buffer is out of danger, i.e., until it is no
154 * longer in STATE_QUEUED or STATE_ACTIVE */
155 videobuf_waiton(vb
, 0, 0);
156 videobuf_dma_contig_free(vq
, vb
);
158 vb
->state
= VIDEOBUF_NEEDS_INIT
;
161 static int mx1_videobuf_prepare(struct videobuf_queue
*vq
,
162 struct videobuf_buffer
*vb
, enum v4l2_field field
)
164 struct soc_camera_device
*icd
= vq
->priv_data
;
165 struct mx1_buffer
*buf
= container_of(vb
, struct mx1_buffer
, vb
);
168 dev_dbg(&icd
->dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
169 vb
, vb
->baddr
, vb
->bsize
);
171 /* Added list head initialization on alloc */
172 WARN_ON(!list_empty(&vb
->queue
));
174 BUG_ON(NULL
== icd
->current_fmt
);
176 /* I think, in buf_prepare you only have to protect global data,
177 * the actual buffer is yours */
180 if (buf
->fmt
!= icd
->current_fmt
||
181 vb
->width
!= icd
->width
||
182 vb
->height
!= icd
->height
||
183 vb
->field
!= field
) {
184 buf
->fmt
= icd
->current_fmt
;
185 vb
->width
= icd
->width
;
186 vb
->height
= icd
->height
;
188 vb
->state
= VIDEOBUF_NEEDS_INIT
;
191 vb
->size
= vb
->width
* vb
->height
* ((buf
->fmt
->depth
+ 7) >> 3);
192 if (0 != vb
->baddr
&& vb
->bsize
< vb
->size
) {
197 if (vb
->state
== VIDEOBUF_NEEDS_INIT
) {
198 ret
= videobuf_iolock(vq
, vb
, NULL
);
202 vb
->state
= VIDEOBUF_PREPARED
;
210 free_buffer(vq
, buf
);
216 static int mx1_camera_setup_dma(struct mx1_camera_dev
*pcdev
)
218 struct videobuf_buffer
*vbuf
= &pcdev
->active
->vb
;
221 if (unlikely(!pcdev
->active
)) {
222 dev_err(pcdev
->dev
, "DMA End IRQ with no active buffer\n");
226 /* setup sg list for future DMA */
227 ret
= imx_dma_setup_single(pcdev
->dma_chan
,
228 videobuf_to_dma_contig(vbuf
),
229 vbuf
->size
, pcdev
->res
->start
+
230 CSIRXR
, DMA_MODE_READ
);
232 dev_err(pcdev
->dev
, "Failed to setup DMA sg list\n");
237 static void mx1_videobuf_queue(struct videobuf_queue
*vq
,
238 struct videobuf_buffer
*vb
)
240 struct soc_camera_device
*icd
= vq
->priv_data
;
241 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
242 struct mx1_camera_dev
*pcdev
= ici
->priv
;
243 struct mx1_buffer
*buf
= container_of(vb
, struct mx1_buffer
, vb
);
246 dev_dbg(&icd
->dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
247 vb
, vb
->baddr
, vb
->bsize
);
249 spin_lock_irqsave(&pcdev
->lock
, flags
);
251 list_add_tail(&vb
->queue
, &pcdev
->capture
);
253 vb
->state
= VIDEOBUF_ACTIVE
;
255 if (!pcdev
->active
) {
258 /* setup sg list for future DMA */
259 if (!mx1_camera_setup_dma(pcdev
)) {
262 temp
= __raw_readl(pcdev
->base
+ CSICR1
) |
264 __raw_writel(temp
, pcdev
->base
+ CSICR1
);
268 spin_unlock_irqrestore(&pcdev
->lock
, flags
);
271 static void mx1_videobuf_release(struct videobuf_queue
*vq
,
272 struct videobuf_buffer
*vb
)
274 struct mx1_buffer
*buf
= container_of(vb
, struct mx1_buffer
, vb
);
276 struct soc_camera_device
*icd
= vq
->priv_data
;
278 dev_dbg(&icd
->dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
279 vb
, vb
->baddr
, vb
->bsize
);
282 case VIDEOBUF_ACTIVE
:
283 dev_dbg(&icd
->dev
, "%s (active)\n", __func__
);
285 case VIDEOBUF_QUEUED
:
286 dev_dbg(&icd
->dev
, "%s (queued)\n", __func__
);
288 case VIDEOBUF_PREPARED
:
289 dev_dbg(&icd
->dev
, "%s (prepared)\n", __func__
);
292 dev_dbg(&icd
->dev
, "%s (unknown)\n", __func__
);
297 free_buffer(vq
, buf
);
300 static void mx1_camera_wakeup(struct mx1_camera_dev
*pcdev
,
301 struct videobuf_buffer
*vb
,
302 struct mx1_buffer
*buf
)
304 /* _init is used to debug races, see comment in mx1_camera_reqbufs() */
305 list_del_init(&vb
->queue
);
306 vb
->state
= VIDEOBUF_DONE
;
307 do_gettimeofday(&vb
->ts
);
311 if (list_empty(&pcdev
->capture
)) {
312 pcdev
->active
= NULL
;
316 pcdev
->active
= list_entry(pcdev
->capture
.next
,
317 struct mx1_buffer
, vb
.queue
);
319 /* setup sg list for future DMA */
320 if (likely(!mx1_camera_setup_dma(pcdev
))) {
324 temp
= __raw_readl(pcdev
->base
+ CSICR1
) | CSICR1_SOF_INTEN
;
325 __raw_writel(temp
, pcdev
->base
+ CSICR1
);
329 static void mx1_camera_dma_irq(int channel
, void *data
)
331 struct mx1_camera_dev
*pcdev
= data
;
332 struct mx1_buffer
*buf
;
333 struct videobuf_buffer
*vb
;
336 spin_lock_irqsave(&pcdev
->lock
, flags
);
338 imx_dma_disable(channel
);
340 if (unlikely(!pcdev
->active
)) {
341 dev_err(pcdev
->dev
, "DMA End IRQ with no active buffer\n");
345 vb
= &pcdev
->active
->vb
;
346 buf
= container_of(vb
, struct mx1_buffer
, vb
);
347 WARN_ON(buf
->inwork
|| list_empty(&vb
->queue
));
348 dev_dbg(pcdev
->dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
349 vb
, vb
->baddr
, vb
->bsize
);
351 mx1_camera_wakeup(pcdev
, vb
, buf
);
353 spin_unlock_irqrestore(&pcdev
->lock
, flags
);
356 static struct videobuf_queue_ops mx1_videobuf_ops
= {
357 .buf_setup
= mx1_videobuf_setup
,
358 .buf_prepare
= mx1_videobuf_prepare
,
359 .buf_queue
= mx1_videobuf_queue
,
360 .buf_release
= mx1_videobuf_release
,
363 static void mx1_camera_init_videobuf(struct videobuf_queue
*q
,
364 struct soc_camera_device
*icd
)
366 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
367 struct mx1_camera_dev
*pcdev
= ici
->priv
;
369 videobuf_queue_dma_contig_init(q
, &mx1_videobuf_ops
, pcdev
->dev
,
371 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
373 sizeof(struct mx1_buffer
), icd
);
376 static int mclk_get_divisor(struct mx1_camera_dev
*pcdev
)
378 unsigned int mclk
= pcdev
->mclk
;
380 unsigned long lcdclk
;
382 lcdclk
= clk_get_rate(pcdev
->clk
);
384 /* We verify platform_mclk_10khz != 0, so if anyone breaks it, here
385 * they get a nice Oops */
386 div
= (lcdclk
+ 2 * mclk
- 1) / (2 * mclk
) - 1;
388 dev_dbg(pcdev
->dev
, "System clock %lukHz, target freq %dkHz, "
389 "divisor %lu\n", lcdclk
/ 1000, mclk
/ 1000, div
);
394 static void mx1_camera_activate(struct mx1_camera_dev
*pcdev
)
396 unsigned int csicr1
= CSICR1_EN
;
398 dev_dbg(pcdev
->dev
, "Activate device\n");
400 clk_enable(pcdev
->clk
);
402 /* enable CSI before doing anything else */
403 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
405 csicr1
|= CSICR1_MCLKEN
| CSICR1_FCC
| CSICR1_GCLK_MODE
;
406 csicr1
|= CSICR1_MCLKDIV(mclk_get_divisor(pcdev
));
407 csicr1
|= CSICR1_RXFF_LEVEL(2); /* 16 words */
409 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
412 static void mx1_camera_deactivate(struct mx1_camera_dev
*pcdev
)
414 dev_dbg(pcdev
->dev
, "Deactivate device\n");
416 /* Disable all CSI interface */
417 __raw_writel(0x00, pcdev
->base
+ CSICR1
);
419 clk_disable(pcdev
->clk
);
422 /* The following two functions absolutely depend on the fact, that
423 * there can be only one camera on i.MX1/i.MXL camera sensor interface */
424 static int mx1_camera_add_device(struct soc_camera_device
*icd
)
426 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
427 struct mx1_camera_dev
*pcdev
= ici
->priv
;
435 dev_info(&icd
->dev
, "MX1 Camera driver attached to camera %d\n",
438 mx1_camera_activate(pcdev
);
439 ret
= icd
->ops
->init(icd
);
448 static void mx1_camera_remove_device(struct soc_camera_device
*icd
)
450 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
451 struct mx1_camera_dev
*pcdev
= ici
->priv
;
454 BUG_ON(icd
!= pcdev
->icd
);
456 /* disable interrupts */
457 csicr1
= __raw_readl(pcdev
->base
+ CSICR1
) & ~CSI_IRQ_MASK
;
458 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
460 /* Stop DMA engine */
461 imx_dma_disable(pcdev
->dma_chan
);
463 dev_info(&icd
->dev
, "MX1 Camera driver detached from camera %d\n",
466 icd
->ops
->release(icd
);
468 mx1_camera_deactivate(pcdev
);
473 static int mx1_camera_set_crop(struct soc_camera_device
*icd
,
474 struct v4l2_rect
*rect
)
476 return icd
->ops
->set_crop(icd
, rect
);
479 static int mx1_camera_set_bus_param(struct soc_camera_device
*icd
, __u32 pixfmt
)
481 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
482 struct mx1_camera_dev
*pcdev
= ici
->priv
;
483 unsigned long camera_flags
, common_flags
;
487 camera_flags
= icd
->ops
->query_bus_param(icd
);
489 /* MX1 supports only 8bit buswidth */
490 common_flags
= soc_camera_bus_param_compatible(camera_flags
,
497 /* Make choises, based on platform choice */
498 if ((common_flags
& SOCAM_VSYNC_ACTIVE_HIGH
) &&
499 (common_flags
& SOCAM_VSYNC_ACTIVE_LOW
)) {
501 pcdev
->pdata
->flags
& MX1_CAMERA_VSYNC_HIGH
)
502 common_flags
&= ~SOCAM_VSYNC_ACTIVE_LOW
;
504 common_flags
&= ~SOCAM_VSYNC_ACTIVE_HIGH
;
507 if ((common_flags
& SOCAM_PCLK_SAMPLE_RISING
) &&
508 (common_flags
& SOCAM_PCLK_SAMPLE_FALLING
)) {
510 pcdev
->pdata
->flags
& MX1_CAMERA_PCLK_RISING
)
511 common_flags
&= ~SOCAM_PCLK_SAMPLE_FALLING
;
513 common_flags
&= ~SOCAM_PCLK_SAMPLE_RISING
;
516 if ((common_flags
& SOCAM_DATA_ACTIVE_HIGH
) &&
517 (common_flags
& SOCAM_DATA_ACTIVE_LOW
)) {
519 pcdev
->pdata
->flags
& MX1_CAMERA_DATA_HIGH
)
520 common_flags
&= ~SOCAM_DATA_ACTIVE_LOW
;
522 common_flags
&= ~SOCAM_DATA_ACTIVE_HIGH
;
525 ret
= icd
->ops
->set_bus_param(icd
, common_flags
);
529 csicr1
= __raw_readl(pcdev
->base
+ CSICR1
);
531 if (common_flags
& SOCAM_PCLK_SAMPLE_RISING
)
532 csicr1
|= CSICR1_REDGE
;
533 if (common_flags
& SOCAM_VSYNC_ACTIVE_HIGH
)
534 csicr1
|= CSICR1_SOF_POL
;
535 if (common_flags
& SOCAM_DATA_ACTIVE_LOW
)
536 csicr1
|= CSICR1_DATA_POL
;
538 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
543 static int mx1_camera_set_fmt(struct soc_camera_device
*icd
,
544 struct v4l2_format
*f
)
546 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
547 const struct soc_camera_format_xlate
*xlate
;
548 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
551 xlate
= soc_camera_xlate_by_fourcc(icd
, pix
->pixelformat
);
553 dev_warn(&ici
->dev
, "Format %x not found\n", pix
->pixelformat
);
557 ret
= icd
->ops
->set_fmt(icd
, f
);
559 icd
->buswidth
= xlate
->buswidth
;
560 icd
->current_fmt
= xlate
->host_fmt
;
566 static int mx1_camera_try_fmt(struct soc_camera_device
*icd
,
567 struct v4l2_format
*f
)
569 /* TODO: limit to mx1 hardware capabilities */
571 /* limit to sensor capabilities */
572 return icd
->ops
->try_fmt(icd
, f
);
575 static int mx1_camera_reqbufs(struct soc_camera_file
*icf
,
576 struct v4l2_requestbuffers
*p
)
580 /* This is for locking debugging only. I removed spinlocks and now I
581 * check whether .prepare is ever called on a linked buffer, or whether
582 * a dma IRQ can occur for an in-work or unlinked buffer. Until now
583 * it hadn't triggered */
584 for (i
= 0; i
< p
->count
; i
++) {
585 struct mx1_buffer
*buf
= container_of(icf
->vb_vidq
.bufs
[i
],
586 struct mx1_buffer
, vb
);
588 INIT_LIST_HEAD(&buf
->vb
.queue
);
594 static unsigned int mx1_camera_poll(struct file
*file
, poll_table
*pt
)
596 struct soc_camera_file
*icf
= file
->private_data
;
597 struct mx1_buffer
*buf
;
599 buf
= list_entry(icf
->vb_vidq
.stream
.next
, struct mx1_buffer
,
602 poll_wait(file
, &buf
->vb
.done
, pt
);
604 if (buf
->vb
.state
== VIDEOBUF_DONE
||
605 buf
->vb
.state
== VIDEOBUF_ERROR
)
606 return POLLIN
| POLLRDNORM
;
611 static int mx1_camera_querycap(struct soc_camera_host
*ici
,
612 struct v4l2_capability
*cap
)
614 /* cap->name is set by the friendly caller:-> */
615 strlcpy(cap
->card
, "i.MX1/i.MXL Camera", sizeof(cap
->card
));
616 cap
->version
= VERSION_CODE
;
617 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
622 static struct soc_camera_host_ops mx1_soc_camera_host_ops
= {
623 .owner
= THIS_MODULE
,
624 .add
= mx1_camera_add_device
,
625 .remove
= mx1_camera_remove_device
,
626 .set_bus_param
= mx1_camera_set_bus_param
,
627 .set_crop
= mx1_camera_set_crop
,
628 .set_fmt
= mx1_camera_set_fmt
,
629 .try_fmt
= mx1_camera_try_fmt
,
630 .init_videobuf
= mx1_camera_init_videobuf
,
631 .reqbufs
= mx1_camera_reqbufs
,
632 .poll
= mx1_camera_poll
,
633 .querycap
= mx1_camera_querycap
,
636 /* Should be allocated dynamically too, but we have only one. */
637 static struct soc_camera_host mx1_soc_camera_host
= {
638 .drv_name
= DRIVER_NAME
,
639 .ops
= &mx1_soc_camera_host_ops
,
642 static struct fiq_handler fh
= {
646 static int __init
mx1_camera_probe(struct platform_device
*pdev
)
648 struct mx1_camera_dev
*pcdev
;
649 struct resource
*res
;
656 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
657 irq
= platform_get_irq(pdev
, 0);
663 clk
= clk_get(&pdev
->dev
, "csi_clk");
669 pcdev
= kzalloc(sizeof(*pcdev
), GFP_KERNEL
);
671 dev_err(&pdev
->dev
, "Could not allocate pcdev\n");
676 dev_set_drvdata(&pdev
->dev
, pcdev
);
680 pcdev
->pdata
= pdev
->dev
.platform_data
;
683 pcdev
->mclk
= pcdev
->pdata
->mclk_10khz
* 10000;
687 "mclk_10khz == 0! Please, fix your platform data. "
688 "Using default 20MHz\n");
689 pcdev
->mclk
= 20000000;
692 INIT_LIST_HEAD(&pcdev
->capture
);
693 spin_lock_init(&pcdev
->lock
);
696 * Request the regions.
698 if (!request_mem_region(res
->start
, resource_size(res
), DRIVER_NAME
)) {
703 base
= ioremap(res
->start
, resource_size(res
));
710 pcdev
->dev
= &pdev
->dev
;
713 pcdev
->dma_chan
= imx_dma_request_by_prio(DRIVER_NAME
, DMA_PRIO_HIGH
);
714 if (pcdev
->dma_chan
< 0) {
715 dev_err(pcdev
->dev
, "Can't request DMA for MX1 CSI\n");
719 dev_dbg(pcdev
->dev
, "got DMA channel %d\n", pcdev
->dma_chan
);
721 imx_dma_setup_handlers(pcdev
->dma_chan
, mx1_camera_dma_irq
, NULL
,
724 imx_dma_config_channel(pcdev
->dma_chan
, IMX_DMA_TYPE_FIFO
,
725 IMX_DMA_MEMSIZE_32
, DMA_REQ_CSI_R
, 0);
726 /* burst length : 16 words = 64 bytes */
727 imx_dma_config_burstlen(pcdev
->dma_chan
, 0);
730 err
= claim_fiq(&fh
);
732 dev_err(pcdev
->dev
, "Camera interrupt register failed \n");
736 set_fiq_handler(&mx1_camera_sof_fiq_start
, &mx1_camera_sof_fiq_end
-
737 &mx1_camera_sof_fiq_start
);
739 regs
.ARM_r8
= DMA_BASE
+ DMA_DIMR
;
740 regs
.ARM_r9
= DMA_BASE
+ DMA_CCR(pcdev
->dma_chan
);
741 regs
.ARM_r10
= (long)pcdev
->base
+ CSICR1
;
742 regs
.ARM_fp
= (long)pcdev
->base
+ CSISR
;
743 regs
.ARM_sp
= 1 << pcdev
->dma_chan
;
746 mxc_set_irq_fiq(irq
, 1);
749 mx1_soc_camera_host
.priv
= pcdev
;
750 mx1_soc_camera_host
.dev
.parent
= &pdev
->dev
;
751 mx1_soc_camera_host
.nr
= pdev
->id
;
752 err
= soc_camera_host_register(&mx1_soc_camera_host
);
756 dev_info(&pdev
->dev
, "MX1 Camera driver loaded\n");
762 mxc_set_irq_fiq(irq
, 0);
765 imx_dma_free(pcdev
->dma_chan
);
769 release_mem_region(res
->start
, resource_size(res
));
778 static int __exit
mx1_camera_remove(struct platform_device
*pdev
)
780 struct mx1_camera_dev
*pcdev
= platform_get_drvdata(pdev
);
781 struct resource
*res
;
783 imx_dma_free(pcdev
->dma_chan
);
784 disable_fiq(pcdev
->irq
);
785 mxc_set_irq_fiq(pcdev
->irq
, 0);
790 soc_camera_host_unregister(&mx1_soc_camera_host
);
792 iounmap(pcdev
->base
);
795 release_mem_region(res
->start
, resource_size(res
));
799 dev_info(&pdev
->dev
, "MX1 Camera driver unloaded\n");
804 static struct platform_driver mx1_camera_driver
= {
808 .remove
= __exit_p(mx1_camera_remove
),
811 static int __init
mx1_camera_init(void)
813 return platform_driver_probe(&mx1_camera_driver
, mx1_camera_probe
);
816 static void __exit
mx1_camera_exit(void)
818 return platform_driver_unregister(&mx1_camera_driver
);
821 module_init(mx1_camera_init
);
822 module_exit(mx1_camera_exit
);
824 MODULE_DESCRIPTION("i.MX1/i.MXL SoC Camera Host driver");
825 MODULE_AUTHOR("Paulius Zaleckas <paulius.zaleckas@teltonika.lt>");
826 MODULE_LICENSE("GPL v2");
827 MODULE_ALIAS("platform:" DRIVER_NAME
);