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/sched.h>
32 #include <linux/slab.h>
33 #include <linux/time.h>
34 #include <linux/version.h>
35 #include <linux/videodev2.h>
37 #include <media/soc_camera.h>
38 #include <media/v4l2-common.h>
39 #include <media/v4l2-dev.h>
40 #include <media/videobuf-dma-contig.h>
41 #include <media/soc_mediabus.h>
45 #include <mach/dma-mx1-mx2.h>
46 #include <mach/hardware.h>
47 #include <mach/mx1_camera.h>
52 #define DMA_CCR(x) (0x8c + ((x) << 6)) /* Control Registers */
53 #define DMA_DIMR 0x08 /* Interrupt mask Register */
54 #define CSICR1 0x00 /* CSI Control Register 1 */
55 #define CSISR 0x08 /* CSI Status Register */
56 #define CSIRXR 0x10 /* CSI RxFIFO Register */
58 #define CSICR1_RXFF_LEVEL(x) (((x) & 0x3) << 19)
59 #define CSICR1_SOF_POL (1 << 17)
60 #define CSICR1_SOF_INTEN (1 << 16)
61 #define CSICR1_MCLKDIV(x) (((x) & 0xf) << 12)
62 #define CSICR1_MCLKEN (1 << 9)
63 #define CSICR1_FCC (1 << 8)
64 #define CSICR1_BIG_ENDIAN (1 << 7)
65 #define CSICR1_CLR_RXFIFO (1 << 5)
66 #define CSICR1_GCLK_MODE (1 << 4)
67 #define CSICR1_DATA_POL (1 << 2)
68 #define CSICR1_REDGE (1 << 1)
69 #define CSICR1_EN (1 << 0)
71 #define CSISR_SFF_OR_INT (1 << 25)
72 #define CSISR_RFF_OR_INT (1 << 24)
73 #define CSISR_STATFF_INT (1 << 21)
74 #define CSISR_RXFF_INT (1 << 18)
75 #define CSISR_SOF_INT (1 << 16)
76 #define CSISR_DRDY (1 << 0)
78 #define VERSION_CODE KERNEL_VERSION(0, 0, 1)
79 #define DRIVER_NAME "mx1-camera"
81 #define CSI_IRQ_MASK (CSISR_SFF_OR_INT | CSISR_RFF_OR_INT | \
82 CSISR_STATFF_INT | CSISR_RXFF_INT | CSISR_SOF_INT)
84 #define CSI_BUS_FLAGS (SOCAM_MASTER | SOCAM_HSYNC_ACTIVE_HIGH | \
85 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW | \
86 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \
87 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_LOW | \
90 #define MAX_VIDEO_MEM 16 /* Video memory limit in megabytes */
96 /* buffer for one video frame */
98 /* common v4l buffer stuff -- must be first */
99 struct videobuf_buffer vb;
100 enum v4l2_mbus_pixelcode code;
105 * i.MX1/i.MXL is only supposed to handle one camera on its Camera Sensor
106 * Interface. If anyone ever builds hardware to enable more than
107 * one camera, they will have to modify this driver too
109 struct mx1_camera_dev {
110 struct soc_camera_host soc_host;
111 struct soc_camera_device *icd;
112 struct mx1_camera_pdata *pdata;
113 struct mx1_buffer *active;
114 struct resource *res;
116 struct list_head capture;
127 * Videobuf operations
129 static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
132 struct soc_camera_device *icd = vq->priv_data;
133 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
134 icd->current_fmt->host_fmt);
136 if (bytes_per_line < 0)
137 return bytes_per_line;
139 *size = bytes_per_line * icd->user_height;
144 while (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
147 dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size);
152 static void free_buffer(struct videobuf_queue *vq, struct mx1_buffer *buf)
154 struct soc_camera_device *icd = vq->priv_data;
155 struct videobuf_buffer *vb = &buf->vb;
157 BUG_ON(in_interrupt());
159 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
160 vb, vb->baddr, vb->bsize);
163 * This waits until this buffer is out of danger, i.e., until it is no
164 * longer in STATE_QUEUED or STATE_ACTIVE
166 videobuf_waiton(vb, 0, 0);
167 videobuf_dma_contig_free(vq, vb);
169 vb->state = VIDEOBUF_NEEDS_INIT;
172 static int mx1_videobuf_prepare(struct videobuf_queue *vq,
173 struct videobuf_buffer *vb, enum v4l2_field field)
175 struct soc_camera_device *icd = vq->priv_data;
176 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
178 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
179 icd->current_fmt->host_fmt);
181 if (bytes_per_line < 0)
182 return bytes_per_line;
184 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
185 vb, vb->baddr, vb->bsize);
187 /* Added list head initialization on alloc */
188 WARN_ON(!list_empty(&vb->queue));
190 BUG_ON(NULL == icd->current_fmt);
193 * I think, in buf_prepare you only have to protect global data,
194 * the actual buffer is yours
198 if (buf->code != icd->current_fmt->code ||
199 vb->width != icd->user_width ||
200 vb->height != icd->user_height ||
201 vb->field != field) {
202 buf->code = icd->current_fmt->code;
203 vb->width = icd->user_width;
204 vb->height = icd->user_height;
206 vb->state = VIDEOBUF_NEEDS_INIT;
209 vb->size = bytes_per_line * vb->height;
210 if (0 != vb->baddr && vb->bsize < vb->size) {
215 if (vb->state == VIDEOBUF_NEEDS_INIT) {
216 ret = videobuf_iolock(vq, vb, NULL);
220 vb->state = VIDEOBUF_PREPARED;
228 free_buffer(vq, buf);
234 static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
236 struct videobuf_buffer *vbuf = &pcdev->active->vb;
237 struct device *dev = pcdev->icd->dev.parent;
240 if (unlikely(!pcdev->active)) {
241 dev_err(dev, "DMA End IRQ with no active buffer\n");
245 /* setup sg list for future DMA */
246 ret = imx_dma_setup_single(pcdev->dma_chan,
247 videobuf_to_dma_contig(vbuf),
248 vbuf->size, pcdev->res->start +
249 CSIRXR, DMA_MODE_READ);
251 dev_err(dev, "Failed to setup DMA sg list\n");
256 /* Called under spinlock_irqsave(&pcdev->lock, ...) */
257 static void mx1_videobuf_queue(struct videobuf_queue *vq,
258 struct videobuf_buffer *vb)
260 struct soc_camera_device *icd = vq->priv_data;
261 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
262 struct mx1_camera_dev *pcdev = ici->priv;
263 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
265 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
266 vb, vb->baddr, vb->bsize);
268 list_add_tail(&vb->queue, &pcdev->capture);
270 vb->state = VIDEOBUF_ACTIVE;
272 if (!pcdev->active) {
275 /* setup sg list for future DMA */
276 if (!mx1_camera_setup_dma(pcdev)) {
279 temp = __raw_readl(pcdev->base + CSICR1) |
281 __raw_writel(temp, pcdev->base + CSICR1);
286 static void mx1_videobuf_release(struct videobuf_queue *vq,
287 struct videobuf_buffer *vb)
289 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
291 struct soc_camera_device *icd = vq->priv_data;
292 struct device *dev = icd->dev.parent;
294 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
295 vb, vb->baddr, vb->bsize);
298 case VIDEOBUF_ACTIVE:
299 dev_dbg(dev, "%s (active)\n", __func__);
301 case VIDEOBUF_QUEUED:
302 dev_dbg(dev, "%s (queued)\n", __func__);
304 case VIDEOBUF_PREPARED:
305 dev_dbg(dev, "%s (prepared)\n", __func__);
308 dev_dbg(dev, "%s (unknown)\n", __func__);
313 free_buffer(vq, buf);
316 static void mx1_camera_wakeup(struct mx1_camera_dev *pcdev,
317 struct videobuf_buffer *vb,
318 struct mx1_buffer *buf)
320 /* _init is used to debug races, see comment in mx1_camera_reqbufs() */
321 list_del_init(&vb->queue);
322 vb->state = VIDEOBUF_DONE;
323 do_gettimeofday(&vb->ts);
327 if (list_empty(&pcdev->capture)) {
328 pcdev->active = NULL;
332 pcdev->active = list_entry(pcdev->capture.next,
333 struct mx1_buffer, vb.queue);
335 /* setup sg list for future DMA */
336 if (likely(!mx1_camera_setup_dma(pcdev))) {
340 temp = __raw_readl(pcdev->base + CSICR1) | CSICR1_SOF_INTEN;
341 __raw_writel(temp, pcdev->base + CSICR1);
345 static void mx1_camera_dma_irq(int channel, void *data)
347 struct mx1_camera_dev *pcdev = data;
348 struct device *dev = pcdev->icd->dev.parent;
349 struct mx1_buffer *buf;
350 struct videobuf_buffer *vb;
353 spin_lock_irqsave(&pcdev->lock, flags);
355 imx_dma_disable(channel);
357 if (unlikely(!pcdev->active)) {
358 dev_err(dev, "DMA End IRQ with no active buffer\n");
362 vb = &pcdev->active->vb;
363 buf = container_of(vb, struct mx1_buffer, vb);
364 WARN_ON(buf->inwork || list_empty(&vb->queue));
365 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
366 vb, vb->baddr, vb->bsize);
368 mx1_camera_wakeup(pcdev, vb, buf);
370 spin_unlock_irqrestore(&pcdev->lock, flags);
373 static struct videobuf_queue_ops mx1_videobuf_ops = {
374 .buf_setup = mx1_videobuf_setup,
375 .buf_prepare = mx1_videobuf_prepare,
376 .buf_queue = mx1_videobuf_queue,
377 .buf_release = mx1_videobuf_release,
380 static void mx1_camera_init_videobuf(struct videobuf_queue *q,
381 struct soc_camera_device *icd)
383 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
384 struct mx1_camera_dev *pcdev = ici->priv;
386 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->dev.parent,
388 V4L2_BUF_TYPE_VIDEO_CAPTURE,
390 sizeof(struct mx1_buffer), icd);
393 static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
395 unsigned int mclk = pcdev->mclk;
397 unsigned long lcdclk;
399 lcdclk = clk_get_rate(pcdev->clk);
402 * We verify platform_mclk_10khz != 0, so if anyone breaks it, here
403 * they get a nice Oops
405 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
407 dev_dbg(pcdev->icd->dev.parent,
408 "System clock %lukHz, target freq %dkHz, divisor %lu\n",
409 lcdclk / 1000, mclk / 1000, div);
414 static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
416 unsigned int csicr1 = CSICR1_EN;
418 dev_dbg(pcdev->icd->dev.parent, "Activate device\n");
420 clk_enable(pcdev->clk);
422 /* enable CSI before doing anything else */
423 __raw_writel(csicr1, pcdev->base + CSICR1);
425 csicr1 |= CSICR1_MCLKEN | CSICR1_FCC | CSICR1_GCLK_MODE;
426 csicr1 |= CSICR1_MCLKDIV(mclk_get_divisor(pcdev));
427 csicr1 |= CSICR1_RXFF_LEVEL(2); /* 16 words */
429 __raw_writel(csicr1, pcdev->base + CSICR1);
432 static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
434 dev_dbg(pcdev->icd->dev.parent, "Deactivate device\n");
436 /* Disable all CSI interface */
437 __raw_writel(0x00, pcdev->base + CSICR1);
439 clk_disable(pcdev->clk);
443 * The following two functions absolutely depend on the fact, that
444 * there can be only one camera on i.MX1/i.MXL camera sensor interface
446 static int mx1_camera_add_device(struct soc_camera_device *icd)
448 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
449 struct mx1_camera_dev *pcdev = ici->priv;
457 dev_info(icd->dev.parent, "MX1 Camera driver attached to camera %d\n",
460 mx1_camera_activate(pcdev);
468 static void mx1_camera_remove_device(struct soc_camera_device *icd)
470 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
471 struct mx1_camera_dev *pcdev = ici->priv;
474 BUG_ON(icd != pcdev->icd);
476 /* disable interrupts */
477 csicr1 = __raw_readl(pcdev->base + CSICR1) & ~CSI_IRQ_MASK;
478 __raw_writel(csicr1, pcdev->base + CSICR1);
480 /* Stop DMA engine */
481 imx_dma_disable(pcdev->dma_chan);
483 dev_info(icd->dev.parent, "MX1 Camera driver detached from camera %d\n",
486 mx1_camera_deactivate(pcdev);
491 static int mx1_camera_set_crop(struct soc_camera_device *icd,
494 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
496 return v4l2_subdev_call(sd, video, s_crop, a);
499 static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
501 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
502 struct mx1_camera_dev *pcdev = ici->priv;
503 unsigned long camera_flags, common_flags;
507 camera_flags = icd->ops->query_bus_param(icd);
509 /* MX1 supports only 8bit buswidth */
510 common_flags = soc_camera_bus_param_compatible(camera_flags,
515 /* Make choises, based on platform choice */
516 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
517 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
519 pcdev->pdata->flags & MX1_CAMERA_VSYNC_HIGH)
520 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
522 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
525 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
526 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
528 pcdev->pdata->flags & MX1_CAMERA_PCLK_RISING)
529 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
531 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
534 if ((common_flags & SOCAM_DATA_ACTIVE_HIGH) &&
535 (common_flags & SOCAM_DATA_ACTIVE_LOW)) {
537 pcdev->pdata->flags & MX1_CAMERA_DATA_HIGH)
538 common_flags &= ~SOCAM_DATA_ACTIVE_LOW;
540 common_flags &= ~SOCAM_DATA_ACTIVE_HIGH;
543 ret = icd->ops->set_bus_param(icd, common_flags);
547 csicr1 = __raw_readl(pcdev->base + CSICR1);
549 if (common_flags & SOCAM_PCLK_SAMPLE_RISING)
550 csicr1 |= CSICR1_REDGE;
551 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH)
552 csicr1 |= CSICR1_SOF_POL;
553 if (common_flags & SOCAM_DATA_ACTIVE_LOW)
554 csicr1 |= CSICR1_DATA_POL;
556 __raw_writel(csicr1, pcdev->base + CSICR1);
561 static int mx1_camera_set_fmt(struct soc_camera_device *icd,
562 struct v4l2_format *f)
564 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
565 const struct soc_camera_format_xlate *xlate;
566 struct v4l2_pix_format *pix = &f->fmt.pix;
567 struct v4l2_mbus_framefmt mf;
570 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
572 dev_warn(icd->dev.parent, "Format %x not found\n",
577 buswidth = xlate->host_fmt->bits_per_sample;
579 dev_warn(icd->dev.parent,
580 "bits-per-sample %d for format %x unsupported\n",
581 buswidth, pix->pixelformat);
585 mf.width = pix->width;
586 mf.height = pix->height;
587 mf.field = pix->field;
588 mf.colorspace = pix->colorspace;
589 mf.code = xlate->code;
591 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
595 if (mf.code != xlate->code)
598 pix->width = mf.width;
599 pix->height = mf.height;
600 pix->field = mf.field;
601 pix->colorspace = mf.colorspace;
602 icd->current_fmt = xlate;
607 static int mx1_camera_try_fmt(struct soc_camera_device *icd,
608 struct v4l2_format *f)
610 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
611 const struct soc_camera_format_xlate *xlate;
612 struct v4l2_pix_format *pix = &f->fmt.pix;
613 struct v4l2_mbus_framefmt mf;
615 /* TODO: limit to mx1 hardware capabilities */
617 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
619 dev_warn(icd->dev.parent, "Format %x not found\n",
624 mf.width = pix->width;
625 mf.height = pix->height;
626 mf.field = pix->field;
627 mf.colorspace = pix->colorspace;
628 mf.code = xlate->code;
630 /* limit to sensor capabilities */
631 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
635 pix->width = mf.width;
636 pix->height = mf.height;
637 pix->field = mf.field;
638 pix->colorspace = mf.colorspace;
643 static int mx1_camera_reqbufs(struct soc_camera_file *icf,
644 struct v4l2_requestbuffers *p)
649 * This is for locking debugging only. I removed spinlocks and now I
650 * check whether .prepare is ever called on a linked buffer, or whether
651 * a dma IRQ can occur for an in-work or unlinked buffer. Until now
652 * it hadn't triggered
654 for (i = 0; i < p->count; i++) {
655 struct mx1_buffer *buf = container_of(icf->vb_vidq.bufs[i],
656 struct mx1_buffer, vb);
658 INIT_LIST_HEAD(&buf->vb.queue);
664 static unsigned int mx1_camera_poll(struct file *file, poll_table *pt)
666 struct soc_camera_file *icf = file->private_data;
667 struct mx1_buffer *buf;
669 buf = list_entry(icf->vb_vidq.stream.next, struct mx1_buffer,
672 poll_wait(file, &buf->vb.done, pt);
674 if (buf->vb.state == VIDEOBUF_DONE ||
675 buf->vb.state == VIDEOBUF_ERROR)
676 return POLLIN | POLLRDNORM;
681 static int mx1_camera_querycap(struct soc_camera_host *ici,
682 struct v4l2_capability *cap)
684 /* cap->name is set by the friendly caller:-> */
685 strlcpy(cap->card, "i.MX1/i.MXL Camera", sizeof(cap->card));
686 cap->version = VERSION_CODE;
687 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
692 static struct soc_camera_host_ops mx1_soc_camera_host_ops = {
693 .owner = THIS_MODULE,
694 .add = mx1_camera_add_device,
695 .remove = mx1_camera_remove_device,
696 .set_bus_param = mx1_camera_set_bus_param,
697 .set_crop = mx1_camera_set_crop,
698 .set_fmt = mx1_camera_set_fmt,
699 .try_fmt = mx1_camera_try_fmt,
700 .init_videobuf = mx1_camera_init_videobuf,
701 .reqbufs = mx1_camera_reqbufs,
702 .poll = mx1_camera_poll,
703 .querycap = mx1_camera_querycap,
706 static struct fiq_handler fh = {
710 static int __init mx1_camera_probe(struct platform_device *pdev)
712 struct mx1_camera_dev *pcdev;
713 struct resource *res;
720 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
721 irq = platform_get_irq(pdev, 0);
722 if (!res || (int)irq <= 0) {
727 clk = clk_get(&pdev->dev, "csi_clk");
733 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
735 dev_err(&pdev->dev, "Could not allocate pcdev\n");
743 pcdev->pdata = pdev->dev.platform_data;
746 pcdev->mclk = pcdev->pdata->mclk_10khz * 10000;
750 "mclk_10khz == 0! Please, fix your platform data. "
751 "Using default 20MHz\n");
752 pcdev->mclk = 20000000;
755 INIT_LIST_HEAD(&pcdev->capture);
756 spin_lock_init(&pcdev->lock);
759 * Request the regions.
761 if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME)) {
766 base = ioremap(res->start, resource_size(res));
775 pcdev->dma_chan = imx_dma_request_by_prio(DRIVER_NAME, DMA_PRIO_HIGH);
776 if (pcdev->dma_chan < 0) {
777 dev_err(&pdev->dev, "Can't request DMA for MX1 CSI\n");
781 dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_chan);
783 imx_dma_setup_handlers(pcdev->dma_chan, mx1_camera_dma_irq, NULL,
786 imx_dma_config_channel(pcdev->dma_chan, IMX_DMA_TYPE_FIFO,
787 IMX_DMA_MEMSIZE_32, DMA_REQ_CSI_R, 0);
788 /* burst length : 16 words = 64 bytes */
789 imx_dma_config_burstlen(pcdev->dma_chan, 0);
792 err = claim_fiq(&fh);
794 dev_err(&pdev->dev, "Camera interrupt register failed \n");
798 set_fiq_handler(&mx1_camera_sof_fiq_start, &mx1_camera_sof_fiq_end -
799 &mx1_camera_sof_fiq_start);
801 regs.ARM_r8 = DMA_BASE + DMA_DIMR;
802 regs.ARM_r9 = DMA_BASE + DMA_CCR(pcdev->dma_chan);
803 regs.ARM_r10 = (long)pcdev->base + CSICR1;
804 regs.ARM_fp = (long)pcdev->base + CSISR;
805 regs.ARM_sp = 1 << pcdev->dma_chan;
808 mxc_set_irq_fiq(irq, 1);
811 pcdev->soc_host.drv_name = DRIVER_NAME;
812 pcdev->soc_host.ops = &mx1_soc_camera_host_ops;
813 pcdev->soc_host.priv = pcdev;
814 pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
815 pcdev->soc_host.nr = pdev->id;
816 err = soc_camera_host_register(&pcdev->soc_host);
820 dev_info(&pdev->dev, "MX1 Camera driver loaded\n");
826 mxc_set_irq_fiq(irq, 0);
829 imx_dma_free(pcdev->dma_chan);
833 release_mem_region(res->start, resource_size(res));
842 static int __exit mx1_camera_remove(struct platform_device *pdev)
844 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
845 struct mx1_camera_dev *pcdev = container_of(soc_host,
846 struct mx1_camera_dev, soc_host);
847 struct resource *res;
849 imx_dma_free(pcdev->dma_chan);
850 disable_fiq(pcdev->irq);
851 mxc_set_irq_fiq(pcdev->irq, 0);
856 soc_camera_host_unregister(soc_host);
858 iounmap(pcdev->base);
861 release_mem_region(res->start, resource_size(res));
865 dev_info(&pdev->dev, "MX1 Camera driver unloaded\n");
870 static struct platform_driver mx1_camera_driver = {
874 .remove = __exit_p(mx1_camera_remove),
877 static int __init mx1_camera_init(void)
879 return platform_driver_probe(&mx1_camera_driver, mx1_camera_probe);
882 static void __exit mx1_camera_exit(void)
884 return platform_driver_unregister(&mx1_camera_driver);
887 module_init(mx1_camera_init);
888 module_exit(mx1_camera_exit);
890 MODULE_DESCRIPTION("i.MX1/i.MXL SoC Camera Host driver");
891 MODULE_AUTHOR("Paulius Zaleckas <paulius.zaleckas@teltonika.lt>");
892 MODULE_LICENSE("GPL v2");
893 MODULE_ALIAS("platform:" DRIVER_NAME);