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/platform_device.h>
30 #include <linux/sched.h>
31 #include <linux/slab.h>
32 #include <linux/time.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>
39 #include <media/soc_mediabus.h>
43 #include <mach/dma-mx1-mx2.h>
44 #include <mach/hardware.h>
45 #include <mach/irqs.h>
46 #include <linux/platform_data/camera-mx1.h>
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 DRIVER_VERSION "0.0.2"
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 (V4L2_MBUS_MASTER | V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
82 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | \
83 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
84 V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_LOW)
86 #define MAX_VIDEO_MEM 16 /* Video memory limit in megabytes */
92 /* buffer for one video frame */
94 /* common v4l buffer stuff -- must be first */
95 struct videobuf_buffer vb
;
96 enum v4l2_mbus_pixelcode code
;
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
105 struct mx1_camera_dev
{
106 struct soc_camera_host soc_host
;
107 struct soc_camera_device
*icd
;
108 struct mx1_camera_pdata
*pdata
;
109 struct mx1_buffer
*active
;
110 struct resource
*res
;
112 struct list_head capture
;
123 * Videobuf operations
125 static int mx1_videobuf_setup(struct videobuf_queue
*vq
, unsigned int *count
,
128 struct soc_camera_device
*icd
= vq
->priv_data
;
130 *size
= icd
->sizeimage
;
135 if (*size
* *count
> MAX_VIDEO_MEM
* 1024 * 1024)
136 *count
= (MAX_VIDEO_MEM
* 1024 * 1024) / *size
;
138 dev_dbg(icd
->parent
, "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
->parent
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
151 vb
, vb
->baddr
, vb
->bsize
);
154 * This waits until this buffer is out of danger, i.e., until it is no
155 * longer in STATE_QUEUED or STATE_ACTIVE
157 videobuf_waiton(vq
, vb
, 0, 0);
158 videobuf_dma_contig_free(vq
, vb
);
160 vb
->state
= VIDEOBUF_NEEDS_INIT
;
163 static int mx1_videobuf_prepare(struct videobuf_queue
*vq
,
164 struct videobuf_buffer
*vb
, enum v4l2_field field
)
166 struct soc_camera_device
*icd
= vq
->priv_data
;
167 struct mx1_buffer
*buf
= container_of(vb
, struct mx1_buffer
, vb
);
170 dev_dbg(icd
->parent
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
171 vb
, vb
->baddr
, vb
->bsize
);
173 /* Added list head initialization on alloc */
174 WARN_ON(!list_empty(&vb
->queue
));
176 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
184 if (buf
->code
!= icd
->current_fmt
->code
||
185 vb
->width
!= icd
->user_width
||
186 vb
->height
!= icd
->user_height
||
187 vb
->field
!= field
) {
188 buf
->code
= icd
->current_fmt
->code
;
189 vb
->width
= icd
->user_width
;
190 vb
->height
= icd
->user_height
;
192 vb
->state
= VIDEOBUF_NEEDS_INIT
;
195 vb
->size
= icd
->sizeimage
;
196 if (0 != vb
->baddr
&& vb
->bsize
< vb
->size
) {
201 if (vb
->state
== VIDEOBUF_NEEDS_INIT
) {
202 ret
= videobuf_iolock(vq
, vb
, NULL
);
206 vb
->state
= VIDEOBUF_PREPARED
;
214 free_buffer(vq
, buf
);
220 static int mx1_camera_setup_dma(struct mx1_camera_dev
*pcdev
)
222 struct videobuf_buffer
*vbuf
= &pcdev
->active
->vb
;
223 struct device
*dev
= pcdev
->icd
->parent
;
226 if (unlikely(!pcdev
->active
)) {
227 dev_err(dev
, "DMA End IRQ with no active buffer\n");
231 /* setup sg list for future DMA */
232 ret
= imx_dma_setup_single(pcdev
->dma_chan
,
233 videobuf_to_dma_contig(vbuf
),
234 vbuf
->size
, pcdev
->res
->start
+
235 CSIRXR
, DMA_MODE_READ
);
237 dev_err(dev
, "Failed to setup DMA sg list\n");
242 /* Called under spinlock_irqsave(&pcdev->lock, ...) */
243 static void mx1_videobuf_queue(struct videobuf_queue
*vq
,
244 struct videobuf_buffer
*vb
)
246 struct soc_camera_device
*icd
= vq
->priv_data
;
247 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
248 struct mx1_camera_dev
*pcdev
= ici
->priv
;
249 struct mx1_buffer
*buf
= container_of(vb
, struct mx1_buffer
, vb
);
251 dev_dbg(icd
->parent
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
252 vb
, vb
->baddr
, vb
->bsize
);
254 list_add_tail(&vb
->queue
, &pcdev
->capture
);
256 vb
->state
= VIDEOBUF_ACTIVE
;
258 if (!pcdev
->active
) {
261 /* setup sg list for future DMA */
262 if (!mx1_camera_setup_dma(pcdev
)) {
265 temp
= __raw_readl(pcdev
->base
+ CSICR1
) |
267 __raw_writel(temp
, pcdev
->base
+ CSICR1
);
272 static void mx1_videobuf_release(struct videobuf_queue
*vq
,
273 struct videobuf_buffer
*vb
)
275 struct mx1_buffer
*buf
= container_of(vb
, struct mx1_buffer
, vb
);
277 struct soc_camera_device
*icd
= vq
->priv_data
;
278 struct device
*dev
= icd
->parent
;
280 dev_dbg(dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
281 vb
, vb
->baddr
, vb
->bsize
);
284 case VIDEOBUF_ACTIVE
:
285 dev_dbg(dev
, "%s (active)\n", __func__
);
287 case VIDEOBUF_QUEUED
:
288 dev_dbg(dev
, "%s (queued)\n", __func__
);
290 case VIDEOBUF_PREPARED
:
291 dev_dbg(dev
, "%s (prepared)\n", __func__
);
294 dev_dbg(dev
, "%s (unknown)\n", __func__
);
299 free_buffer(vq
, buf
);
302 static void mx1_camera_wakeup(struct mx1_camera_dev
*pcdev
,
303 struct videobuf_buffer
*vb
,
304 struct mx1_buffer
*buf
)
306 /* _init is used to debug races, see comment in mx1_camera_reqbufs() */
307 list_del_init(&vb
->queue
);
308 vb
->state
= VIDEOBUF_DONE
;
309 v4l2_get_timestamp(&vb
->ts
);
313 if (list_empty(&pcdev
->capture
)) {
314 pcdev
->active
= NULL
;
318 pcdev
->active
= list_entry(pcdev
->capture
.next
,
319 struct mx1_buffer
, vb
.queue
);
321 /* setup sg list for future DMA */
322 if (likely(!mx1_camera_setup_dma(pcdev
))) {
326 temp
= __raw_readl(pcdev
->base
+ CSICR1
) | CSICR1_SOF_INTEN
;
327 __raw_writel(temp
, pcdev
->base
+ CSICR1
);
331 static void mx1_camera_dma_irq(int channel
, void *data
)
333 struct mx1_camera_dev
*pcdev
= data
;
334 struct device
*dev
= pcdev
->icd
->parent
;
335 struct mx1_buffer
*buf
;
336 struct videobuf_buffer
*vb
;
339 spin_lock_irqsave(&pcdev
->lock
, flags
);
341 imx_dma_disable(channel
);
343 if (unlikely(!pcdev
->active
)) {
344 dev_err(dev
, "DMA End IRQ with no active buffer\n");
348 vb
= &pcdev
->active
->vb
;
349 buf
= container_of(vb
, struct mx1_buffer
, vb
);
350 WARN_ON(buf
->inwork
|| list_empty(&vb
->queue
));
351 dev_dbg(dev
, "%s (vb=0x%p) 0x%08lx %d\n", __func__
,
352 vb
, vb
->baddr
, vb
->bsize
);
354 mx1_camera_wakeup(pcdev
, vb
, buf
);
356 spin_unlock_irqrestore(&pcdev
->lock
, flags
);
359 static struct videobuf_queue_ops mx1_videobuf_ops
= {
360 .buf_setup
= mx1_videobuf_setup
,
361 .buf_prepare
= mx1_videobuf_prepare
,
362 .buf_queue
= mx1_videobuf_queue
,
363 .buf_release
= mx1_videobuf_release
,
366 static void mx1_camera_init_videobuf(struct videobuf_queue
*q
,
367 struct soc_camera_device
*icd
)
369 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
370 struct mx1_camera_dev
*pcdev
= ici
->priv
;
372 videobuf_queue_dma_contig_init(q
, &mx1_videobuf_ops
, icd
->parent
,
373 &pcdev
->lock
, V4L2_BUF_TYPE_VIDEO_CAPTURE
,
375 sizeof(struct mx1_buffer
), icd
, &ici
->host_lock
);
378 static int mclk_get_divisor(struct mx1_camera_dev
*pcdev
)
380 unsigned int mclk
= pcdev
->mclk
;
382 unsigned long lcdclk
;
384 lcdclk
= clk_get_rate(pcdev
->clk
);
387 * We verify platform_mclk_10khz != 0, so if anyone breaks it, here
388 * they get a nice Oops
390 div
= (lcdclk
+ 2 * mclk
- 1) / (2 * mclk
) - 1;
392 dev_dbg(pcdev
->icd
->parent
,
393 "System clock %lukHz, target freq %dkHz, divisor %lu\n",
394 lcdclk
/ 1000, mclk
/ 1000, div
);
399 static void mx1_camera_activate(struct mx1_camera_dev
*pcdev
)
401 unsigned int csicr1
= CSICR1_EN
;
403 dev_dbg(pcdev
->icd
->parent
, "Activate device\n");
405 clk_prepare_enable(pcdev
->clk
);
407 /* enable CSI before doing anything else */
408 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
410 csicr1
|= CSICR1_MCLKEN
| CSICR1_FCC
| CSICR1_GCLK_MODE
;
411 csicr1
|= CSICR1_MCLKDIV(mclk_get_divisor(pcdev
));
412 csicr1
|= CSICR1_RXFF_LEVEL(2); /* 16 words */
414 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
417 static void mx1_camera_deactivate(struct mx1_camera_dev
*pcdev
)
419 dev_dbg(pcdev
->icd
->parent
, "Deactivate device\n");
421 /* Disable all CSI interface */
422 __raw_writel(0x00, pcdev
->base
+ CSICR1
);
424 clk_disable_unprepare(pcdev
->clk
);
428 * The following two functions absolutely depend on the fact, that
429 * there can be only one camera on i.MX1/i.MXL camera sensor interface
431 static int mx1_camera_add_device(struct soc_camera_device
*icd
)
433 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
434 struct mx1_camera_dev
*pcdev
= ici
->priv
;
439 dev_info(icd
->parent
, "MX1 Camera driver attached to camera %d\n",
442 mx1_camera_activate(pcdev
);
449 static void mx1_camera_remove_device(struct soc_camera_device
*icd
)
451 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
452 struct mx1_camera_dev
*pcdev
= ici
->priv
;
455 BUG_ON(icd
!= pcdev
->icd
);
457 /* disable interrupts */
458 csicr1
= __raw_readl(pcdev
->base
+ CSICR1
) & ~CSI_IRQ_MASK
;
459 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
461 /* Stop DMA engine */
462 imx_dma_disable(pcdev
->dma_chan
);
464 dev_info(icd
->parent
, "MX1 Camera driver detached from camera %d\n",
467 mx1_camera_deactivate(pcdev
);
472 static int mx1_camera_set_bus_param(struct soc_camera_device
*icd
)
474 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
475 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
476 struct mx1_camera_dev
*pcdev
= ici
->priv
;
477 struct v4l2_mbus_config cfg
= {.type
= V4L2_MBUS_PARALLEL
,};
478 unsigned long common_flags
;
482 /* MX1 supports only 8bit buswidth */
483 ret
= v4l2_subdev_call(sd
, video
, g_mbus_config
, &cfg
);
485 common_flags
= soc_mbus_config_compatible(&cfg
, CSI_BUS_FLAGS
);
487 dev_warn(icd
->parent
,
488 "Flags incompatible: camera 0x%x, host 0x%x\n",
489 cfg
.flags
, CSI_BUS_FLAGS
);
492 } else if (ret
!= -ENOIOCTLCMD
) {
495 common_flags
= CSI_BUS_FLAGS
;
498 /* Make choises, based on platform choice */
499 if ((common_flags
& V4L2_MBUS_VSYNC_ACTIVE_HIGH
) &&
500 (common_flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
)) {
502 pcdev
->pdata
->flags
& MX1_CAMERA_VSYNC_HIGH
)
503 common_flags
&= ~V4L2_MBUS_VSYNC_ACTIVE_LOW
;
505 common_flags
&= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH
;
508 if ((common_flags
& V4L2_MBUS_PCLK_SAMPLE_RISING
) &&
509 (common_flags
& V4L2_MBUS_PCLK_SAMPLE_FALLING
)) {
511 pcdev
->pdata
->flags
& MX1_CAMERA_PCLK_RISING
)
512 common_flags
&= ~V4L2_MBUS_PCLK_SAMPLE_FALLING
;
514 common_flags
&= ~V4L2_MBUS_PCLK_SAMPLE_RISING
;
517 if ((common_flags
& V4L2_MBUS_DATA_ACTIVE_HIGH
) &&
518 (common_flags
& V4L2_MBUS_DATA_ACTIVE_LOW
)) {
520 pcdev
->pdata
->flags
& MX1_CAMERA_DATA_HIGH
)
521 common_flags
&= ~V4L2_MBUS_DATA_ACTIVE_LOW
;
523 common_flags
&= ~V4L2_MBUS_DATA_ACTIVE_HIGH
;
526 cfg
.flags
= common_flags
;
527 ret
= v4l2_subdev_call(sd
, video
, s_mbus_config
, &cfg
);
528 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
529 dev_dbg(icd
->parent
, "camera s_mbus_config(0x%lx) returned %d\n",
534 csicr1
= __raw_readl(pcdev
->base
+ CSICR1
);
536 if (common_flags
& V4L2_MBUS_PCLK_SAMPLE_RISING
)
537 csicr1
|= CSICR1_REDGE
;
538 if (common_flags
& V4L2_MBUS_VSYNC_ACTIVE_HIGH
)
539 csicr1
|= CSICR1_SOF_POL
;
540 if (common_flags
& V4L2_MBUS_DATA_ACTIVE_LOW
)
541 csicr1
|= CSICR1_DATA_POL
;
543 __raw_writel(csicr1
, pcdev
->base
+ CSICR1
);
548 static int mx1_camera_set_fmt(struct soc_camera_device
*icd
,
549 struct v4l2_format
*f
)
551 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
552 const struct soc_camera_format_xlate
*xlate
;
553 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
554 struct v4l2_mbus_framefmt mf
;
557 xlate
= soc_camera_xlate_by_fourcc(icd
, pix
->pixelformat
);
559 dev_warn(icd
->parent
, "Format %x not found\n",
564 buswidth
= xlate
->host_fmt
->bits_per_sample
;
566 dev_warn(icd
->parent
,
567 "bits-per-sample %d for format %x unsupported\n",
568 buswidth
, pix
->pixelformat
);
572 mf
.width
= pix
->width
;
573 mf
.height
= pix
->height
;
574 mf
.field
= pix
->field
;
575 mf
.colorspace
= pix
->colorspace
;
576 mf
.code
= xlate
->code
;
578 ret
= v4l2_subdev_call(sd
, video
, s_mbus_fmt
, &mf
);
582 if (mf
.code
!= xlate
->code
)
585 pix
->width
= mf
.width
;
586 pix
->height
= mf
.height
;
587 pix
->field
= mf
.field
;
588 pix
->colorspace
= mf
.colorspace
;
589 icd
->current_fmt
= xlate
;
594 static int mx1_camera_try_fmt(struct soc_camera_device
*icd
,
595 struct v4l2_format
*f
)
597 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
598 const struct soc_camera_format_xlate
*xlate
;
599 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
600 struct v4l2_mbus_framefmt mf
;
602 /* TODO: limit to mx1 hardware capabilities */
604 xlate
= soc_camera_xlate_by_fourcc(icd
, pix
->pixelformat
);
606 dev_warn(icd
->parent
, "Format %x not found\n",
611 mf
.width
= pix
->width
;
612 mf
.height
= pix
->height
;
613 mf
.field
= pix
->field
;
614 mf
.colorspace
= pix
->colorspace
;
615 mf
.code
= xlate
->code
;
617 /* limit to sensor capabilities */
618 ret
= v4l2_subdev_call(sd
, video
, try_mbus_fmt
, &mf
);
622 pix
->width
= mf
.width
;
623 pix
->height
= mf
.height
;
624 pix
->field
= mf
.field
;
625 pix
->colorspace
= mf
.colorspace
;
630 static int mx1_camera_reqbufs(struct soc_camera_device
*icd
,
631 struct v4l2_requestbuffers
*p
)
636 * This is for locking debugging only. I removed spinlocks and now I
637 * check whether .prepare is ever called on a linked buffer, or whether
638 * a dma IRQ can occur for an in-work or unlinked buffer. Until now
639 * it hadn't triggered
641 for (i
= 0; i
< p
->count
; i
++) {
642 struct mx1_buffer
*buf
= container_of(icd
->vb_vidq
.bufs
[i
],
643 struct mx1_buffer
, vb
);
645 INIT_LIST_HEAD(&buf
->vb
.queue
);
651 static unsigned int mx1_camera_poll(struct file
*file
, poll_table
*pt
)
653 struct soc_camera_device
*icd
= file
->private_data
;
654 struct mx1_buffer
*buf
;
656 buf
= list_entry(icd
->vb_vidq
.stream
.next
, struct mx1_buffer
,
659 poll_wait(file
, &buf
->vb
.done
, pt
);
661 if (buf
->vb
.state
== VIDEOBUF_DONE
||
662 buf
->vb
.state
== VIDEOBUF_ERROR
)
663 return POLLIN
| POLLRDNORM
;
668 static int mx1_camera_querycap(struct soc_camera_host
*ici
,
669 struct v4l2_capability
*cap
)
671 /* cap->name is set by the friendly caller:-> */
672 strlcpy(cap
->card
, "i.MX1/i.MXL Camera", sizeof(cap
->card
));
673 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
678 static struct soc_camera_host_ops mx1_soc_camera_host_ops
= {
679 .owner
= THIS_MODULE
,
680 .add
= mx1_camera_add_device
,
681 .remove
= mx1_camera_remove_device
,
682 .set_bus_param
= mx1_camera_set_bus_param
,
683 .set_fmt
= mx1_camera_set_fmt
,
684 .try_fmt
= mx1_camera_try_fmt
,
685 .init_videobuf
= mx1_camera_init_videobuf
,
686 .reqbufs
= mx1_camera_reqbufs
,
687 .poll
= mx1_camera_poll
,
688 .querycap
= mx1_camera_querycap
,
691 static struct fiq_handler fh
= {
695 static int __init
mx1_camera_probe(struct platform_device
*pdev
)
697 struct mx1_camera_dev
*pcdev
;
698 struct resource
*res
;
705 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
706 irq
= platform_get_irq(pdev
, 0);
707 if (!res
|| (int)irq
<= 0) {
712 clk
= clk_get(&pdev
->dev
, "csi_clk");
718 pcdev
= kzalloc(sizeof(*pcdev
), GFP_KERNEL
);
720 dev_err(&pdev
->dev
, "Could not allocate pcdev\n");
728 pcdev
->pdata
= pdev
->dev
.platform_data
;
731 pcdev
->mclk
= pcdev
->pdata
->mclk_10khz
* 10000;
735 "mclk_10khz == 0! Please, fix your platform data. "
736 "Using default 20MHz\n");
737 pcdev
->mclk
= 20000000;
740 INIT_LIST_HEAD(&pcdev
->capture
);
741 spin_lock_init(&pcdev
->lock
);
744 * Request the regions.
746 if (!request_mem_region(res
->start
, resource_size(res
), DRIVER_NAME
)) {
751 base
= ioremap(res
->start
, resource_size(res
));
760 pcdev
->dma_chan
= imx_dma_request_by_prio(DRIVER_NAME
, DMA_PRIO_HIGH
);
761 if (pcdev
->dma_chan
< 0) {
762 dev_err(&pdev
->dev
, "Can't request DMA for MX1 CSI\n");
766 dev_dbg(&pdev
->dev
, "got DMA channel %d\n", pcdev
->dma_chan
);
768 imx_dma_setup_handlers(pcdev
->dma_chan
, mx1_camera_dma_irq
, NULL
,
771 imx_dma_config_channel(pcdev
->dma_chan
, IMX_DMA_TYPE_FIFO
,
772 IMX_DMA_MEMSIZE_32
, MX1_DMA_REQ_CSI_R
, 0);
773 /* burst length : 16 words = 64 bytes */
774 imx_dma_config_burstlen(pcdev
->dma_chan
, 0);
777 err
= claim_fiq(&fh
);
779 dev_err(&pdev
->dev
, "Camera interrupt register failed\n");
783 set_fiq_handler(&mx1_camera_sof_fiq_start
, &mx1_camera_sof_fiq_end
-
784 &mx1_camera_sof_fiq_start
);
786 regs
.ARM_r8
= (long)MX1_DMA_DIMR
;
787 regs
.ARM_r9
= (long)MX1_DMA_CCR(pcdev
->dma_chan
);
788 regs
.ARM_r10
= (long)pcdev
->base
+ CSICR1
;
789 regs
.ARM_fp
= (long)pcdev
->base
+ CSISR
;
790 regs
.ARM_sp
= 1 << pcdev
->dma_chan
;
793 mxc_set_irq_fiq(irq
, 1);
796 pcdev
->soc_host
.drv_name
= DRIVER_NAME
;
797 pcdev
->soc_host
.ops
= &mx1_soc_camera_host_ops
;
798 pcdev
->soc_host
.priv
= pcdev
;
799 pcdev
->soc_host
.v4l2_dev
.dev
= &pdev
->dev
;
800 pcdev
->soc_host
.nr
= pdev
->id
;
801 err
= soc_camera_host_register(&pcdev
->soc_host
);
805 dev_info(&pdev
->dev
, "MX1 Camera driver loaded\n");
811 mxc_set_irq_fiq(irq
, 0);
814 imx_dma_free(pcdev
->dma_chan
);
818 release_mem_region(res
->start
, resource_size(res
));
827 static int __exit
mx1_camera_remove(struct platform_device
*pdev
)
829 struct soc_camera_host
*soc_host
= to_soc_camera_host(&pdev
->dev
);
830 struct mx1_camera_dev
*pcdev
= container_of(soc_host
,
831 struct mx1_camera_dev
, soc_host
);
832 struct resource
*res
;
834 imx_dma_free(pcdev
->dma_chan
);
835 disable_fiq(pcdev
->irq
);
836 mxc_set_irq_fiq(pcdev
->irq
, 0);
841 soc_camera_host_unregister(soc_host
);
843 iounmap(pcdev
->base
);
846 release_mem_region(res
->start
, resource_size(res
));
850 dev_info(&pdev
->dev
, "MX1 Camera driver unloaded\n");
855 static struct platform_driver mx1_camera_driver
= {
859 .remove
= __exit_p(mx1_camera_remove
),
862 module_platform_driver_probe(mx1_camera_driver
, mx1_camera_probe
);
864 MODULE_DESCRIPTION("i.MX1/i.MXL SoC Camera Host driver");
865 MODULE_AUTHOR("Paulius Zaleckas <paulius.zaleckas@teltonika.lt>");
866 MODULE_LICENSE("GPL v2");
867 MODULE_VERSION(DRIVER_VERSION
);
868 MODULE_ALIAS("platform:" DRIVER_NAME
);