18 #include <linux/device.h>
20 #include <linux/errno.h>
25 #include <linux/kernel.h>
27 #include <linux/module.h>
31 #include <linux/sched.h>
32 #include <linux/slab.h>
33 #include <linux/time.h>
34 #include <linux/videodev2.h>
45 #include <mach/hardware.h>
46 #include <mach/irqs.h>
56 #define CSICR1_RXFF_LEVEL(x) (((x) & 0x3) << 19)
57 #define CSICR1_SOF_POL (1 << 17)
58 #define CSICR1_SOF_INTEN (1 << 16)
59 #define CSICR1_MCLKDIV(x) (((x) & 0xf) << 12)
60 #define CSICR1_MCLKEN (1 << 9)
61 #define CSICR1_FCC (1 << 8)
62 #define CSICR1_BIG_ENDIAN (1 << 7)
63 #define CSICR1_CLR_RXFIFO (1 << 5)
64 #define CSICR1_GCLK_MODE (1 << 4)
65 #define CSICR1_DATA_POL (1 << 2)
66 #define CSICR1_REDGE (1 << 1)
67 #define CSICR1_EN (1 << 0)
69 #define CSISR_SFF_OR_INT (1 << 25)
70 #define CSISR_RFF_OR_INT (1 << 24)
71 #define CSISR_STATFF_INT (1 << 21)
72 #define CSISR_RXFF_INT (1 << 18)
73 #define CSISR_SOF_INT (1 << 16)
74 #define CSISR_DRDY (1 << 0)
76 #define DRIVER_VERSION "0.0.2"
77 #define DRIVER_NAME "mx1-camera"
79 #define CSI_IRQ_MASK (CSISR_SFF_OR_INT | CSISR_RFF_OR_INT | \
80 CSISR_STATFF_INT | CSISR_RXFF_INT | CSISR_SOF_INT)
82 #define CSI_BUS_FLAGS (V4L2_MBUS_MASTER | V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
83 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | \
84 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
85 V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_LOW)
87 #define MAX_VIDEO_MEM 16
188 vb->
field != field) {
228 dev_err(dev,
"DMA End IRQ with no active buffer\n");
233 ret = imx_dma_setup_single(pcdev->
dma_chan,
235 vbuf->
size, pcdev->
res->start +
238 dev_err(dev,
"Failed to setup DMA sg list\n");
263 if (!mx1_camera_setup_dma(pcdev)) {
281 dev_dbg(dev,
"%s (vb=0x%p) 0x%08lx %d\n", __func__,
286 dev_dbg(dev,
"%s (active)\n", __func__);
289 dev_dbg(dev,
"%s (queued)\n", __func__);
292 dev_dbg(dev,
"%s (prepared)\n", __func__);
295 dev_dbg(dev,
"%s (unknown)\n", __func__);
308 list_del_init(&vb->
queue);
314 if (list_empty(&pcdev->
capture)) {
323 if (
likely(!mx1_camera_setup_dma(pcdev))) {
332 static void mx1_camera_dma_irq(
int channel,
void *
data)
342 imx_dma_disable(channel);
345 dev_err(dev,
"DMA End IRQ with no active buffer\n");
352 dev_dbg(dev,
"%s (vb=0x%p) 0x%08lx %d\n", __func__,
355 mx1_camera_wakeup(pcdev, vb, buf);
357 spin_unlock_irqrestore(&pcdev->
lock, flags);
361 .buf_setup = mx1_videobuf_setup,
362 .buf_prepare = mx1_videobuf_prepare,
363 .buf_queue = mx1_videobuf_queue,
364 .buf_release = mx1_videobuf_release,
383 unsigned long lcdclk;
391 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
394 "System clock %lukHz, target freq %dkHz, divisor %lu\n",
395 lcdclk / 1000, mclk / 1000, div);
404 dev_dbg(pcdev->
icd->parent,
"Activate device\n");
406 clk_prepare_enable(pcdev->
clk);
420 dev_dbg(pcdev->
icd->parent,
"Deactivate device\n");
425 clk_disable_unprepare(pcdev->
clk);
440 dev_info(icd->
parent,
"MX1 Camera driver attached to camera %d\n",
443 mx1_camera_activate(pcdev);
465 dev_info(icd->
parent,
"MX1 Camera driver detached from camera %d\n",
468 mx1_camera_deactivate(pcdev);
489 "Flags incompatible: camera 0x%x, host 0x%x\n",
504 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
506 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
513 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
515 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
522 common_flags &= ~V4L2_MBUS_DATA_ACTIVE_LOW;
524 common_flags &= ~V4L2_MBUS_DATA_ACTIVE_HIGH;
530 dev_dbg(icd->
parent,
"camera s_mbus_config(0x%lx) returned %d\n",
537 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
539 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
541 if (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)
552 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
553 const struct soc_camera_format_xlate *
xlate;
555 struct v4l2_mbus_framefmt mf;
565 buswidth = xlate->host_fmt->bits_per_sample;
568 "bits-per-sample %d for format %x unsupported\n",
573 mf.width = pix->
width;
575 mf.field = pix->
field;
577 mf.code = xlate->code;
583 if (mf.code != xlate->code)
586 pix->
width = mf.width;
588 pix->
field = mf.field;
598 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
599 const struct soc_camera_format_xlate *xlate;
601 struct v4l2_mbus_framefmt mf;
612 mf.width = pix->
width;
614 mf.field = pix->
field;
616 mf.code = xlate->code;
623 pix->
width = mf.width;
625 pix->
field = mf.field;
642 for (i = 0; i < p->
count; i++) {
646 INIT_LIST_HEAD(&buf->
vb.queue);
660 poll_wait(file, &buf->
vb.done, pt);
681 .add = mx1_camera_add_device,
682 .remove = mx1_camera_remove_device,
683 .set_bus_param = mx1_camera_set_bus_param,
684 .set_fmt = mx1_camera_set_fmt,
685 .try_fmt = mx1_camera_try_fmt,
686 .init_videobuf = mx1_camera_init_videobuf,
687 .reqbufs = mx1_camera_reqbufs,
688 .poll = mx1_camera_poll,
689 .querycap = mx1_camera_querycap,
708 if (!res || (
int)irq <= 0) {
721 dev_err(&pdev->
dev,
"Could not allocate pcdev\n");
729 pcdev->
pdata = pdev->
dev.platform_data;
732 pcdev->
mclk = pcdev->
pdata->mclk_10khz * 10000;
736 "mclk_10khz == 0! Please, fix your platform data. "
737 "Using default 20MHz\n");
738 pcdev->
mclk = 20000000;
741 INIT_LIST_HEAD(&pcdev->
capture);
763 dev_err(&pdev->
dev,
"Can't request DMA for MX1 CSI\n");
769 imx_dma_setup_handlers(pcdev->
dma_chan, mx1_camera_dma_irq,
NULL,
775 imx_dma_config_burstlen(pcdev->
dma_chan, 0);
780 dev_err(&pdev->
dev,
"Camera interrupt register failed \n");
785 &mx1_camera_sof_fiq_start);
798 pcdev->
soc_host.ops = &mx1_soc_camera_host_ops;
806 dev_info(&pdev->
dev,
"MX1 Camera driver loaded\n");
851 dev_info(&pdev->
dev,
"MX1 Camera driver unloaded\n");
860 .remove =
__exit_p(mx1_camera_remove),
863 static int __init mx1_camera_init(
void)
868 static void __exit mx1_camera_exit(
void)